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

Commit e653c11a authored by Stanley Tng's avatar Stanley Tng Committed by android-build-merger
Browse files

Merge "Fixed ConcurrentModificationException with HearingAids profile" into pi-dev

am: 36f15ae2

Change-Id: I095a1632f29d9ac94859a3d2eace1bc207632334
parents d3a955cd 36f15ae2
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -27,8 +27,10 @@ import com.android.internal.annotations.VisibleForTesting;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Set;
import java.util.Objects;
import java.util.Objects;


/**
/**
@@ -191,6 +193,7 @@ public class CachedBluetoothDeviceManager {
            log("updateHearingAidsDevices: getHearingAidProfile() is null");
            log("updateHearingAidsDevices: getHearingAidProfile() is null");
            return;
            return;
        }
        }
        final Set<Long> syncIdChangedSet = new HashSet<Long>();
        for (CachedBluetoothDevice cachedDevice : mCachedDevices) {
        for (CachedBluetoothDevice cachedDevice : mCachedDevices) {
            if (cachedDevice.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
            if (cachedDevice.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
                continue;
                continue;
@@ -200,9 +203,12 @@ public class CachedBluetoothDeviceManager {


            if (newHiSyncId != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
            if (newHiSyncId != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
                cachedDevice.setHiSyncId(newHiSyncId);
                cachedDevice.setHiSyncId(newHiSyncId);
                onHiSyncIdChanged(newHiSyncId);
                syncIdChangedSet.add(newHiSyncId);
            }
            }
        }
        }
        for (Long syncId : syncIdChangedSet) {
            onHiSyncIdChanged(syncId);
        }
    }
    }


    /**
    /**
+4 −1
Original line number Original line Diff line number Diff line
@@ -486,11 +486,14 @@ public class CachedBluetoothDeviceManagerTest {
        doAnswer((invocation) -> mHearingAidProfile).when(mLocalProfileManager)
        doAnswer((invocation) -> mHearingAidProfile).when(mLocalProfileManager)
            .getHearingAidProfile();
            .getHearingAidProfile();
        doAnswer((invocation) -> HISYNCID1).when(mHearingAidProfile).getHiSyncId(mDevice1);
        doAnswer((invocation) -> HISYNCID1).when(mHearingAidProfile).getHiSyncId(mDevice1);
        doAnswer((invocation) -> HISYNCID1).when(mHearingAidProfile).getHiSyncId(mDevice2);
        mCachedDeviceManager.mCachedDevices.add(mCachedDevice1);
        mCachedDeviceManager.mCachedDevices.add(mCachedDevice1);
        mCachedDeviceManager.mCachedDevices.add(mCachedDevice2);
        mCachedDeviceManager.updateHearingAidsDevices(mLocalProfileManager);
        mCachedDeviceManager.updateHearingAidsDevices(mLocalProfileManager);


        // Assert that the mCachedDevice1 has an updated HiSyncId.
        // Assert that the mCachedDevice1 and mCachedDevice2 have an updated HiSyncId.
        assertThat(mCachedDevice1.getHiSyncId()).isEqualTo(HISYNCID1);
        assertThat(mCachedDevice1.getHiSyncId()).isEqualTo(HISYNCID1);
        assertThat(mCachedDevice2.getHiSyncId()).isEqualTo(HISYNCID1);
    }
    }


    /**
    /**