Add CTS test to verify setIsVoipAudioMode functions

Verify that in addition to setting the mAudioModeIsVoip member of
Connection, Connection#setIsVoipAudioMode also propagates through to
Telecom and sets the AudioManager mode correctly.

Bug: 36097087
Bug: 36097043
Test: this is cts
Change-Id: I303d008e54e0b8c23f534de3f39a7752fd85d194
diff --git a/tests/tests/telecom/src/android/telecom/cts/ConnectionServiceTest.java b/tests/tests/telecom/src/android/telecom/cts/ConnectionServiceTest.java
index 1895b0f..0b70f1b 100644
--- a/tests/tests/telecom/src/android/telecom/cts/ConnectionServiceTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/ConnectionServiceTest.java
@@ -19,6 +19,8 @@
 import static android.telecom.cts.TestUtils.*;
 
 import android.content.ComponentName;
+import android.content.Context;
+import android.media.AudioManager;
 import android.telecom.Call;
 import android.telecom.Connection;
 import android.telecom.ConnectionService;
@@ -27,7 +29,8 @@
 import java.util.Collection;
 
 /**
- * Test some additional {@link ConnectionService} APIs not already covered by other tests.
+ * Test some additional {@link ConnectionService} and {@link Connection} APIs not already covered
+ * by other tests.
  */
 public class ConnectionServiceTest extends BaseTelecomTestWithMockServices {
 
@@ -104,6 +107,23 @@
         assertCallState(call, Call.STATE_DIALING);
     }
 
+    public void testVoipAudioModePropagation() throws Exception {
+        if (!mShouldTestTelecom) {
+            return;
+        }
+
+        placeAndVerifyCall();
+        MockConnection connection = verifyConnectionForOutgoingCall();
+        connection.setAudioModeIsVoip(true);
+        waitOnAllHandlers(getInstrumentation());
+
+        AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
+        assertEquals(AudioManager.MODE_IN_COMMUNICATION, audioManager.getMode());
+        connection.setAudioModeIsVoip(false);
+        waitOnAllHandlers(getInstrumentation());
+        assertEquals(AudioManager.MODE_IN_CALL, audioManager.getMode());
+    }
+
     public void testGetAllConnections() {
         if (!mShouldTestTelecom) {
             return;