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

Commit 340ad66d authored by Gaurav Asati's avatar Gaurav Asati Committed by Gerrit - the friendly Code Review server
Browse files

Bluetooth: Do not accept SCO without any active listener.

 - Some HS re-connect SCO after call disconnect.
   do not accept such incoming connection SCO connection
   requests.
 - Check for valid SCO listener before accepting incoming
   SCO connection requests.

Change-Id: Iab5853382413467dfc7514587f50894fe11c9633
CRs-Fixed: 754738
parent ec1ee663
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -1218,6 +1218,12 @@ final class HeadsetStateMachine extends StateMachine {

            switch (state) {
                case HeadsetHalConstants.AUDIO_STATE_CONNECTED:
                    if (!isScoAcceptable()) {
                        Log.e(TAG,"Audio Connected without any listener");
                        disconnectAudioNative(getByteAddress(device));
                        break;
                    }

                    // TODO(BT) should I save the state for next broadcast as the prevState?
                    mAudioState = BluetoothHeadset.STATE_AUDIO_CONNECTED;
                    setAudioParameters(device); /*Set proper Audio Paramters.*/
@@ -2191,6 +2197,11 @@ final class HeadsetStateMachine extends StateMachine {

            switch (state) {
                case HeadsetHalConstants.AUDIO_STATE_CONNECTED:
                    if (!isScoAcceptable()) {
                        Log.e(TAG,"Audio Connected without any listener");
                        disconnectAudioNative(getByteAddress(device));
                        break;
                    }
                    mAudioState = BluetoothHeadset.STATE_AUDIO_CONNECTED;
                    setAudioParameters(device); /* Set proper Audio Parameters. */
                    mAudioManager.setBluetoothScoOn(true);
@@ -3657,6 +3668,14 @@ final class HeadsetStateMachine extends StateMachine {
                (mPhoneState.getCallState() != HeadsetHalConstants.CALL_STATE_IDLE));
    }

    // Accept incoming SCO only when there is active call, VR activated,
    // active VOIP call and Incoming call with inband ringtone supported
    private boolean isScoAcceptable() {
        return (((mPhoneState.getCallState() == HeadsetHalConstants.CALL_STATE_INCOMING) &&
                ((mLocalBrsf & BRSF_AG_IN_BAND_RING) != 0)) || mVoiceRecognitionStarted ||
                 isInCall());
    }

    boolean isConnected() {
        IState currentState = getCurrentState();
        return (currentState == mConnected || currentState == mAudioOn);