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

Commit c7ceab19 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "Fix write lock locking mechanisme"

parents feff455d bbc90946
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -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();
                    }
                }