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

Commit 832915e0 authored by Jack He's avatar Jack He
Browse files

HID Test: Gate workarounds with feature flags for future removal

* Gate workarounds with associated feature flags so that when feature
  flag is removed, the workaround can be cleaned up as well

Bug: 361800494
Bug: 354758065
Test: atest -v HidHostDualModeTest
Flag: remove_input_device_on_vup
Flag: prevent_duplicate_uuid_intent
Change-Id: Ia694a9408db5e39a116b4521aedada6892541270
parent e52e3998
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -315,22 +315,32 @@ public class HidHostDualModeTest {
        }

        // Have to use Hamcrest matchers instead of Mockito matchers in MockitoHamcrest context
        if (Flags.removeInputDeviceOnVup()) {
            verifyConnectionState(mDevice, equalTo(TRANSPORT_BREDR), equalTo(STATE_CONNECTING));
            verifyConnectionState(mDevice, equalTo(TRANSPORT_BREDR), equalTo(STATE_CONNECTED));
            assertThat(mHidService.getPreferredTransport(mDevice)).isEqualTo(TRANSPORT_BREDR);
        } else {
            // Without removeInputDeviceOnVup, previous preference on LE transport might still exist
            verifyConnectionState(
                    mDevice, oneOf(TRANSPORT_BREDR, TRANSPORT_LE), equalTo(STATE_CONNECTING));
            verifyConnectionState(
                    mDevice, oneOf(TRANSPORT_BREDR, TRANSPORT_LE), equalTo(STATE_CONNECTED));
        }
        // Two ACTION_UUIDs are returned after pairing with dual mode HID device
        // 2nd ACTION_UUID and ACTION_CONNECTION_STATE_CHANGED has race condition, hence unordered
        verifyIntentReceivedUnorderedAtLeast(
                1,
                hasAction(BluetoothDevice.ACTION_UUID),
                hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice),
                hasExtra(BluetoothDevice.EXTRA_UUID,
                        allOf(Matchers.hasItemInArray(BluetoothUuid.HOGP),
                hasExtra(
                        BluetoothDevice.EXTRA_UUID,
                        allOf(
                                Matchers.hasItemInArray(BluetoothUuid.HOGP),
                                Matchers.hasItemInArray(BluetoothUuid.HID))));

        // Cannot guarantee TRANSPORT_BREDR at this moment, hence we need to check
        if (mHidService.getPreferredTransport(mDevice) == TRANSPORT_BREDR) {
        if (Flags.removeInputDeviceOnVup()
                || mHidService.getPreferredTransport(mDevice) == TRANSPORT_BREDR) {
            // Cannot guarantee TRANSPORT_BREDR without removeInputDeviceOnVup, hence we need to
            // Switch to LE transport to prepare for test cases
            mHidService.setPreferredTransport(mDevice, TRANSPORT_LE);
            verifyTransportSwitch(mDevice, TRANSPORT_BREDR, TRANSPORT_LE);
@@ -342,8 +352,9 @@ public class HidHostDualModeTest {
    @After
    public void tearDown() throws Exception {
        if (mDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
            // Restore transport to BR/EDR
            if (mHidService.getPreferredTransport(mDevice) == TRANSPORT_LE) {
            // Restore transport to BR/EDR when removeInputDeviceOnVup is not enabled
            if (!Flags.removeInputDeviceOnVup()
                    && mHidService.getPreferredTransport(mDevice) == TRANSPORT_LE) {
                boolean connected = mHidService.getConnectedDevices().contains(mDevice);
                mHidService.setPreferredTransport(mDevice, TRANSPORT_BREDR);
                if (connected) {