From b0e804a303272655ec7c2cece66d69f39b488955 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Mon, 4 Jan 2016 16:48:53 -0500 Subject: [PATCH] Always show enabled keyboards. With the latest keyboard layout selection process changes we now only show layouts that are appropriate for a given keyboard. If a user selected an inappropriate layout prior to this though, then we need to still show it in the selection menu so they can remove if it they desire. Bug: 25624985 Change-Id: I0707981f5b60c1867954752760f6c780a74507b0 --- .../server/input/InputManagerService.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 8d0dac96c0830..ee91b632d87c9 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -1022,30 +1022,53 @@ public class InputManagerService extends IInputManager.Stub return list.toArray(new KeyboardLayout[list.size()]); } - @Override + @Override // Binder call public KeyboardLayout[] getKeyboardLayoutsForInputDevice( final InputDeviceIdentifier identifier) { - final ArrayList list = new ArrayList(); + final String[] enabledLayoutDescriptors = + getEnabledKeyboardLayoutsForInputDevice(identifier); + final ArrayList enabledLayouts = + new ArrayList(enabledLayoutDescriptors.length); + final ArrayList potentialLayouts = new ArrayList(); visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { boolean mHasSeenDeviceSpecificLayout; @Override public void visitKeyboardLayout(Resources resources, int keyboardLayoutResId, KeyboardLayout layout) { + // First check if it's enabled. If the keyboard layout is enabled then we always + // want to return it as a possible layout for the device. + for (String s : enabledLayoutDescriptors) { + if (s != null && s.equals(layout.getDescriptor())) { + enabledLayouts.add(layout); + return; + } + } + // Next find any potential layouts that aren't yet enabled for the device. For + // devices that have special layouts we assume there's a reason that the generic + // layouts don't work for them so we don't want to return them since it's likely + // to result in a poor user experience. if (layout.getVendorId() == identifier.getVendorId() && layout.getProductId() == identifier.getProductId()) { if (!mHasSeenDeviceSpecificLayout) { mHasSeenDeviceSpecificLayout = true; - list.clear(); + potentialLayouts.clear(); } - list.add(layout); + potentialLayouts.add(layout); } else if (layout.getVendorId() == -1 && layout.getProductId() == -1 && !mHasSeenDeviceSpecificLayout) { - list.add(layout); + potentialLayouts.add(layout); } } }); - return list.toArray(new KeyboardLayout[list.size()]); + final int enabledLayoutSize = enabledLayouts.size(); + final int potentialLayoutSize = potentialLayouts.size(); + KeyboardLayout[] layouts = new KeyboardLayout[enabledLayoutSize + potentialLayoutSize]; + enabledLayouts.toArray(layouts); + for (int i = 0; i < potentialLayoutSize; i++) { + layouts[enabledLayoutSize + i] = potentialLayouts.get(i); + } + return layouts; } @Override // Binder call