diff options
| author | 2024-02-13 08:21:06 +0000 | |
|---|---|---|
| committer | 2024-02-13 08:21:06 +0000 | |
| commit | 701ce348f45837749e68c4dcd5db50422ed2e6dc (patch) | |
| tree | 6994dd1ce32886e1ecb5653840990ba8f37428bc | |
| parent | 89e122c8e8fa5a2c8bd03d30bdae9da6380b5216 (diff) | |
| parent | fdddc978fa2e910431bf49eb87dcbdf573aae3f3 (diff) | |
Merge "Fetch bluetooth cached device name outside synchronized block." into main
| -rw-r--r-- | packages/SystemUI/aconfig/systemui.aconfig | 9 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java | 19 |
2 files changed, 25 insertions, 3 deletions
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig index 56576f1f0c03..407873e02aea 100644 --- a/packages/SystemUI/aconfig/systemui.aconfig +++ b/packages/SystemUI/aconfig/systemui.aconfig @@ -420,3 +420,12 @@ flag { } } +flag { + name: "get_connected_device_name_unsynchronized" + namespace: "systemui" + description: "Decide whether to fetch the connected bluetooth device name outside a synchronized block." + bug: "323995015" + metadata { + purpose: PURPOSE_BUGFIX + } +} 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 fc2f6e958b32..c089092c9b86 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java @@ -35,6 +35,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; +import com.android.systemui.Flags; import com.android.systemui.bluetooth.BluetoothLogger; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.qualifiers.Background; @@ -240,9 +241,21 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @WorkerThread @Override public String getConnectedDeviceName() { - synchronized (mConnectedDevices) { - if (mConnectedDevices.size() == 1) { - return mConnectedDevices.get(0).getName(); + if (Flags.getConnectedDeviceNameUnsynchronized()) { + CachedBluetoothDevice connectedDevice = null; + // Calling the getName() API for CachedBluetoothDevice outside the synchronized block + // so that the main thread is not blocked. + synchronized (mConnectedDevices) { + if (mConnectedDevices.size() == 1) { + connectedDevice = mConnectedDevices.get(0); + } + } + return connectedDevice != null ? connectedDevice.getName() : null; + } else { + synchronized (mConnectedDevices) { + if (mConnectedDevices.size() == 1) { + return mConnectedDevices.get(0).getName(); + } } } return null; |