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

Commit 24a9de23 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix flakiness when BluetoothDevice is not initialized" into main

parents 439a8ae0 5e11f4e3
Loading
Loading
Loading
Loading
+34 −25
Original line number Diff line number Diff line
@@ -266,18 +266,22 @@ public class AudioDeviceBrokerTest {
                    .adoptShellPermissionIdentity(Manifest.permission.BLUETOOTH_PRIVILEGED);

            // no metadata set
            assertTrue(mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_DEFAULT.getBytes()));
            assertFalse(
                    mAudioDeviceBroker.isBluetoothAudioDeviceCategoryFixed(
            if (mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_DEFAULT.getBytes())) {
                assertFalse(mAudioDeviceBroker.isBluetoothAudioDeviceCategoryFixed(
                        mFakeBtDevice.getAddress()));
            }

            // metadata set
            assertTrue(mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_HEADSET.getBytes()));
            if (mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_HEADSET.getBytes())) {
                assertTrue(mAudioDeviceBroker.isBluetoothAudioDeviceCategoryFixed(
                        mFakeBtDevice.getAddress()));
            }
        } finally {
            // reset the metadata device type
            mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_DEFAULT.getBytes());
            InstrumentationRegistry.getInstrumentation().getUiAutomation()
                    .dropShellPermissionIdentity();
        }
@@ -304,25 +308,30 @@ public class AudioDeviceBrokerTest {
                    .adoptShellPermissionIdentity(Manifest.permission.BLUETOOTH_PRIVILEGED);

            // no metadata set
            assertTrue(mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_DEFAULT.getBytes()));
            if (mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_DEFAULT.getBytes())) {
                assertEquals(AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER,
                        mAudioDeviceBroker.getAndUpdateBtAdiDeviceStateCategoryForAddress(
                                mFakeBtDevice.getAddress()));
                verify(mMockAudioService,
                        timeout(MAX_MESSAGE_HANDLING_DELAY_MS).times(0)).onUpdatedAdiDeviceState(
                        eq(devState));
            }

            // metadata set
            assertTrue(mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_HEADSET.getBytes()));
            if (mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_HEADSET.getBytes())) {
                assertEquals(AudioManager.AUDIO_DEVICE_CATEGORY_HEADPHONES,
                        mAudioDeviceBroker.getAndUpdateBtAdiDeviceStateCategoryForAddress(
                                mFakeBtDevice.getAddress()));
                verify(mMockAudioService,
                        timeout(MAX_MESSAGE_HANDLING_DELAY_MS)).onUpdatedAdiDeviceState(
                        any());
            }
        } finally {
            // reset the metadata device type
            mFakeBtDevice.setMetadata(BluetoothDevice.METADATA_DEVICE_TYPE,
                    DEVICE_TYPE_DEFAULT.getBytes());
            InstrumentationRegistry.getInstrumentation().getUiAutomation()
                    .dropShellPermissionIdentity();
        }