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

Commit d09a777d authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Hearing Aid: Remove device from HiSyncIdMap when unbonded

Bug: 116317072
Bug: 116044083
Bug: 113022639
Test: Instrumentation
Change-Id: Ieb895bfbd1a25fcf542b528b0b99622979751e1d
Merged-In: I22d434d252bcd31a058b773de1841f5c4e921375
(cherry picked from commit f29a4b7c)
parent b2e3f7f9
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -405,6 +405,16 @@ public class HearingAidService extends ProfileService {
        }
    }

    /**
     * Get the HiSyncIdMap for testing
     *
     * @return mDeviceHiSyncIdMap
     */
    @VisibleForTesting
    Map<BluetoothDevice, Long> getHiSyncIdMap() {
        return mDeviceHiSyncIdMap;
    }

    int getConnectionState(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        synchronized (mStateMachines) {
@@ -658,6 +668,7 @@ public class HearingAidService extends ProfileService {
        if (bondState != BluetoothDevice.BOND_NONE) {
            return;
        }
        mDeviceHiSyncIdMap.remove(device);
        synchronized (mStateMachines) {
            HearingAidStateMachine sm = mStateMachines.get(device);
            if (sm == null) {
+25 −0
Original line number Diff line number Diff line
@@ -916,6 +916,31 @@ public class HearingAidServiceTest {
                mService.getConnectionState(mLeftDevice));
    }

    /**
     * Test that the service can update HiSyncId from native message
     */
    @Test
    public void getHiSyncIdFromNative_addToMap() {
        getHiSyncIdFromNative();
        Assert.assertTrue("hiSyncIdMap should contain mLeftDevice",
                mService.getHiSyncIdMap().containsKey(mLeftDevice));
        Assert.assertTrue("hiSyncIdMap should contain mRightDevice",
                mService.getHiSyncIdMap().containsKey(mRightDevice));
        Assert.assertTrue("hiSyncIdMap should contain mSingleDevice",
                mService.getHiSyncIdMap().containsKey(mSingleDevice));
    }

    /**
     * Test that the service removes the device from HiSyncIdMap when it's unbonded
     */
    @Test
    public void deviceUnbonded_removeHiSyncId() {
        getHiSyncIdFromNative();
        mService.bondStateChanged(mLeftDevice, BluetoothDevice.BOND_NONE);
        Assert.assertFalse("hiSyncIdMap shouldn't contain mLeftDevice",
                mService.getHiSyncIdMap().containsKey(mLeftDevice));
    }

    private void connectDevice(BluetoothDevice device) {
        HearingAidStackEvent connCompletedEvent;