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

Commit 1f7ddfb2 authored by Sungsoo Lim's avatar Sungsoo Lim Committed by Gerrit Code Review
Browse files

Merge "Fix HearingAidServiceTest failure" into main

parents e4e61fa2 b49f9233
Loading
Loading
Loading
Loading
+23 −10
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ public class HearingAidServiceTest {
    private HashMap<BluetoothDevice, LinkedBlockingQueue<Intent>> mDeviceQueueMap;
    private static final int TIMEOUT_MS = 1000;

    private BroadcastReceiver mHearingAidIntentReceiver;
    private HearingAidIntentReceiver mHearingAidIntentReceiver;

    @Mock private AdapterService mAdapterService;
    @Mock private ActiveDeviceManager mActiveDeviceManager;
@@ -113,13 +113,6 @@ public class HearingAidServiceTest {
        // Override the timeout value to speed up the test
        HearingAidStateMachine.sConnectTimeoutMs = TIMEOUT_MS;    // 1s

        // Set up the Connection State Changed receiver
        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
        mHearingAidIntentReceiver = new HearingAidIntentReceiver();
        mTargetContext.registerReceiver(mHearingAidIntentReceiver, filter);

        // Get a device for testing
        mLeftDevice = TestUtils.getTestDevice(mAdapter, 0);
        mRightDevice = TestUtils.getTestDevice(mAdapter, 1);
@@ -132,12 +125,20 @@ public class HearingAidServiceTest {
                .getBondState(any(BluetoothDevice.class));
        doReturn(new ParcelUuid[]{BluetoothUuid.HEARING_AID}).when(mAdapterService)
                .getRemoteUuids(any(BluetoothDevice.class));

        // Set up the Connection State Changed receiver
        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
        mHearingAidIntentReceiver = new HearingAidIntentReceiver(mDeviceQueueMap);
        mTargetContext.registerReceiver(mHearingAidIntentReceiver, filter);
    }

    @After
    public void tearDown() throws Exception {
        stopService();
        mTargetContext.unregisterReceiver(mHearingAidIntentReceiver);
        mHearingAidIntentReceiver.clear();
        mDeviceQueueMap.clear();
        TestUtils.clearAdapterService(mAdapterService);
        reset(mAudioManager);
@@ -156,10 +157,22 @@ public class HearingAidServiceTest {
        Assert.assertNull(mService);
    }

    private class HearingAidIntentReceiver extends BroadcastReceiver {
    private static class HearingAidIntentReceiver extends BroadcastReceiver {
        HashMap<BluetoothDevice, LinkedBlockingQueue<Intent>> mDeviceQueueMap;

        public HearingAidIntentReceiver(
                HashMap<BluetoothDevice, LinkedBlockingQueue<Intent>> deviceQueueMap) {
            mDeviceQueueMap = deviceQueueMap;
        }

        public void clear() {
            mDeviceQueueMap = null;
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            if (BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
            if (BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())
                    && mDeviceQueueMap != null) {
                try {
                    BluetoothDevice device = intent.getParcelableExtra(
                            BluetoothDevice.EXTRA_DEVICE);