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

Commit 86d215ea authored by Thomas Stuart's avatar Thomas Stuart
Browse files

fix potential audio flicker w/ CS outgoing calls

During my development of the core-telecom library I noticed that
outgoing calls were flickering between ACTIVE earpiece and QUITE.  After
a deep dive, I noticed this was a result of the call state moving from
CallState.CONNECTING to CallState.NEW which would change the focus to
null and remove the call from audio focus.

To prevent the unwanted behavior, outgoing calls that reach
CallsManager#onSuccessfulOutgoinCall should only move to the DIALING
state and requested states should be ignored.

Fixes: 290847206
Test: 2 new unit tests + 1 manual test:
         1. comment out setDialing in core-tel test app
         2. start an outgoing call
         observe/expect: AUDIO_ROUTE never moves from active
                         to quite.

Change-Id: Iac72660f07649b3a41b9a83a9c8911127404e0aa
parent 735890be
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -758,11 +758,10 @@ public class CallsManager extends Call.ListenerBase
    @Override
    @VisibleForTesting
    public void onSuccessfulOutgoingCall(Call call, int callState) {
        Log.v(this, "onSuccessfulOutgoingCall, %s", call);
        Log.v(this, "onSuccessfulOutgoingCall, call=[%s], state=[%d]", call, callState);
        call.setPostCallPackageName(getRoleManagerAdapter().getDefaultCallScreeningApp(
                call.getAssociatedUser()));

        setCallState(call, callState, "successful outgoing call");
        if (!mCalls.contains(call)) {
            // Call was not added previously in startOutgoingCall due to it being a potential MMI
            // code, so add it now.
@@ -774,8 +773,14 @@ public class CallsManager extends Call.ListenerBase
            listener.onConnectionServiceChanged(call, null, call.getConnectionService());
        }

        // Allow the ConnectionService to start the call in the active state. This case is helpful
        // for conference calls or meetings that can skip the dialing stage.
        if (callState == CallState.ACTIVE) {
            setCallState(call, callState, "skipping the dialing state and setting active");
        } else {
            markCallAsDialing(call);
        }
    }

    @Override
    public void onFailedOutgoingCall(Call call, DisconnectCause disconnectCause) {
+24 −0
Original line number Diff line number Diff line
@@ -2508,6 +2508,30 @@ public class CallsManagerTest extends TelecomTestCase {
        assertEquals(DEFAULT_CALL_SCREENING_APP, outgoingCall.getPostCallPackageName());
    }

    /**
     * Verify the only call state set from calling onSuccessfulOutgoingCall is CallState.DIALING.
     */
    @SmallTest
    @Test
    public void testOutgoingCallStateIsSetToAPreviousStateAndIgnored() {
        Call outgoingCall = addSpyCall(CallState.CONNECTING);
        mCallsManager.onSuccessfulOutgoingCall(outgoingCall, CallState.NEW);
        verify(outgoingCall, never()).setState(eq(CallState.NEW), any());
        verify(outgoingCall, times(1)).setState(eq(CallState.DIALING), any());
    }

    /**
     * Verify a ConnectionService can start the call in the active state and avoid the dialing state
     */
    @SmallTest
    @Test
    public void testOutgoingCallStateCanAvoidDialingAndGoStraightToActive() {
        Call outgoingCall = addSpyCall(CallState.CONNECTING);
        mCallsManager.onSuccessfulOutgoingCall(outgoingCall, CallState.ACTIVE);
        verify(outgoingCall, never()).setState(eq(CallState.DIALING), any());
        verify(outgoingCall, times(1)).setState(eq(CallState.ACTIVE), any());
    }

    @SmallTest
    @Test
    public void testRejectIncomingCallOnPAHInactive_SecondaryUser() throws Exception {