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

Commit d7e0723f authored by Mallikarjuna GB's avatar Mallikarjuna GB Committed by Android Git Automerger
Browse files

am 78097164: Do not accept SCO without any active listener.

* commit '78097164':
  Do not accept SCO without any active listener.
parents f9056321 78097164
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);