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

Commit 1b715a66 authored by William Escande's avatar William Escande
Browse files

No longer call service to know its state

Since the AdapterService always call the BMS with a callback to update
its state, the BMS does not need to make an extra binder call to get the
current state value

Bug: 262605980
Test: Manual
Test: adb shell cmd bluetooth_manager disable && \
      adb shell cmd bluetooth_manager wait-for-state:STATE_OFF &&\
      adb shell cmd bluetooth_manager enable
Change-Id: I27bb747a73ab990e50d41d1bf6d939e1f5668d6d
parent 181d3523
Loading
Loading
Loading
Loading
+5 −46
Original line number Diff line number Diff line
@@ -491,16 +491,7 @@ class BluetoothManagerService {
                }
            }

            int st = STATE_OFF;
            try {
                mBluetoothLock.readLock().lock();
                st = synchronousGetState();
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, "Unable to call getState", e);
                return;
            } finally {
                mBluetoothLock.readLock().unlock();
            }
            int st = mState.get();

            Log.d(
                    TAG,
@@ -1026,14 +1017,6 @@ class BluetoothManagerService {
        return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
    }

    @GuardedBy("mBluetoothLock")
    private int synchronousGetState() throws RemoteException, TimeoutException {
        if (mBluetooth == null) return STATE_OFF;
        final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
        mBluetooth.getState(recv);
        return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(STATE_OFF);
    }

    @GuardedBy("mBluetoothLock")
    private void synchronousOnBrEdrDown(AttributionSource attributionSource)
            throws RemoteException, TimeoutException {
@@ -1111,17 +1094,7 @@ class BluetoothManagerService {
    }

    int getState() {
        mBluetoothLock.readLock().lock();
        try {
            if (mBluetooth != null) {
                return synchronousGetState();
            }
        } catch (RemoteException | TimeoutException e) {
            Log.e(TAG, "getState()", e);
        } finally {
            mBluetoothLock.readLock().unlock();
        }
        return STATE_OFF;
        return mState.get();
    }

    class ClientDeathRecipient implements IBinder.DeathRecipient {
@@ -1209,14 +1182,12 @@ class BluetoothManagerService {
    private void disableBleScanMode() {
        mBluetoothLock.writeLock().lock();
        try {
            if (mBluetooth != null && synchronousGetState() != STATE_ON) {
            if (mBluetooth != null && mState.oneOf(STATE_ON)) {
                if (DBG) {
                    Log.d(TAG, "Resetting the mEnable flag for clean disable");
                }
                mEnable = false;
            }
        } catch (RemoteException | TimeoutException e) {
            Log.e(TAG, "getState()", e);
        } finally {
            mBluetoothLock.writeLock().unlock();
        }
@@ -1765,18 +1736,7 @@ class BluetoothManagerService {
        }

        private boolean bindService(int rebindCount) {
            int state = STATE_OFF;
            try {
                mBluetoothLock.readLock().lock();
                state = synchronousGetState();
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, "Unable to call getState", e);
                return false;
            } finally {
                mBluetoothLock.readLock().unlock();
            }

            if (state != STATE_ON) {
            if (!mState.oneOf(STATE_ON)) {
                if (DBG) {
                    Log.d(TAG, "Unable to bindService while Bluetooth is disabled");
                }
@@ -2138,8 +2098,7 @@ class BluetoothManagerService {
                    try {
                        if (mBluetooth != null) {
                            boolean isHandled = true;
                            int state = synchronousGetState();
                            switch (state) {
                            switch (mState.get()) {
                                case STATE_BLE_ON:
                                    if (isBle == 1) {
                                        Log.i(TAG, "Already at BLE_ON State");