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

Commit e5c8ca00 authored by Sravan Kumar V's avatar Sravan Kumar V Committed by Linux Build Service Account
Browse files

Pbap: Avoid recursive calling during turn off BT

Use case:
1. Turn ON BT
2. Start inquiry
3. Turn OFF BT
4. Repeat steps 1 to 3 for 1000 iterations

Failure:
"Unfortunately, Bluetooth share has stopped" error comes.

Root cause:
Handler is made null by call to closeService() called via
BT_TURNING_OFF -> closeService() -> onDestroye() ->
mSessionStatusHandler made NULL -> closeService()
going to recursive call.

Fix:
Before initiate shutdown msg check closeService API
was called or not using flag which helps to avoid recursive
calling to fix a relevant NPE.
Set PBAP Profile state to disconnected if not already set.

CRs-Fixed: 1045017
Change-Id: I362678772138257510727c6fa2cdb9582aa6e536
parent 9179d70b
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -434,12 +434,15 @@ public class BluetoothPbapService extends Service implements IObexConnectionHand
        }

        super.onDestroy();
        if (getState() != BluetoothPbap.STATE_DISCONNECTED) {
            setState(BluetoothPbap.STATE_DISCONNECTED, BluetoothPbap.RESULT_CANCELED);
        }
        if (DEBUG)
            Log.d(TAG, "StatusHandler :" + mSessionStatusHandler + " mInterrupted:" + mInterrupted);
        // synchronize call to closeService by sending SHUTDOWN Message
        if (mSessionStatusHandler != null){
            Log.d(TAG, " onDestroy, sending SHUTDOWN Message");
            mSessionStatusHandler.sendMessage(mSessionStatusHandler
                .obtainMessage(SHUTDOWN));
        if (mSessionStatusHandler != null && (!mInterrupted)) {
            if (DEBUG) Log.d(TAG, " onDestroy, sending SHUTDOWN Message");
            mSessionStatusHandler.sendMessage(mSessionStatusHandler.obtainMessage(SHUTDOWN));
        }
    }

@@ -792,7 +795,7 @@ public class BluetoothPbapService extends Service implements IObexConnectionHand
                            .obtainMessage(AUTH_TIMEOUT), USER_CONFIRM_TIMEOUT_VALUE);
                    break;
                case SHUTDOWN:
                    Log.d(TAG, "Closing PBAP service");
                    if (DEBUG) Log.d(TAG, "Closing PBAP service ");
                    closeService();
                    break;
                case MSG_ACQUIRE_WAKE_LOCK:
@@ -826,6 +829,10 @@ public class BluetoothPbapService extends Service implements IObexConnectionHand
        setState(state, BluetoothPbap.RESULT_SUCCESS);
    }

    private int getState() {
        return mState;
    }

    private synchronized void setState(int state, int result) {
        if (state != mState) {
            if (DEBUG) Log.d(TAG, "Pbap state " + mState + " -> " + state + ", result = "