diff options
author | William Escande <wescande@google.com> | 2022-04-14 01:56:09 +0200 |
---|---|---|
committer | William Escande <wescande@google.com> | 2022-04-14 01:59:26 +0200 |
commit | bbc909460b108a03eacefe8998fac83966915e70 (patch) | |
tree | a8772a0524c76e4323049c413fa8ef9fde88d574 /framework/java/android/bluetooth/BluetoothAdapter.java | |
parent | 94bfeecdd68ba6790e1437c49d66b278a0d05b8a (diff) |
Fix write lock locking mechanisme
Using synchronized on a instance of a writeLock is not something that
can work with read/write lock
Fix: 227963093
Test: build - Don't know how to reproduce such async behavior
Change-Id: I9f2be339a97e83f4f3a6034e71a40f632062fb09
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 4f17110e65..1759276de6 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -82,6 +82,7 @@ import java.util.UUID; import java.util.WeakHashMap; import java.util.concurrent.Executor; import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; /** @@ -962,8 +963,12 @@ public final class BluetoothAdapter { BluetoothAdapter(IBluetoothManager managerService, AttributionSource attributionSource) { mManagerService = Objects.requireNonNull(managerService); mAttributionSource = Objects.requireNonNull(attributionSource); - synchronized (mServiceLock.writeLock()) { + Lock l = mServiceLock.writeLock(); + l.lock(); + try { mService = getBluetoothService(mManagerCallback); + } finally { + l.unlock(); } mLeScanClients = new HashMap<LeScanCallback, ScanCallback>(); mToken = new Binder(DESCRIPTOR); @@ -3859,8 +3864,12 @@ public final class BluetoothAdapter { private final IBluetoothManagerCallback mManagerCallback = new IBluetoothManagerCallback.Stub() { public void onBluetoothServiceUp(IBluetooth bluetoothService) { - synchronized (mServiceLock.writeLock()) { + Lock l = mServiceLock.writeLock(); + l.lock(); + try { mService = bluetoothService; + } finally { + l.unlock(); } synchronized (mMetadataListeners) { mMetadataListeners.forEach((device, pair) -> { @@ -3894,7 +3903,9 @@ public final class BluetoothAdapter { } public void onBluetoothServiceDown() { - synchronized (mServiceLock.writeLock()) { + Lock l = mServiceLock.writeLock(); + l.lock(); + try { mService = null; if (mLeScanClients != null) { mLeScanClients.clear(); @@ -3905,6 +3916,8 @@ public final class BluetoothAdapter { if (mBluetoothLeScanner != null) { mBluetoothLeScanner.cleanup(); } + } finally { + l.unlock(); } } |