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 Original line Diff line number Diff line
@@ -491,16 +491,7 @@ class BluetoothManagerService {
                }
                }
            }
            }


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


            Log.d(
            Log.d(
                    TAG,
                    TAG,
@@ -1026,14 +1017,6 @@ class BluetoothManagerService {
        return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
        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")
    @GuardedBy("mBluetoothLock")
    private void synchronousOnBrEdrDown(AttributionSource attributionSource)
    private void synchronousOnBrEdrDown(AttributionSource attributionSource)
            throws RemoteException, TimeoutException {
            throws RemoteException, TimeoutException {
@@ -1111,17 +1094,7 @@ class BluetoothManagerService {
    }
    }


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


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


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