Improve handling of built-in keyboard.
The window manager policy made some incorrect assumptions about the
meaning of the Configuration.keyboard field. We need to be more
careful about distinguishing between built-in and external keyboards.
Most of this change is to move the determination of the parts of
the Configuration related to input devices into the WindowManagerService
leveraging new features of the InputManagerService to good effect.
Then we plumb through the flag that indicates whether a device
is internal or external so that we can be more particular about
how the lid switch effects changes to the Configuration.
Bug: 6424373
Change-Id: I36a1c22ade35e578955465a25940a33f227b9763
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index bd50e22..5ec1fa5 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -2521,8 +2521,8 @@
return val;
} catch (Exception e) {
// guard against null pointer or index out of bounds errors
- Slog.e(TAG, "Values array must be non-empty and must be the same length "
- + "as the auto-brightness levels array. Check config.xml.", e);
+ Slog.e(TAG, "Values array must be non-empty and must be one element longer than "
+ + "the auto-brightness levels array. Check config.xml.", e);
return 255;
}
}
diff --git a/services/java/com/android/server/input/InputManagerService.java b/services/java/com/android/server/input/InputManagerService.java
index aece7d25..117e064 100644
--- a/services/java/com/android/server/input/InputManagerService.java
+++ b/services/java/com/android/server/input/InputManagerService.java
@@ -162,7 +162,6 @@
private static native void nativeSetSystemUiVisibility(int ptr, int visibility);
private static native void nativeSetFocusedApplication(int ptr,
InputApplicationHandle application);
- private static native void nativeGetInputConfiguration(int ptr, Configuration configuration);
private static native boolean nativeTransferTouchFocus(int ptr,
InputChannel fromChannel, InputChannel toChannel);
private static native void nativeSetPointerSpeed(int ptr, int speed);
@@ -298,14 +297,6 @@
}
nativeSetDisplayOrientation(mPtr, displayId, rotation);
}
-
- public void getInputConfiguration(Configuration config) {
- if (config == null) {
- throw new IllegalArgumentException("config must not be null.");
- }
-
- nativeGetInputConfiguration(mPtr, config);
- }
/**
* Gets the current state of a key or button by key code.
@@ -522,6 +513,16 @@
}
}
+ /**
+ * Gets all input devices in the system.
+ * @return The array of input devices.
+ */
+ public InputDevice[] getInputDevices() {
+ synchronized (mInputDevicesLock) {
+ return mInputDevices;
+ }
+ }
+
@Override // Binder call
public void registerInputDevicesChangedListener(IInputDevicesChangedListener listener) {
if (listener == null) {
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index ae1cc7f..633b884 100755
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -6283,8 +6283,6 @@
final int dh = mCurDisplayHeight;
if (config != null) {
- mInputManager.getInputConfiguration(config);
-
int orientation = Configuration.ORIENTATION_SQUARE;
if (dw < dh) {
orientation = Configuration.ORIENTATION_PORTRAIT;
@@ -6327,12 +6325,46 @@
config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh);
+ // Update the configuration based on available input devices, lid switch,
+ // and platform configuration.
+ config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
+ config.keyboard = Configuration.KEYBOARD_NOKEYS;
+ config.navigation = Configuration.NAVIGATION_NONAV;
+
+ int keyboardPresence = 0;
+ int navigationPresence = 0;
+ for (InputDevice device : mInputManager.getInputDevices()) {
+ if (!device.isVirtual()) {
+ final int sources = device.getSources();
+ final int presenceFlag = device.isExternal() ?
+ WindowManagerPolicy.PRESENCE_EXTERNAL :
+ WindowManagerPolicy.PRESENCE_INTERNAL;
+
+ if ((sources & InputDevice.SOURCE_TOUCHSCREEN) != 0) {
+ config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
+ }
+
+ if ((sources & InputDevice.SOURCE_TRACKBALL) != 0) {
+ config.navigation = Configuration.NAVIGATION_TRACKBALL;
+ navigationPresence |= presenceFlag;
+ } else if ((sources & InputDevice.SOURCE_DPAD) != 0
+ && config.navigation == Configuration.NAVIGATION_NONAV) {
+ config.navigation = Configuration.NAVIGATION_DPAD;
+ navigationPresence |= presenceFlag;
+ }
+
+ if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
+ config.keyboard = Configuration.KEYBOARD_QWERTY;
+ keyboardPresence |= presenceFlag;
+ }
+ }
+ }
+
// Determine whether a hard keyboard is available and enabled.
boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
if (hardKeyboardAvailable != mHardKeyboardAvailable) {
mHardKeyboardAvailable = hardKeyboardAvailable;
mHardKeyboardEnabled = hardKeyboardAvailable;
-
mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
}
@@ -6340,13 +6372,11 @@
config.keyboard = Configuration.KEYBOARD_NOKEYS;
}
- // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
- // based on whether a hard or soft keyboard is present, whether navigation keys
- // are present and the lid switch state.
+ // Let the policy update hidden states.
config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
- mPolicy.adjustConfigurationLw(config);
+ mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
}
return true;