Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06b652cd authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Automerger Merge Worker
Browse files

Merge "Fix: Cache key should include Layout type" into udc-dev am: 9ae95fb7 am: 219f87d2

parents de6f2499 219f87d2
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -562,7 +562,7 @@ final class KeyboardLayoutManager implements InputManager.InputDeviceListener {
                key.append(",languageTag:").append(inputDevice.getKeyboardLanguageTag());
                key.append(",languageTag:").append(inputDevice.getKeyboardLanguageTag());
            }
            }
            if (!TextUtils.isEmpty(inputDevice.getKeyboardLayoutType())) {
            if (!TextUtils.isEmpty(inputDevice.getKeyboardLayoutType())) {
                key.append(",layoutType:").append(inputDevice.getKeyboardLanguageTag());
                key.append(",layoutType:").append(inputDevice.getKeyboardLayoutType());
            }
            }
        }
        }
        return key.toString();
        return key.toString();
+28 −6
Original line number Original line Diff line number Diff line
@@ -85,6 +85,9 @@ class KeyboardLayoutManagerTests {
        const val DEVICE_ID = 1
        const val DEVICE_ID = 1
        const val VENDOR_SPECIFIC_DEVICE_ID = 2
        const val VENDOR_SPECIFIC_DEVICE_ID = 2
        const val ENGLISH_DVORAK_DEVICE_ID = 3
        const val ENGLISH_DVORAK_DEVICE_ID = 3
        const val ENGLISH_QWERTY_DEVICE_ID = 4
        const val DEFAULT_VENDOR_ID = 123
        const val DEFAULT_PRODUCT_ID = 456
        const val USER_ID = 4
        const val USER_ID = 4
        const val IME_ID = "ime_id"
        const val IME_ID = "ime_id"
        const val PACKAGE_NAME = "KeyboardLayoutManagerTests"
        const val PACKAGE_NAME = "KeyboardLayoutManagerTests"
@@ -122,6 +125,7 @@ class KeyboardLayoutManagerTests {
    private lateinit var keyboardDevice: InputDevice
    private lateinit var keyboardDevice: InputDevice
    private lateinit var vendorSpecificKeyboardDevice: InputDevice
    private lateinit var vendorSpecificKeyboardDevice: InputDevice
    private lateinit var englishDvorakKeyboardDevice: InputDevice
    private lateinit var englishDvorakKeyboardDevice: InputDevice
    private lateinit var englishQwertyKeyboardDevice: InputDevice


    @Before
    @Before
    fun setup() {
    fun setup() {
@@ -150,17 +154,26 @@ class KeyboardLayoutManagerTests {
        Mockito.`when`(context.getSystemService(Mockito.eq(Context.INPUT_SERVICE)))
        Mockito.`when`(context.getSystemService(Mockito.eq(Context.INPUT_SERVICE)))
            .thenReturn(inputManager)
            .thenReturn(inputManager)


        keyboardDevice = createKeyboard(DEVICE_ID, 0, 0, "", "")
        keyboardDevice = createKeyboard(DEVICE_ID, DEFAULT_VENDOR_ID, DEFAULT_PRODUCT_ID, "", "")
        vendorSpecificKeyboardDevice = createKeyboard(VENDOR_SPECIFIC_DEVICE_ID, 1, 1, "", "")
        vendorSpecificKeyboardDevice = createKeyboard(VENDOR_SPECIFIC_DEVICE_ID, 1, 1, "", "")
        englishDvorakKeyboardDevice =
        englishDvorakKeyboardDevice = createKeyboard(ENGLISH_DVORAK_DEVICE_ID, DEFAULT_VENDOR_ID,
            createKeyboard(ENGLISH_DVORAK_DEVICE_ID, 0, 0, "en", "dvorak")
                DEFAULT_PRODUCT_ID, "en", "dvorak")
        englishQwertyKeyboardDevice = createKeyboard(ENGLISH_QWERTY_DEVICE_ID, DEFAULT_VENDOR_ID,
                DEFAULT_PRODUCT_ID, "en", "qwerty")
        Mockito.`when`(iInputManager.inputDeviceIds)
        Mockito.`when`(iInputManager.inputDeviceIds)
            .thenReturn(intArrayOf(DEVICE_ID, VENDOR_SPECIFIC_DEVICE_ID, ENGLISH_DVORAK_DEVICE_ID))
            .thenReturn(intArrayOf(
                DEVICE_ID,
                VENDOR_SPECIFIC_DEVICE_ID,
                ENGLISH_DVORAK_DEVICE_ID,
                ENGLISH_QWERTY_DEVICE_ID
            ))
        Mockito.`when`(iInputManager.getInputDevice(DEVICE_ID)).thenReturn(keyboardDevice)
        Mockito.`when`(iInputManager.getInputDevice(DEVICE_ID)).thenReturn(keyboardDevice)
        Mockito.`when`(iInputManager.getInputDevice(VENDOR_SPECIFIC_DEVICE_ID))
        Mockito.`when`(iInputManager.getInputDevice(VENDOR_SPECIFIC_DEVICE_ID))
            .thenReturn(vendorSpecificKeyboardDevice)
            .thenReturn(vendorSpecificKeyboardDevice)
        Mockito.`when`(iInputManager.getInputDevice(ENGLISH_DVORAK_DEVICE_ID))
        Mockito.`when`(iInputManager.getInputDevice(ENGLISH_DVORAK_DEVICE_ID))
            .thenReturn(englishDvorakKeyboardDevice)
            .thenReturn(englishDvorakKeyboardDevice)
        Mockito.`when`(iInputManager.getInputDevice(ENGLISH_QWERTY_DEVICE_ID))
                .thenReturn(englishQwertyKeyboardDevice)
    }
    }


    private fun setupBroadcastReceiver() {
    private fun setupBroadcastReceiver() {
@@ -778,14 +791,23 @@ class KeyboardLayoutManagerTests {
    @Test
    @Test
    fun testNewUi_getDefaultKeyboardLayoutForInputDevice_withHwLanguageTagAndLayoutType() {
    fun testNewUi_getDefaultKeyboardLayoutForInputDevice_withHwLanguageTagAndLayoutType() {
        NewSettingsApiFlag(true).use {
        NewSettingsApiFlag(true).use {
            // Should return English dvorak even if IME current layout is qwerty, since HW says the
            val frenchSubtype = createImeSubtypeForLanguageTagAndLayoutType("fr", "azerty")
            // Should return English dvorak even if IME current layout is French, since HW says the
            // keyboard is a Dvorak keyboard
            // keyboard is a Dvorak keyboard
            assertCorrectLayout(
            assertCorrectLayout(
                englishDvorakKeyboardDevice,
                englishDvorakKeyboardDevice,
                createImeSubtypeForLanguageTagAndLayoutType("en", "qwerty"),
                frenchSubtype,
                createLayoutDescriptor("keyboard_layout_english_us_dvorak")
                createLayoutDescriptor("keyboard_layout_english_us_dvorak")
            )
            )


            // Back to back changing HW keyboards with same product and vendor ID but different
            // language and layout type should configure the layouts correctly.
            assertCorrectLayout(
                englishQwertyKeyboardDevice,
                frenchSubtype,
                createLayoutDescriptor("keyboard_layout_english_us")
            )

            // Fallback to IME information if the HW provided layout script is incompatible with the
            // Fallback to IME information if the HW provided layout script is incompatible with the
            // provided IME subtype
            // provided IME subtype
            assertCorrectLayout(
            assertCorrectLayout(