From 6f1beb8f6ffd92704f72fc3bba8bc43380ba27b3 Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Mon, 8 Apr 2019 13:34:16 -0700 Subject: Fix the audio-on device detection logic Earlier change had broken the logic that we use to detect where audio was being routed to in the BT stack. Fix that by checking to see whether the HFP device is actually routing audio. Fixes: 128813699 Test: manual, unit Change-Id: I4be99c192cd5a7cc80c26339b599ece6e525cffe --- .../telecom/tests/BluetoothRouteManagerTest.java | 18 ++++++++++++++++++ .../telecom/tests/BluetoothRouteTransitionTests.java | 2 ++ 2 files changed, 20 insertions(+) (limited to 'tests/src/com/android/server/telecom') diff --git a/tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java b/tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java index 060031d8..93c29097 100644 --- a/tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java +++ b/tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java @@ -112,6 +112,22 @@ public class BluetoothRouteManagerTest extends TelecomTestCase { sm.quitNow(); } + @SmallTest + @Test + public void testAudioOnDeviceWithScoOffActiveDevice() { + BluetoothRouteManager sm = setupStateMachine( + BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX, DEVICE1); + setupConnectedDevices(new BluetoothDevice[]{DEVICE1}, null, DEVICE1, null); + when(mHeadsetProxy.getAudioState(DEVICE1)) + .thenReturn(BluetoothHeadset.STATE_AUDIO_DISCONNECTED); + executeRoutingAction(sm, BluetoothRouteManager.BT_AUDIO_LOST, DEVICE1.getAddress()); + + verifyConnectionAttempt(DEVICE1, 0); + assertEquals(BluetoothRouteManager.AUDIO_OFF_STATE_NAME, + sm.getCurrentState().getName()); + sm.quitNow(); + } + @SmallTest @Test public void testConnectHfpRetryWhileConnectedToAnotherDevice() { @@ -164,6 +180,8 @@ public class BluetoothRouteManagerTest extends TelecomTestCase { when(mDeviceManager.getConnectedDevices()).thenReturn(allDevices); when(mHeadsetProxy.getConnectedDevices()).thenReturn(Arrays.asList(hfpDevices)); when(mHeadsetProxy.getActiveDevice()).thenReturn(hfpActiveDevice); + when(mHeadsetProxy.getAudioState(hfpActiveDevice)) + .thenReturn(BluetoothHeadset.STATE_AUDIO_CONNECTED); when(mBluetoothHearingAid.getConnectedDevices()) .thenReturn(Arrays.asList(hearingAidDevices)); diff --git a/tests/src/com/android/server/telecom/tests/BluetoothRouteTransitionTests.java b/tests/src/com/android/server/telecom/tests/BluetoothRouteTransitionTests.java index 2f68ac27..2584f330 100644 --- a/tests/src/com/android/server/telecom/tests/BluetoothRouteTransitionTests.java +++ b/tests/src/com/android/server/telecom/tests/BluetoothRouteTransitionTests.java @@ -341,6 +341,8 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { when(mHeadsetProxy.getActiveDevice()).thenReturn(activeDevice); if (audioOnDevice != null) { when(mHeadsetProxy.getActiveDevice()).thenReturn(audioOnDevice); + when(mHeadsetProxy.getAudioState(audioOnDevice)) + .thenReturn(BluetoothHeadset.STATE_AUDIO_CONNECTED); } } -- cgit v1.2.3