Loading flags/telecom_callaudioroutestatemachine_flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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 src/com/android/server/telecom/CallAudioManager.java +26 −15 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); Loading @@ -102,6 +105,7 @@ public class CallAudioManager extends CallsManagerListenerBase { mRingbackPlayer = ringbackPlayer; mBluetoothStateReceiver = bluetoothStateReceiver; mDtmfLocalTonePlayer = dtmfLocalTonePlayer; mFeatureFlags = featureFlags; mPlayerFactory.setCallAudioManager(this); mCallAudioModeStateMachine.setCallAudioManager(this); Loading Loading @@ -772,6 +776,7 @@ public class CallAudioManager extends CallsManagerListenerBase { possibleConnectingCall = call; } } if (mFeatureFlags.ensureAudioModeUpdatesOnForegroundCallChange()) { // Prefer a connecting call if (possibleConnectingCall != null) { mForegroundCall = possibleConnectingCall; Loading @@ -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) { Loading @@ -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, Loading src/com/android/server/telecom/CallsManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); Loading tests/src/com/android/server/telecom/tests/CallAudioManagerTest.java +45 −11 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading @@ -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, Loading @@ -102,7 +106,8 @@ public class CallAudioManagerTest extends TelecomTestCase { mRinger, mRingbackPlayer, mBluetoothStateReceiver, mDtmfLocalTonePlayer); mDtmfLocalTonePlayer, mFlags); } @Override Loading Loading @@ -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(); Loading @@ -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() { Loading Loading @@ -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)); Loading @@ -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() { Loading Loading @@ -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); Loading Loading
flags/telecom_callaudioroutestatemachine_flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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
src/com/android/server/telecom/CallAudioManager.java +26 −15 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); Loading @@ -102,6 +105,7 @@ public class CallAudioManager extends CallsManagerListenerBase { mRingbackPlayer = ringbackPlayer; mBluetoothStateReceiver = bluetoothStateReceiver; mDtmfLocalTonePlayer = dtmfLocalTonePlayer; mFeatureFlags = featureFlags; mPlayerFactory.setCallAudioManager(this); mCallAudioModeStateMachine.setCallAudioManager(this); Loading Loading @@ -772,6 +776,7 @@ public class CallAudioManager extends CallsManagerListenerBase { possibleConnectingCall = call; } } if (mFeatureFlags.ensureAudioModeUpdatesOnForegroundCallChange()) { // Prefer a connecting call if (possibleConnectingCall != null) { mForegroundCall = possibleConnectingCall; Loading @@ -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) { Loading @@ -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, Loading
src/com/android/server/telecom/CallsManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); Loading
tests/src/com/android/server/telecom/tests/CallAudioManagerTest.java +45 −11 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading @@ -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, Loading @@ -102,7 +106,8 @@ public class CallAudioManagerTest extends TelecomTestCase { mRinger, mRingbackPlayer, mBluetoothStateReceiver, mDtmfLocalTonePlayer); mDtmfLocalTonePlayer, mFlags); } @Override Loading Loading @@ -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(); Loading @@ -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() { Loading Loading @@ -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)); Loading @@ -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() { Loading Loading @@ -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); Loading