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

Commit f82b5bef authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Resolve call audio refactor test failures

There were test breakages found in trunk staging in BT and Telecom CTS
tests which are being resolved as part of this CL. Ensure that we don't
try to set the communication device for a null device and update the
system audio state when we receive UPDATE_SYSTEM_AUDIO_ROUTE in the
controller.

This CL also resolves an issue with audio routing to the base route when
playing the end tone (which may override a user's previously requested
route). For instance, when a wired headset is plugged in and the user
switches to speaker, we receive ACTIVE_FOCUS when playing the end tone
which causes audio to route back to wired headset. Audio incorrectly
plays on wired headset in this instance so we can opt to ignore falling
back on the base route for end tones to resolve this.

Bug: 349394420
Bug: 349060651
Flag: com.android.server.telecom.flags.use_refactored_audio_route_switching
Test: atest CtsTelecomTestCases, atest BluetoothInstrumentationTests
Change-Id: If9c977d9c32f4ae1436007b7132cc3d9d52be605
parent 413076ef
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -576,9 +576,26 @@ public class CallAudioManager extends CallsManagerListenerBase {

    @VisibleForTesting
    public void setCallAudioRouteFocusState(int focusState) {
        if (mFeatureFlags.useRefactoredAudioRouteSwitching()) {
            mCallAudioRouteAdapter.sendMessageWithSessionInfo(
                    CallAudioRouteStateMachine.SWITCH_FOCUS, focusState, 0);
        } else {
            mCallAudioRouteAdapter.sendMessageWithSessionInfo(
                    CallAudioRouteStateMachine.SWITCH_FOCUS, focusState);
        }
    }

    public void setCallAudioRouteFocusStateForEndTone() {
        if (mFeatureFlags.useRefactoredAudioRouteSwitching()) {
            mCallAudioRouteAdapter.sendMessageWithSessionInfo(
                    CallAudioRouteStateMachine.SWITCH_FOCUS,
                    CallAudioRouteStateMachine.ACTIVE_FOCUS, 1);
        } else {
            mCallAudioRouteAdapter.sendMessageWithSessionInfo(
                    CallAudioRouteStateMachine.SWITCH_FOCUS,
                    CallAudioRouteStateMachine.ACTIVE_FOCUS);
        }
    }

    public void notifyAudioOperationsComplete() {
        mCallAudioModeStateMachine.sendMessageWithArgs(
+1 −1
Original line number Diff line number Diff line
@@ -824,7 +824,7 @@ public class CallAudioModeStateMachine extends StateMachine {
            }
            mAudioManager.setMode(mMostRecentMode);
            mLocalLog.log("Mode " + mMostRecentMode);
            mCallAudioManager.setCallAudioRouteFocusState(CallAudioRouteStateMachine.ACTIVE_FOCUS);
            mCallAudioManager.setCallAudioRouteFocusStateForEndTone();
        }

        @Override
+1 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ public interface CallAudioRouteAdapter {
    void sendMessageWithSessionInfo(int message);
    void sendMessageWithSessionInfo(int message, int arg);
    void sendMessageWithSessionInfo(int message, int arg, String data);
    void sendMessageWithSessionInfo(int message, int arg, int data);
    void sendMessageWithSessionInfo(int message, int arg, BluetoothDevice bluetoothDevice);
    void sendMessage(int message, Runnable r);
    void setCallAudioManager(CallAudioManager callAudioManager);
+24 −4
Original line number Diff line number Diff line
@@ -213,6 +213,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
                    String address;
                    BluetoothDevice bluetoothDevice;
                    int focus;
                    int handleEndTone;
                    @AudioRoute.AudioRouteType int type;
                    switch (msg.what) {
                        case CONNECT_WIRED_HEADSET:
@@ -305,11 +306,18 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
                            break;
                        case SWITCH_FOCUS:
                            focus = msg.arg1;
                            handleSwitchFocus(focus);
                            handleEndTone = (int) ((SomeArgs) msg.obj).arg2;
                            handleSwitchFocus(focus, handleEndTone);
                            break;
                        case EXIT_PENDING_ROUTE:
                            handleExitPendingRoute();
                            break;
                        case UPDATE_SYSTEM_AUDIO_ROUTE:
                            updateCallAudioState(new CallAudioState(mIsMute,
                                    mCallAudioState.getRoute(),
                                    mCallAudioState.getSupportedRouteMask(),
                                    mCallAudioState.getActiveBluetoothDevice(),
                                    mCallAudioState.getSupportedBluetoothDevices()));
                        default:
                            break;
                    }
@@ -397,6 +405,14 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
        sendMessage(message, arg, 0, args);
    }

    @Override
    public void sendMessageWithSessionInfo(int message, int arg, int data) {
        SomeArgs args = SomeArgs.obtain();
        args.arg1 = Log.createSubsession();
        args.arg2 = data;
        sendMessage(message, arg, 0, args);
    }

    @Override
    public void sendMessageWithSessionInfo(int message, int arg, BluetoothDevice bluetoothDevice) {
        SomeArgs args = SomeArgs.obtain();
@@ -766,7 +782,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
        onMuteStateChanged(mIsMute);
    }

    private void handleSwitchFocus(int focus) {
    private void handleSwitchFocus(int focus, int handleEndTone) {
        Log.i(this, "handleSwitchFocus: focus (%s)", focus);
        mFocusType = focus;
        switch (focus) {
@@ -782,9 +798,13 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
            }
            case ACTIVE_FOCUS -> {
                // Route to active baseline route (we may need to change audio route in the case
                // when a video call is put on hold).
                // when a video call is put on hold). Ignore route changes if we're handling playing
                // the end tone. Otherwise, it's possible that we'll override the route a client has
                // previously requested.
                if (handleEndTone == 0) {
                    routeTo(true, getBaseRoute(true, null));
                }
            }
            case RINGING_FOCUS -> {
                if (!mIsActive) {
                    AudioRoute route = getBaseRoute(true, null);
+4 −0
Original line number Diff line number Diff line
@@ -1685,6 +1685,10 @@ public class CallAudioRouteStateMachine extends StateMachine implements CallAudi
        sendMessage(message, arg, 0, args);
    }

    public void sendMessageWithSessionInfo(int message, int arg, int data) {
        // ignore, only used in CallAudioRouteController
    }

    public void sendMessageWithSessionInfo(int message, int arg, BluetoothDevice bluetoothDevice) {
        // ignore, only used in CallAudioRouteController
    }
Loading