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

Commit 2c67d4a8 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Add flag for call audio mode change.

Adding a flag for the new behavior which takes place when swapping between
a PSTN and VOIP call; this was a bug fix made to correct missing audio
mode transitions.

Bug: 289861657
Test: atest CallAudioManagerTest
Change-Id: I0feba38a3a529d139f251b995c0ddda40d89465b
parent 05c0c644
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -6,3 +6,10 @@ flag {
  description: "Fix supported routes wrongly include bluetooth issue."
  bug: "292599751"
}

flag {
  name: "ensure_audio_mode_updates_on_foreground_call_change"
  namespace: "telecom"
  description: "Ensure that the audio mode is updated anytime the foreground call changes."
  bug: "289861657"
}
 No newline at end of file
+26 −15
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.telecom.CallAudioModeStateMachine.MessageArgs.Builder;
import com.android.server.telecom.bluetooth.BluetoothStateReceiver;
import com.android.server.telecom.flags.FeatureFlags;

import java.util.Collection;
import java.util.HashSet;
@@ -62,6 +63,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
    private final Ringer mRinger;
    private final RingbackPlayer mRingbackPlayer;
    private final DtmfLocalTonePlayer mDtmfLocalTonePlayer;
    private final FeatureFlags mFeatureFlags;

    private Call mStreamingCall;
    private Call mForegroundCall;
