From ad08b5b831d4e7abee46593686f235f45be65b93 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Wed, 15 Jan 2020 13:59:00 -0500 Subject: [PATCH] DO NOT MERGE: Use a copy of bt device profile list when updating CachedBluetoothDevice#getProfiles() only returns a Collections.unmodifiableList which isn't thread safe. Use a copy in BluetoothControllerImpl so we can avoid a CME Test: atest SystemUITests Bug: 146828136 Change-Id: I451a746836c67b8b82f26f4f39b5363ac5e0ea79 --- .../android/settingslib/bluetooth/CachedBluetoothDevice.java | 4 ++++ .../systemui/statusbar/policy/BluetoothControllerImpl.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 8f164f1592d31..c7d72f2e3ce40 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -661,6 +661,10 @@ public class CachedBluetoothDevice implements Comparable return Collections.unmodifiableList(mProfiles); } + public List getProfileListCopy() { + return new ArrayList<>(mProfiles); + } + public List getConnectableProfiles() { List connectableProfiles = new ArrayList(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java index 351579a957104..7d562fbdfe611 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java @@ -277,7 +277,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa boolean otherProfileConnected = false; for (CachedBluetoothDevice device : getDevices()) { - for (LocalBluetoothProfile profile : device.getProfiles()) { + for (LocalBluetoothProfile profile : device.getProfileListCopy()) { int profileId = profile.getProfileId(); boolean isConnected = device.isConnectedProfile(profile); if (profileId == BluetoothProfile.HEADSET