@@ -1405,6 +1405,68 @@ TEST_F(InputReaderTest, SetPowerWakeUp) {
14051405 ASSERT_EQ (mFakeEventHub ->fakeReadKernelWakeup (3 ), false );
14061406}
14071407
1408+ TEST_F (InputReaderTest, MergeableInputDevices) {
1409+ constexpr int32_t eventHubIds[2 ] = {END_RESERVED_ID, END_RESERVED_ID + 1 };
1410+
1411+ // By default, all of the default-created eventhub devices will have the same identifier
1412+ // (implicitly vid 0, pid 0, etc.), which is why we expect them to be merged.
1413+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[0 ], " 1st" , InputDeviceClass::KEYBOARD, nullptr ));
1414+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[1 ], " 2nd" , InputDeviceClass::JOYSTICK, nullptr ));
1415+
1416+ // The two devices will be merged to one input device as they have same identifier, and none are
1417+ // pointer devices.
1418+ ASSERT_EQ (1U , mFakePolicy ->getInputDevices ().size ());
1419+ }
1420+
1421+ TEST_F (InputReaderTest, MergeableDevicesWithTouch) {
1422+ constexpr int32_t eventHubIds[3 ] = {END_RESERVED_ID, END_RESERVED_ID + 1 , END_RESERVED_ID + 2 };
1423+
1424+ // By default, all of the default-created eventhub devices will have the same identifier
1425+ // (implicitly vid 0, pid 0, etc.), which is why we expect them to be merged.
1426+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[0 ], " 1st" , InputDeviceClass::TOUCH_MT, nullptr ));
1427+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[1 ], " 2nd" , InputDeviceClass::KEYBOARD, nullptr ));
1428+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[2 ], " 3rd" , InputDeviceClass::GAMEPAD, nullptr ));
1429+
1430+ // The three devices will be merged to one input device as they have same identifier, and only
1431+ // one is a pointer device.
1432+ ASSERT_EQ (1U , mFakePolicy ->getInputDevices ().size ());
1433+ }
1434+
1435+ TEST_F (InputReaderTest, UnmergeableTouchDevices) {
1436+ SCOPED_FLAG_OVERRIDE (prevent_merging_input_pointer_devices, true );
1437+
1438+ constexpr int32_t eventHubIds[3 ] = {END_RESERVED_ID, END_RESERVED_ID + 1 , END_RESERVED_ID + 2 };
1439+
1440+ // By default, all of the default-created eventhub devices will have the same identifier
1441+ // (implicitly vid 0, pid 0, etc.), which is why they can potentially be merged.
1442+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[0 ], " 1st" , InputDeviceClass::TOUCH, nullptr ));
1443+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[1 ], " 2nd" , InputDeviceClass::TOUCH_MT, nullptr ));
1444+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[2 ], " 2nd" , InputDeviceClass::CURSOR, nullptr ));
1445+
1446+ // The three devices will not be merged, as they have same identifier, but are all pointer
1447+ // devices.
1448+ ASSERT_EQ (3U , mFakePolicy ->getInputDevices ().size ());
1449+ }
1450+
1451+ TEST_F (InputReaderTest, MergeableMixedDevices) {
1452+ SCOPED_FLAG_OVERRIDE (prevent_merging_input_pointer_devices, true );
1453+
1454+ constexpr int32_t eventHubIds[4 ] = {END_RESERVED_ID, END_RESERVED_ID + 1 , END_RESERVED_ID + 2 ,
1455+ END_RESERVED_ID + 3 };
1456+
1457+ // By default, all of the default-created eventhub devices will have the same identifier
1458+ // (implicitly vid 0, pid 0, etc.), which is why they can potentially be merged.
1459+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[0 ], " 1st" , InputDeviceClass::TOUCH, nullptr ));
1460+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[1 ], " 2nd" , InputDeviceClass::TOUCH_MT, nullptr ));
1461+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[2 ], " 3rd" , InputDeviceClass::DPAD, nullptr ));
1462+ ASSERT_NO_FATAL_FAILURE (addDevice (eventHubIds[3 ], " 4th" , InputDeviceClass::JOYSTICK, nullptr ));
1463+
1464+ // Non-touch devices can be merged with one of the touch devices, as they have same identifier,
1465+ // but the two touch devices will not combine with each other. It is not specified which touch
1466+ // device the non-touch devices merge with.
1467+ ASSERT_EQ (2U , mFakePolicy ->getInputDevices ().size ());
1468+ }
1469+
14081470// --- InputReaderIntegrationTest ---
14091471
14101472// These tests create and interact with the InputReader only through its interface.
0 commit comments