@@ -76,7 +78,8 @@ public class CallAudioManager extends CallsManagerListenerBase {
            Ringer ringer,
            RingbackPlayer ringbackPlayer,
            BluetoothStateReceiver bluetoothStateReceiver,
            DtmfLocalTonePlayer dtmfLocalTonePlayer) {
            DtmfLocalTonePlayer dtmfLocalTonePlayer,
            FeatureFlags featureFlags) {
        mActiveDialingOrConnectingCalls = new LinkedHashSet<>(1);
        mRingingCalls = new LinkedHashSet<>(1);
        mHoldingCalls = new LinkedHashSet<>(1);
@@ -102,6 +105,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
        mRingbackPlayer = ringbackPlayer;
        mBluetoothStateReceiver = bluetoothStateReceiver;
        mDtmfLocalTonePlayer = dtmfLocalTonePlayer;
        mFeatureFlags = featureFlags;

        mPlayerFactory.setCallAudioManager(this);
        mCallAudioModeStateMachine.setCallAudioManager(this);
@@ -772,6 +776,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
                    possibleConnectingCall = call;
                }
            }
            if (mFeatureFlags.ensureAudioModeUpdatesOnForegroundCallChange()) {
                // Prefer a connecting call
                if (possibleConnectingCall != null) {
                    mForegroundCall = possibleConnectingCall;
@@ -787,6 +792,11 @@ public class CallAudioManager extends CallsManagerListenerBase {
                            // If we can't find one, then just fall back to the first one.
                            .orElse(mActiveDialingOrConnectingCalls.iterator().next());
                }
            } else {
                // Legacy (buggy) behavior.
                mForegroundCall = possibleConnectingCall == null ?
                        mActiveDialingOrConnectingCalls.iterator().next() : possibleConnectingCall;
            }
        } else if (mRingingCalls.size() > 0) {
            mForegroundCall = mRingingCalls.iterator().next();
        } else if (mHoldingCalls.size() > 0) {
@@ -806,7 +816,8 @@ public class CallAudioManager extends CallsManagerListenerBase {
            mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                    CallAudioRouteStateMachine.UPDATE_SYSTEM_AUDIO_ROUTE);

            if (mForegroundCall != null) {
            if (mForegroundCall != null
                    && mFeatureFlags.ensureAudioModeUpdatesOnForegroundCallChange()) {
                // Ensure the voip audio mode for the new foreground call is taken into account.
                mCallAudioModeStateMachine.sendMessageWithArgs(
                        CallAudioModeStateMachine.FOREGROUND_VOIP_MODE_CHANGE,
+1 −1
Original line number Diff line number Diff line
@@ -657,7 +657,7 @@ public class CallsManager extends Call.ListenerBase
                this, callAudioModeStateMachineFactory.create(systemStateHelper,
                (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE), featureFlags),
                playerFactory, mRinger, new RingbackPlayer(playerFactory),
                bluetoothStateReceiver, mDtmfLocalTonePlayer);
                bluetoothStateReceiver, mDtmfLocalTonePlayer, featureFlags);

        mConnectionSvrFocusMgr = connectionServiceFocusManagerFactory.create(mRequester);
        mHeadsetMediaButton = headsetMediaButtonFactory.create(context, this, mLock);
+45 −11
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.server.telecom.RingbackPlayer;
import com.android.server.telecom.Ringer;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.bluetooth.BluetoothStateReceiver;
import com.android.server.telecom.flags.FeatureFlags;

import org.junit.After;
import org.junit.Before;
@@ -79,6 +80,8 @@ public class CallAudioManagerTest extends TelecomTestCase {
    @Mock private BluetoothStateReceiver mBluetoothStateReceiver;
    @Mock private TelecomSystem.SyncRoot mLock;

    @Mock private FeatureFlags mFlags;

    private CallAudioManager mCallAudioManager;

    @Override
@@ -94,6 +97,7 @@ public class CallAudioManagerTest extends TelecomTestCase {
            return mockInCallTonePlayer;
        }).when(mPlayerFactory).createPlayer(anyInt());
        when(mCallsManager.getLock()).thenReturn(mLock);
        when(mFlags.ensureAudioModeUpdatesOnForegroundCallChange()).thenReturn(true);
        mCallAudioManager = new CallAudioManager(
                mCallAudioRouteStateMachine,
                mCallsManager,
@@ -102,7 +106,8 @@ public class CallAudioManagerTest extends TelecomTestCase {
                mRinger,
                mRingbackPlayer,
                mBluetoothStateReceiver,
                mDtmfLocalTonePlayer);
                mDtmfLocalTonePlayer,
                mFlags);
    }

    @Override
@@ -278,19 +283,27 @@ public class CallAudioManagerTest extends TelecomTestCase {
        verify(mCallAudioModeStateMachine, times(2)).sendMessageWithArgs(
                eq(CallAudioModeStateMachine.NEW_ACTIVE_OR_DIALING_CALL), captor.capture());
        assertMessageArgEquality(expectedArgs, captor.getValue());
        // Expet another invocation due to audio mode change signal.
        if (mFlags.ensureAudioModeUpdatesOnForegroundCallChange()) {
            // Expect another invocation due to audio mode change signal.
            verify(mCallAudioModeStateMachine, times(3)).sendMessageWithArgs(
                    anyInt(), any(CallAudioModeStateMachine.MessageArgs.class));

        } else {
            verify(mCallAudioModeStateMachine, times(2)).sendMessageWithArgs(
                    anyInt(), any(CallAudioModeStateMachine.MessageArgs.class));
        }

        when(call.getState()).thenReturn(CallState.ACTIVE);
        mCallAudioManager.onCallStateChanged(call, CallState.DIALING, CallState.ACTIVE);
        verify(mCallAudioModeStateMachine, times(3)).sendMessageWithArgs(
                eq(CallAudioModeStateMachine.NEW_ACTIVE_OR_DIALING_CALL), captor.capture());
        assertMessageArgEquality(expectedArgs, captor.getValue());
        if (mFlags.ensureAudioModeUpdatesOnForegroundCallChange()) {
            verify(mCallAudioModeStateMachine, times(4)).sendMessageWithArgs(
                    anyInt(), any(CallAudioModeStateMachine.MessageArgs.class));

        } else {
            verify(mCallAudioModeStateMachine, times(3)).sendMessageWithArgs(
                    anyInt(), any(CallAudioModeStateMachine.MessageArgs.class));
        }
        disconnectCall(call);
        stopTone();

@@ -298,6 +311,12 @@ public class CallAudioManagerTest extends TelecomTestCase {
        verifyProperCleanup();
    }

    @Test
    public void testSingleOutgoingCallWithoutAudioModeUpdateOnForegroundCallChange() {
        when(mFlags.ensureAudioModeUpdatesOnForegroundCallChange()).thenReturn(false);
        testSingleOutgoingCall();
    }

    @MediumTest
    @Test
    public void testRingbackStartStop() {
@@ -329,9 +348,14 @@ public class CallAudioManagerTest extends TelecomTestCase {
        verify(mCallAudioModeStateMachine, times(2)).sendMessageWithArgs(
                eq(CallAudioModeStateMachine.NEW_ACTIVE_OR_DIALING_CALL), captor.capture());
        assertMessageArgEquality(expectedArgs, captor.getValue());
        if (mFlags.ensureAudioModeUpdatesOnForegroundCallChange()) {
            // Expect an extra time due to audio mode change signal
            verify(mCallAudioModeStateMachine, times(3)).sendMessageWithArgs(
                    anyInt(), any(CallAudioModeStateMachine.MessageArgs.class));
        } else {
            verify(mCallAudioModeStateMachine, times(2)).sendMessageWithArgs(
                    anyInt(), any(CallAudioModeStateMachine.MessageArgs.class));
        }

        // Ensure we started ringback.
        verify(mRingbackPlayer).startRingbackForCall(any(Call.class));
@@ -353,6 +377,12 @@ public class CallAudioManagerTest extends TelecomTestCase {
        verify(mRingbackPlayer, times(1)).startRingbackForCall(any(Call.class));
    }

    @Test
    public void testRingbackStartStopWithoutAudioModeUpdateOnForegroundCallChange() {
        when(mFlags.ensureAudioModeUpdatesOnForegroundCallChange()).thenReturn(false);
        testRingbackStartStop();
    }

    @SmallTest
    @Test
    public void testNewCallGoesToAudioProcessing() {
@@ -708,6 +738,10 @@ public class CallAudioManagerTest extends TelecomTestCase {
    @SmallTest
    @Test
    public void testTriggerAudioManagerModeChange() {
        if (!mFlags.ensureAudioModeUpdatesOnForegroundCallChange()) {
            // Skip if the new behavior isn't in use.
            return;
        }
        // Start with an incoming PSTN call
        Call pstnCall = mock(Call.class);
        when(pstnCall.getState()).thenReturn(CallState.RINGING);