Skip to content

Commit dbb1f9b

Browse files
committed
DeviceKeyHandle: The device should consume only known keys
When the device receive the key, only should consume it if the device know about the key. Otherwise, the key must be handle by the active app. Also make mDeviceKeyHandler private (is not useful outside this class) Change-Id: I4b9ea57b802e8c8c88c8b93a63d510f5952b0700 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
1 parent 4b662bd commit dbb1f9b

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

core/java/com/android/internal/os/DeviceKeyHandler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
import android.view.KeyEvent;
1515

1616
public interface DeviceKeyHandler {
17-
public static final int KEYEVENT_CAUGHT = -1;
18-
public static final int KEYEVENT_UNCAUGHT = 0;
1917

20-
public int handleKeyEvent(KeyEvent event);
18+
/**
19+
* Invoked when an unknown key was detected by the system, letting the device handle
20+
* this special keys prior to pass the key to the active app.
21+
*
22+
* @param event The key event to be handled
23+
* @return If the event is consume
24+
*/
25+
public boolean handleKeyEvent(KeyEvent event);
2126
}

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
259259
KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
260260
}
261261

262-
DeviceKeyHandler mDeviceKeyHandler;
262+
private DeviceKeyHandler mDeviceKeyHandler;
263263

264264
/**
265265
* Lock protecting internal state. Must not call out into window
@@ -1222,9 +1222,9 @@ public void init(Context context, IWindowManager windowManager,
12221222
Constructor<?> constructor = klass.getConstructor(Context.class);
12231223
mDeviceKeyHandler = (DeviceKeyHandler) constructor.newInstance(
12241224
mContext);
1225-
Slog.d(TAG, "Device key handler loaded");
1225+
if(DEBUG) Slog.d(TAG, "Device key handler loaded");
12261226
} catch (Exception e) {
1227-
Slog.d(TAG, "Could not instantiate device key handler "
1227+
Slog.w(TAG, "Could not instantiate device key handler "
12281228
+ deviceKeyHandlerClass + " from class "
12291229
+ deviceKeyHandlerLib, e);
12301230
}
@@ -2527,11 +2527,15 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
25272527
return -1;
25282528
}
25292529

2530+
// Specific device key handling
25302531
if (mDeviceKeyHandler != null) {
25312532
try {
2532-
return mDeviceKeyHandler.handleKeyEvent(event);
2533+
// The device only should consume known keys.
2534+
if (mDeviceKeyHandler.handleKeyEvent(event)) {
2535+
return -1;
2536+
}
25332537
} catch (Exception e) {
2534-
Slog.d(TAG, "Could not dispatch event to device key handler", e);
2538+
Slog.w(TAG, "Could not dispatch event to device key handler", e);
25352539
}
25362540
}
25372541

0 commit comments

Comments
 (0)