Force input device changed callback when Keyboard layout info is updated
Virtual keyboard creation uses KEYBOARD_LAYOUT_ASSOCIATION reconfig to
associated input device with keyboard layout info. But this can
happen after input device added (Race condition between device creation
and input device added callback.)
If input device already added then we sometimes don't get input device
changed callback since the generation is same.
Test: atest VirtualKeyboardLayoutTest
Bug: 277778640
Change-Id: I218b6d797da27ec3a383fbcd2ebeacb0afbf5fab
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 0b50504..d56db11 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -3687,6 +3687,7 @@
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
/*changes=*/{});
+ uint32_t generation = mReader->getContext()->getGeneration();
mFakePolicy->addKeyboardLayoutAssociation(DEVICE_LOCATION, DEVICE_KEYBOARD_LAYOUT_INFO);
unused += mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
@@ -3697,6 +3698,14 @@
deviceInfo.getKeyboardLayoutInfo()->languageTag);
ASSERT_EQ(DEVICE_KEYBOARD_LAYOUT_INFO.layoutType,
deviceInfo.getKeyboardLayoutInfo()->layoutType);
+ ASSERT_TRUE(mReader->getContext()->getGeneration() != generation);
+
+ // Call change layout association with the same values: Generation shouldn't change
+ generation = mReader->getContext()->getGeneration();
+ mFakePolicy->addKeyboardLayoutAssociation(DEVICE_LOCATION, DEVICE_KEYBOARD_LAYOUT_INFO);
+ unused += mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::Change::KEYBOARD_LAYOUT_ASSOCIATION);
+ ASSERT_TRUE(mReader->getContext()->getGeneration() == generation);
}
TEST_F(KeyboardInputMapperTest, LayoutInfoCorrectlyMapped) {