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

Commit 89d55ad7 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Fix stuck in pairing when BT is turned off.

When pairing is stuck, on turning BT off, we were
not setting the outgoing parining variable to null in
setBondState because of the extra check for isEnabled.

isEnabled check was added to prevent the proxy crash in
setProfilePriorities function. Proxies should never be null.
Add a safety check and also some extra logs to debug the problem.

Change-Id: I694dfeb8fa9426b3916775ca868c2313fa9c22ee
parent 152abefc
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ class BluetoothBondState {
    /** reason is ignored unless state == BOND_NOT_BONDED */
    public synchronized void setBondState(String address, int state, int reason) {
        if (DBG) Log.d(TAG, "setBondState " + "address" + " " + state + "reason: " + reason);
        if (!mService.isEnabled()) return;

        int oldState = getBondState(address);
        if (oldState == state) {
@@ -459,19 +458,29 @@ class BluetoothBondState {
        //   intent reach them. But that left a small time gap that could reject
        //   incoming connection due to undefined priorities.
        if (state == BluetoothDevice.BOND_BONDED) {
            if (mA2dpProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
            if (mA2dpProxy != null &&
                  mA2dpProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
                mA2dpProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_ON);
            }

            if (mHeadsetProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
            if (mHeadsetProxy != null &&
                  mHeadsetProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
                mHeadsetProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_ON);
            }
        } else if (state == BluetoothDevice.BOND_NONE) {
            if (mA2dpProxy != null) {
                mA2dpProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_UNDEFINED);
            }
            if (mHeadsetProxy != null) {
                mHeadsetProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_UNDEFINED);
            }
        }

        if (mA2dpProxy == null || mHeadsetProxy == null) {
            Log.e(TAG, "Proxy is null:" + mA2dpProxy + ":" + mHeadsetProxy);
        }
    }

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {