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

Commit 78097164 authored by Mallikarjuna GB's avatar Mallikarjuna GB Committed by Andre Eisenbach
Browse files

Do not accept SCO without any active listener.

Use case:
1. Connect to Motorola s305 headset.
2. start playing music on Phone.
3. Make an MO call for last dialled number from headset.
4. Accept and end the call from remote phone.

Failure:
After call ends, music resumes on headset for 1-2secs and
routed to speaker.

Root cause:
Headset is re-connecting SCO after call disconnection.

Fix:
 - Some HS re-connect SCO after call disconnection.
   Do not accept such incoming SCO connection requests.
 - Check for valid SCO listener(active CS or VOIP call, VR started)
   before accepting incoming SCO connection requests.

Change-Id: Ifcb1f760b3eabf52d9b507c5d25021b90bfec561
parent 10c1bd2a
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -1082,6 +1082,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.*/
@@ -1947,6 +1953,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);
@@ -3207,6 +3218,12 @@ 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
    private boolean isScoAcceptable() {
        return (mVoiceRecognitionStarted || isInCall());
    }

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