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

Commit 302a1abc authored by Christine Hallstrom's avatar Christine Hallstrom
Browse files

Properly check if BT is off when shutting down radios

Use BluetoothAdapter#getState() instead of
BluetoothAdapter#isEnabled() when checking if Bluetooth has turned
off, as isEnabled() is set to false early in the shutdown process
and getState() provides a better indication of the state of BT.

Bug: 27354612
Change-Id: Ic7828f0726491d49c9a14ba5d654b24f66743662
parent 630c0a3a
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ interface IBluetoothManager
    boolean enable();
    boolean enable();
    boolean enableNoAutoConnect();
    boolean enableNoAutoConnect();
    boolean disable(boolean persist);
    boolean disable(boolean persist);
    int getState();
    IBluetoothGatt getBluetoothGatt();
    IBluetoothGatt getBluetoothGatt();


    boolean bindBluetoothProfileService(int profile, IBluetoothProfileServiceConnection proxy);
    boolean bindBluetoothProfileService(int profile, IBluetoothProfileServiceConnection proxy);
+18 −0
Original line number Original line Diff line number Diff line
@@ -425,6 +425,24 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        return false;
        return false;
    }
    }


    public int getState() {
        if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
                (!checkIfCallerIsForegroundUser())) {
            Slog.w(TAG, "getState(): not allowed for non-active and non system user");
            return BluetoothAdapter.STATE_OFF;
        }

        try {
            mBluetoothLock.readLock().lock();
            if (mBluetooth != null) return mBluetooth.getState();
        } catch (RemoteException e) {
            Slog.e(TAG, "getState()", e);
        } finally {
            mBluetoothLock.readLock().unlock();
        }
        return BluetoothAdapter.STATE_OFF;
    }

    class ClientDeathRecipient implements IBinder.DeathRecipient {
    class ClientDeathRecipient implements IBinder.DeathRecipient {
        public void binderDied() {
        public void binderDied() {
            if (DBG) Slog.d(TAG, "Binder is dead -  unregister Ble App");
            if (DBG) Slog.d(TAG, "Binder is dead -  unregister Ble App");