diff options
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(); } } |