Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebc99cb2 authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Merge "Fix write lock locking mechanisme" am: c7ceab19 am: aa1288c9 am:...

Merge "Fix write lock locking mechanisme" am: c7ceab19 am: aa1288c9 am: f836ba2d am: 0b730f05

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2063178



Change-Id: Id3971ca667fac3c2119b14b1723154360c31df8f
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents bf2b5da5 0b730f05
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -84,6 +84,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;

/**
@@ -990,8 +991,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);
@@ -3834,8 +3839,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) -> {
@@ -3869,7 +3878,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();
@@ -3880,6 +3891,8 @@ public final class BluetoothAdapter {
                        if (mBluetoothLeScanner != null) {
                            mBluetoothLeScanner.cleanup();
                        }
                    } finally {
                        l.unlock();
                    }
                }