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

Commit 09c74d53 authored by William Escande's avatar William Escande
Browse files

SystemServer: Access adapter with lock

Accessing the mAdapter should be done while holding a readLock to
prevent concurrent access.
In the future, the lock should no longer be necessary as all access to
the mAdapter will be done on the correct thread

Test: m service-bluetooth | no op change
Bug: 288450479
Change-Id: I77888bd85a7d1e1c9a346d2ea1b9fb5fef9f82a8
parent 7eb4a475
Loading
Loading
Loading
Loading
+16 −25
Original line number Diff line number Diff line
@@ -1213,35 +1213,26 @@ class BluetoothManagerService {
                android.Manifest.permission.BLUETOOTH_PRIVILEGED,
            })
    private void sendBrEdrDownCallback(AttributionSource source) {
        Log.d(TAG, "Calling sendBrEdrDownCallback callbacks");

        mAdapterLock.readLock().lock();
        try {
            if (mAdapter == null) {
                Log.w(TAG, "sendBrEdrDownCallback: mAdapter is null");
                return;
            }

            if (isBleAppPresent()) {
                // Need to stay at BLE ON. Disconnect all Gatt connections
                Log.i(TAG, "sendBrEdrDownCallback: Staying in BLE_ON");
            try {
                mAdapter.unregAllGattClient(source);
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, "Unable to disconnect all apps.", e);
            }
            } else {
                Log.i(TAG, "sendBrEdrDownCallback: Stopping ble");
            mAdapterLock.readLock().lock();
            try {
                if (mAdapter != null) {
                mAdapter.stopBle(source);
            }
        } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, "Call to stopBle() failed.", e);
            Log.e(TAG, "sendBrEdrDownCallback: Call to mAdapter failed.", e);
        } finally {
            mAdapterLock.readLock().unlock();
        }
    }
    }

    boolean enableNoAutoConnect(String packageName) {
        if (isSatelliteModeOn()) {