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

Commit 746e7ffd authored by Hall Liu's avatar Hall Liu
Browse files

Stop checking whether the speakerphone is on

Recent changes in the audio framework have separated out speakerphone
requests by calling package. Therefore, if some other app turns
bluetooth on and we get notified about it after isSpeakerphoneOn starts
returning false, we may not clear our request for speakerphone,
thereby causing the device to return to speakerphone mode the next time
BT is turned off.

Fix this by no longer checking isSpeakerphoneOn. However, in order to
prevent us from lodging our own request when an external app turns
speakerphone on, start turning on speakerphone upon user request rather
than in the entry method of the speakerphone state.

Fixes: 162289995
Test: atest CallAudioRouteTransitionTests, manual

Change-Id: I4c52307a4937b61eebe18cf2dc1a881bfd834b34
parent efc7dead
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -413,6 +413,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    return HANDLED;
                case SWITCH_SPEAKER:
                case USER_SWITCH_SPEAKER:
                    setSpeakerphoneOn(true);
                    // fall through
                case SPEAKER_ON:
                    transitionTo(mActiveSpeakerRoute);
                    return HANDLED;
@@ -534,6 +536,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    // This may be sent as a confirmation by the BT stack after switch off BT.
                    return HANDLED;
                case CONNECT_DOCK:
                    setSpeakerphoneOn(true);
                    sendInternalMessage(SWITCH_SPEAKER);
                    return HANDLED;
                case DISCONNECT_DOCK:
@@ -612,6 +615,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    return HANDLED;
                case SWITCH_SPEAKER:
                case USER_SWITCH_SPEAKER:
                    setSpeakerphoneOn(true);
                    // fall through
                case SPEAKER_ON:
                    transitionTo(mActiveSpeakerRoute);
                    return HANDLED;
@@ -727,6 +732,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    return HANDLED;
                case DISCONNECT_WIRED_HEADSET:
                    if (mWasOnSpeaker) {
                        setSpeakerphoneOn(true);
                        sendInternalMessage(SWITCH_SPEAKER);
                    } else {
                        sendInternalMessage(SWITCH_BASELINE_ROUTE, INCLUDE_BLUETOOTH_IN_BASELINE);
@@ -798,6 +804,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    transitionTo(mActiveHeadsetRoute);
                    break;
                case SWITCH_SPEAKER:
                    setSpeakerphoneOn(true);
                    transitionTo(mActiveSpeakerRoute);
                    break;
                default:
@@ -854,6 +861,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    mHasUserExplicitlyLeftBluetooth = true;
                    // fall through
                case SWITCH_SPEAKER:
                    setSpeakerphoneOn(true);
                    // fall through
                case SPEAKER_ON:
                    setBluetoothOff();
                    transitionTo(mActiveSpeakerRoute);
@@ -949,6 +958,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    mHasUserExplicitlyLeftBluetooth = true;
                    // fall through
                case SWITCH_SPEAKER:
                    setSpeakerphoneOn(true);
                    // fall through
                case SPEAKER_ON:
                    transitionTo(mActiveSpeakerRoute);
                    return HANDLED;
@@ -1108,8 +1119,9 @@ public class CallAudioRouteStateMachine extends StateMachine {
        @Override
        public void enter() {
            super.enter();
            // Don't set speakerphone on here -- we might end up in this state by following
            // the speaker state that some other app commanded.
            mWasOnSpeaker = true;
            setSpeakerphoneOn(true);
            CallAudioState newState = new CallAudioState(mIsMuted, ROUTE_SPEAKER,
                    mAvailableRoutes, null, mBluetoothRouteManager.getConnectedDevices());
            setSystemAudioState(newState, true);
@@ -1596,12 +1608,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
    }

    private void setSpeakerphoneOn(boolean on) {
        if (mAudioManager.isSpeakerphoneOn() != on) {
        Log.i(this, "turning speaker phone %s", on);
        mAudioManager.setSpeakerphoneOn(on);
        } else {
            Log.i(this, "Ignoring speakerphone request -- already %s", on);
        }
        mStatusBarNotifier.notifySpeakerphone(on);
    }

+1 −1
Original line number Diff line number Diff line
@@ -815,7 +815,7 @@ public class CallAudioRouteTransitionTests extends TelecomTestCase {
                "Speakerphone turned off externally during speaker", // name
                CallAudioState.ROUTE_SPEAKER, // initialRoute
                CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_BLUETOOTH, // availableRoutes
                NONE, // speakerInteraction
                OFF, // speakerInteraction
                ON, // bluetoothInteraction
                CallAudioRouteStateMachine.SPEAKER_OFF, // action
                CallAudioState.ROUTE_BLUETOOTH, // expectedRoute