From f61e260ca7e980d15adb0e1ce935b5dcca1cc12a Mon Sep 17 00:00:00 2001 From: hughchen Date: Mon, 10 Feb 2020 20:02:45 +0800 Subject: Fix ConcurrentModificationException on CachedBluetoothDevice This CL use CopyOnWriteArrayList to avoid ConcurrentModificationException. Bug: 148115479 Test: manually Change-Id: I1944b8ffb14bf2f3f6613d2b5ab6a5fbc9552d57 --- .../com/android/settingslib/bluetooth/CachedBluetoothDevice.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 3aa35cb48c38..5d1e4cbf8b72 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -41,7 +41,6 @@ import com.android.settingslib.Utils; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -71,10 +70,10 @@ public class CachedBluetoothDevice implements Comparable short mRssi; // mProfiles and mRemovedProfiles does not do swap() between main and sub device. It is // because current sub device is only for HearingAid and its profile is the same. - private final List mProfiles = new ArrayList<>(); + private final Collection mProfiles = new CopyOnWriteArrayList<>(); // List of profiles that were previously in mProfiles, but have been removed - private final List mRemovedProfiles = new ArrayList<>(); + private final Collection mRemovedProfiles = new CopyOnWriteArrayList<>(); // Device supports PANU but not NAP: remove PanProfile after device disconnects from NAP private boolean mLocalNapRoleConnected; @@ -717,7 +716,7 @@ public class CachedBluetoothDevice implements Comparable } public List getProfiles() { - return Collections.unmodifiableList(mProfiles); + return new ArrayList<>(mProfiles); } public List getConnectableProfiles() { @@ -734,7 +733,7 @@ public class CachedBluetoothDevice implements Comparable } public List getRemovedProfiles() { - return mRemovedProfiles; + return new ArrayList<>(mRemovedProfiles); } public void registerCallback(Callback callback) { -- cgit v1.2.3-59-g8ed1b