Loading tests/src/com/android/server/telecom/tests/CallAudioRouteControllerTest.java +27 −13 Original line number Diff line number Diff line Loading @@ -104,20 +104,16 @@ import org.mockito.Mock; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @RunWith(JUnit4.class) public class CallAudioRouteControllerTest extends TelecomTestCase { private static final String BT_ADDRESS_1 = "00:00:00:00:00:01"; private static final BluetoothDevice BLUETOOTH_DEVICE_1 = BluetoothRouteManagerTest.makeBluetoothDevice("00:00:00:00:00:01"); private static final Set<BluetoothDevice> BLUETOOTH_DEVICES; private static final Set<BluetoothDevice> BLUETOOTH_DEVICES = new HashSet<>(); private static final int TEST_TIMEOUT = 500; static { BLUETOOTH_DEVICES = new HashSet<>(); BLUETOOTH_DEVICES.add(BLUETOOTH_DEVICE_1); } @Mock WiredHeadsetManager mWiredHeadsetManager; @Mock Loading Loading @@ -217,12 +213,14 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { when(mFeatureFlags.resolveActiveBtRoutingAndBtTimingIssue()).thenReturn(false); when(mFeatureFlags.newAudioPathSpeakerBroadcastAndUnfocusedRouting()).thenReturn(false); when(mFeatureFlags.fixUserRequestBaselineRouteVideoCall()).thenReturn(false); BLUETOOTH_DEVICES.add(BLUETOOTH_DEVICE_1); } @After public void tearDown() throws Exception { mController.getAdapterHandler().getLooper().quit(); mController.getAdapterHandler().getLooper().getThread().join(); BLUETOOTH_DEVICES.clear(); super.tearDown(); } Loading Loading @@ -428,7 +426,7 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { mController.sendMessageWithSessionInfo(SWITCH_FOCUS, RINGING_FOCUS, 0); verify(mBluetoothDeviceManager, timeout(TEST_TIMEOUT)) .connectAudio(BLUETOOTH_DEVICE_1, AudioRoute.TYPE_BLUETOOTH_SCO, false); assertTrue(mController.isActive()); waitForRouteActiveStateAndVerify(true); mController.sendMessageWithSessionInfo(SWITCH_FOCUS, ACTIVE_FOCUS, 0); assertTrue(mController.isActive()); Loading @@ -440,7 +438,7 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { // Ensure the BT device is disconnected. verify(mBluetoothDeviceManager, timeout(TEST_TIMEOUT).atLeastOnce()).disconnectSco(); assertFalse(mController.isActive()); waitForRouteActiveStateAndVerify(false); } @SmallTest Loading Loading @@ -1127,11 +1125,11 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { // Now switch call to active focus so that base route can be recalculated. mController.sendMessageWithSessionInfo(SWITCH_FOCUS, ACTIVE_FOCUS, 0); expectedState = new CallAudioState(false, CallAudioState.ROUTE_BLUETOOTH, CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_BLUETOOTH | CallAudioState.ROUTE_SPEAKER, BLUETOOTH_DEVICE_1, BLUETOOTH_DEVICES); // Verify that audio is still routed into BLUETOOTH_DEVICE_1 and not the 2nd BT device. verify(mCallsManager, timeout(TEST_TIMEOUT)).onCallAudioStateChanged( // Verify that audio is still routed into BLUETOOTH_DEVICE_1 and not the 2nd BT device. Add // atLeastOnce verification because the expected route would've been hit when we first // initially added the scoDevice and is getting captured here along with the invocation // from switching to active focus. verify(mCallsManager, timeout(TEST_TIMEOUT).atLeastOnce()).onCallAudioStateChanged( any(CallAudioState.class), eq(expectedState)); // Clean up BLUETOOTH_DEVICES for subsequent tests. Loading Loading @@ -1384,4 +1382,20 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { verify(mCallsManager, timeout(TEST_TIMEOUT)).onCallAudioStateChanged( any(CallAudioState.class), eq(expectedState)); } private void waitForRouteActiveStateAndVerify(boolean expectActive) { try { if (expectActive) { mController.getAudioActiveCompleteLatch().await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); } else { mController.getAudioOperationsCompleteLatch().await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); } } catch (Exception e) { // Catch timeout exception and allow failure below. } finally { assertEquals(mController.isActive(), expectActive); } } } tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -694,7 +694,10 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase { 0, bluetoothDevice2.getAddress()); waitForHandlerAction(stateMachine.getAdapterHandler(), TEST_TIMEOUT); verify(mockBluetoothRouteManager).connectBluetoothAudio(bluetoothDevice2.getAddress()); // It's possible that this is called again when we actually move into the active BT route // and we end up verifying this after that has happened. verify(mockBluetoothRouteManager, atLeastOnce()).connectBluetoothAudio( bluetoothDevice2.getAddress()); waitForHandlerAction(stateMachine.getAdapterHandler(), TEST_TIMEOUT); CallAudioState expectedEndState = new CallAudioState(false, CallAudioState.ROUTE_BLUETOOTH, Loading Loading
tests/src/com/android/server/telecom/tests/CallAudioRouteControllerTest.java +27 −13 Original line number Diff line number Diff line Loading @@ -104,20 +104,16 @@ import org.mockito.Mock; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @RunWith(JUnit4.class) public class CallAudioRouteControllerTest extends TelecomTestCase { private static final String BT_ADDRESS_1 = "00:00:00:00:00:01"; private static final BluetoothDevice BLUETOOTH_DEVICE_1 = BluetoothRouteManagerTest.makeBluetoothDevice("00:00:00:00:00:01"); private static final Set<BluetoothDevice> BLUETOOTH_DEVICES; private static final Set<BluetoothDevice> BLUETOOTH_DEVICES = new HashSet<>(); private static final int TEST_TIMEOUT = 500; static { BLUETOOTH_DEVICES = new HashSet<>(); BLUETOOTH_DEVICES.add(BLUETOOTH_DEVICE_1); } @Mock WiredHeadsetManager mWiredHeadsetManager; @Mock Loading Loading @@ -217,12 +213,14 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { when(mFeatureFlags.resolveActiveBtRoutingAndBtTimingIssue()).thenReturn(false); when(mFeatureFlags.newAudioPathSpeakerBroadcastAndUnfocusedRouting()).thenReturn(false); when(mFeatureFlags.fixUserRequestBaselineRouteVideoCall()).thenReturn(false); BLUETOOTH_DEVICES.add(BLUETOOTH_DEVICE_1); } @After public void tearDown() throws Exception { mController.getAdapterHandler().getLooper().quit(); mController.getAdapterHandler().getLooper().getThread().join(); BLUETOOTH_DEVICES.clear(); super.tearDown(); } Loading Loading @@ -428,7 +426,7 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { mController.sendMessageWithSessionInfo(SWITCH_FOCUS, RINGING_FOCUS, 0); verify(mBluetoothDeviceManager, timeout(TEST_TIMEOUT)) .connectAudio(BLUETOOTH_DEVICE_1, AudioRoute.TYPE_BLUETOOTH_SCO, false); assertTrue(mController.isActive()); waitForRouteActiveStateAndVerify(true); mController.sendMessageWithSessionInfo(SWITCH_FOCUS, ACTIVE_FOCUS, 0); assertTrue(mController.isActive()); Loading @@ -440,7 +438,7 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { // Ensure the BT device is disconnected. verify(mBluetoothDeviceManager, timeout(TEST_TIMEOUT).atLeastOnce()).disconnectSco(); assertFalse(mController.isActive()); waitForRouteActiveStateAndVerify(false); } @SmallTest Loading Loading @@ -1127,11 +1125,11 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { // Now switch call to active focus so that base route can be recalculated. mController.sendMessageWithSessionInfo(SWITCH_FOCUS, ACTIVE_FOCUS, 0); expectedState = new CallAudioState(false, CallAudioState.ROUTE_BLUETOOTH, CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_BLUETOOTH | CallAudioState.ROUTE_SPEAKER, BLUETOOTH_DEVICE_1, BLUETOOTH_DEVICES); // Verify that audio is still routed into BLUETOOTH_DEVICE_1 and not the 2nd BT device. verify(mCallsManager, timeout(TEST_TIMEOUT)).onCallAudioStateChanged( // Verify that audio is still routed into BLUETOOTH_DEVICE_1 and not the 2nd BT device. Add // atLeastOnce verification because the expected route would've been hit when we first // initially added the scoDevice and is getting captured here along with the invocation // from switching to active focus. verify(mCallsManager, timeout(TEST_TIMEOUT).atLeastOnce()).onCallAudioStateChanged( any(CallAudioState.class), eq(expectedState)); // Clean up BLUETOOTH_DEVICES for subsequent tests. Loading Loading @@ -1384,4 +1382,20 @@ public class CallAudioRouteControllerTest extends TelecomTestCase { verify(mCallsManager, timeout(TEST_TIMEOUT)).onCallAudioStateChanged( any(CallAudioState.class), eq(expectedState)); } private void waitForRouteActiveStateAndVerify(boolean expectActive) { try { if (expectActive) { mController.getAudioActiveCompleteLatch().await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); } else { mController.getAudioOperationsCompleteLatch().await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); } } catch (Exception e) { // Catch timeout exception and allow failure below. } finally { assertEquals(mController.isActive(), expectActive); } } }
tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -694,7 +694,10 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase { 0, bluetoothDevice2.getAddress()); waitForHandlerAction(stateMachine.getAdapterHandler(), TEST_TIMEOUT); verify(mockBluetoothRouteManager).connectBluetoothAudio(bluetoothDevice2.getAddress()); // It's possible that this is called again when we actually move into the active BT route // and we end up verifying this after that has happened. verify(mockBluetoothRouteManager, atLeastOnce()).connectBluetoothAudio( bluetoothDevice2.getAddress()); waitForHandlerAction(stateMachine.getAdapterHandler(), TEST_TIMEOUT); CallAudioState expectedEndState = new CallAudioState(false, CallAudioState.ROUTE_BLUETOOTH, Loading