From 81f10425e6b1978444a789120f33e333afefb887 Mon Sep 17 00:00:00 2001 From: Vaibhav Devmurari Date: Sun, 23 Apr 2023 14:38:21 +0000 Subject: Show all KCMs if IME doesn't provide language tag information Test: atest KeyboardLayoutManagerTests Bug: 279281653 Change-Id: Idce443602bfa844b59754f980f8fc0ec0b2b7e66 --- .../server/input/KeyboardLayoutManager.java | 2 +- .../server/input/KeyboardLayoutManagerTests.kt | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/input/KeyboardLayoutManager.java b/services/core/java/com/android/server/input/KeyboardLayoutManager.java index 72c7dadac271..69dd68c6dfcb 100644 --- a/services/core/java/com/android/server/input/KeyboardLayoutManager.java +++ b/services/core/java/com/android/server/input/KeyboardLayoutManager.java @@ -1262,7 +1262,7 @@ final class KeyboardLayoutManager implements InputManager.InputDeviceListener { private static boolean isLayoutCompatibleWithLanguageTag(KeyboardLayout layout, @NonNull String languageTag) { LocaleList layoutLocales = layout.getLocales(); - if (layoutLocales.isEmpty()) { + if (layoutLocales.isEmpty() || TextUtils.isEmpty(languageTag)) { // KCM file doesn't have an associated language tag. This can be from // a 3rd party app so need to include it as a potential layout. return true; diff --git a/services/tests/servicestests/src/com/android/server/input/KeyboardLayoutManagerTests.kt b/services/tests/servicestests/src/com/android/server/input/KeyboardLayoutManagerTests.kt index ea3f3bca32ff..d0d28c3f7ec0 100644 --- a/services/tests/servicestests/src/com/android/server/input/KeyboardLayoutManagerTests.kt +++ b/services/tests/servicestests/src/com/android/server/input/KeyboardLayoutManagerTests.kt @@ -633,6 +633,30 @@ class KeyboardLayoutManagerTests { 0, keyboardLayouts.size ) + + // If IME doesn't have a corresponding language tag, then should show all available + // layouts no matter the script code. + keyboardLayouts = + keyboardLayoutManager.getKeyboardLayoutListForInputDevice( + keyboardDevice.identifier, USER_ID, imeInfo, null + ) + assertNotEquals( + "New UI: getKeyboardLayoutListForInputDevice API should return all layouts if" + + "language tag or subtype not provided", + 0, + keyboardLayouts.size + ) + assertTrue("New UI: getKeyboardLayoutListForInputDevice API should contain Latin " + + "layouts if language tag or subtype not provided", + containsLayout(keyboardLayouts, ENGLISH_US_LAYOUT_DESCRIPTOR) + ) + assertTrue("New UI: getKeyboardLayoutListForInputDevice API should contain Cyrillic " + + "layouts if language tag or subtype not provided", + containsLayout( + keyboardLayouts, + createLayoutDescriptor("keyboard_layout_russian") + ) + ) } } -- cgit v1.2.3-59-g8ed1b