Fix Backslash not showing with paired keyboard
Our current label retrieving flow is
1. Special cased drawables (e.g. backspace)
2. Special cased names (e.g. F2)
3. Device KeyCharacterMap getLabel
For single character keys such as '\', we reach the end of 3. with
no result if the main device doesn't have the key. This change uses
the virtual keyboard map as a backup to retrieve labels for these
last resort cases.
Bug: 28830189
Change-Id: I69cc82a11e7b803db7f60ea07d34c59f6000149e
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
index 79e06c6..7f16c69 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
@@ -111,6 +111,7 @@
private Dialog mKeyboardShortcutsDialog;
private KeyCharacterMap mKeyCharacterMap;
+ private KeyCharacterMap mBackupKeyCharacterMap;
private KeyboardShortcuts(Context context) {
this.mContext = new ContextThemeWrapper(context, android.R.style.Theme_Material_Light);
@@ -326,6 +327,7 @@
*/
private void retrieveKeyCharacterMap(int deviceId) {
final InputManager inputManager = InputManager.getInstance();
+ mBackupKeyCharacterMap = inputManager.getInputDevice(-1).getKeyCharacterMap();
if (deviceId != -1) {
final InputDevice inputDevice = inputManager.getInputDevice(deviceId);
if (inputDevice != null) {
@@ -343,8 +345,8 @@
return;
}
}
- final InputDevice inputDevice = inputManager.getInputDevice(-1);
- mKeyCharacterMap = inputDevice.getKeyCharacterMap();
+ // Fall back to -1, the virtual keyboard.
+ mKeyCharacterMap = mBackupKeyCharacterMap;
}
private void showKeyboardShortcuts(int deviceId) {
@@ -675,7 +677,12 @@
if (displayLabel != 0) {
displayLabelString = String.valueOf(displayLabel);
} else {
- return null;
+ displayLabel = mBackupKeyCharacterMap.getDisplayLabel(info.getKeycode());
+ if (displayLabel != 0) {
+ displayLabelString = String.valueOf(displayLabel);
+ } else {
+ return null;
+ }
}
}