Reset audio route when self-managed calls are disconnected.
When self-managed calls are disconnected to make way for a new managed
call, ensure we switch back to the baseline audio route. Although audio
routing is considered across all connection services, it is counter
intuitive to the user to be in a speakerphone call (for example) in a
self-managed app and then to have a newly place managed call which
replaces it also route over speakerphone. We solve this by ensuring that
the audio route switches back to baseline whenever we disconnect all
self-managed calls in order to place a new managed call. This is
especially important when the user places an emergency call that causes
self-managed calls to disconnect.
Test: Manual test with ril.ecclist; added new unit test to cover this case.
Bug: 70640139
Change-Id: I28100410fe674fe75dc7ddd6d92e968e5970aef4
diff --git a/src/com/android/server/telecom/CallAudioManager.java b/src/com/android/server/telecom/CallAudioManager.java
index 3e50bd5..bf1ef8f 100644
--- a/src/com/android/server/telecom/CallAudioManager.java
+++ b/src/com/android/server/telecom/CallAudioManager.java
@@ -418,6 +418,17 @@
}
}
+ /**
+ * Switch call audio routing to the baseline route, including bluetooth headsets if there are
+ * any connected.
+ */
+ void switchBaseline() {
+ Log.i(this, "switchBaseline");
+ mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
+ CallAudioRouteStateMachine.USER_SWITCH_BASELINE_ROUTE,
+ CallAudioRouteStateMachine.INCLUDE_BLUETOOTH_IN_BASELINE);
+ }
+
void silenceRingers() {
for (Call call : mRingingCalls) {
call.silence();
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index f2151f1..f9cad9f 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -3092,6 +3092,12 @@
mCalls.stream()
.filter(c -> c.isSelfManaged())
.forEach(c -> c.disconnect());
+
+ // When disconnecting all self-managed calls, switch audio routing back to the baseline
+ // route. This ensures if, for example, the self-managed ConnectionService was routed to
+ // speakerphone that we'll switch back to earpiece for the managed call which necessitated
+ // disconnecting the self-managed calls.
+ mCallAudioManager.switchBaseline();
}
/**
diff --git a/tests/src/com/android/server/telecom/tests/BasicCallTests.java b/tests/src/com/android/server/telecom/tests/BasicCallTests.java
index f391ee6..41a775f 100644
--- a/tests/src/com/android/server/telecom/tests/BasicCallTests.java
+++ b/tests/src/com/android/server/telecom/tests/BasicCallTests.java
@@ -955,4 +955,30 @@
assertFalse(mTelecomSystem.getTelecomServiceImpl().getBinder()
.isOutgoingCallPermitted(mPhoneAccountSelfManaged.getAccountHandle()));
}
+
+ /**
+ * Basic to verify audio route gets reset to baseline when emergency call placed while a
+ * self-managed call is underway.
+ * @throws Exception
+ */
+ @LargeTest
+ public void testDisconnectSelfManaged() throws Exception {
+ // Add a self-managed call.
+ PhoneAccountHandle phoneAccountHandle = mPhoneAccountSelfManaged.getAccountHandle();
+ startAndMakeActiveIncomingCall("650-555-1212", phoneAccountHandle,
+ mConnectionServiceFixtureA);
+ Connection connection = mConnectionServiceFixtureA.mLatestConnection;
+
+ // Route self-managed call to speaker.
+ connection.setAudioRoute(CallAudioState.ROUTE_SPEAKER);
+ waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT);
+
+ // Place an emergency call.
+ startAndMakeDialingEmergencyCall("650-555-1212", mPhoneAccountE0.getAccountHandle(),
+ mConnectionServiceFixtureA);
+
+ // Should have reverted back to earpiece.
+ assertEquals(CallAudioState.ROUTE_EARPIECE,
+ mInCallServiceFixtureX.mCallAudioState.getRoute());
+ }
}