Loading src/com/android/server/telecom/CallAudioRouteStateMachine.java +6 −3 Original line number Diff line number Diff line Loading @@ -1607,10 +1607,13 @@ public class CallAudioRouteStateMachine extends StateMachine { BluetoothDevice connectedDevice = mBluetoothRouteManager.getBluetoothAudioConnectedDevice(); if (address == null && connectedDevice != null) { // null means connect to any device, so don't bother reconnecting. Also, send a // message to ourselves telling us that BT audio is already connected. Log.i(this, "HFP audio already on. Skipping connecting."); // null means connect to any device, so if we're already connected to some device, // that means we can just tell ourselves that it's connected. // Do still try to connect audio though, so that BluetoothRouteManager knows that // there's an active call. Log.i(this, "Bluetooth audio already on."); sendInternalMessage(BT_AUDIO_CONNECTED); mBluetoothRouteManager.connectBluetoothAudio(connectedDevice.getAddress()); return; } if (connectedDevice == null || !Objects.equals(address, connectedDevice.getAddress())) { Loading src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -645,6 +645,16 @@ public class BluetoothRouteManager extends StateMachine { Log.i(this, "No device with address %s available. Using %s instead.", address, actualAddress); } BluetoothDevice alreadyConnectedDevice = getBluetoothAudioConnectedDevice(); if (alreadyConnectedDevice != null && alreadyConnectedDevice.getAddress().equals( actualAddress)) { Log.i(this, "trying to connect to already connected device -- skipping connection" + " and going into the actual connected state."); transitionToActualState(); return null; } if (!mDeviceManager.connectAudio(actualAddress)) { boolean shouldRetry = retryCount < MAX_CONNECTION_RETRIES; Log.w(LOG_TAG, "Could not connect to %s. Will %s", actualAddress, Loading tests/src/com/android/server/telecom/tests/BluetoothRouteTransitionTests.java +18 −0 Original line number Diff line number Diff line Loading @@ -346,6 +346,8 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { when(mDeviceManager.getConnectedDevices()).thenReturn(Arrays.asList(devices)); when(mHeadsetProxy.getConnectedDevices()).thenReturn(Arrays.asList(devices)); when(mHeadsetProxy.getActiveDevice()).thenReturn(activeDevice); when(mHeadsetProxy.getAudioState(nullable(BluetoothDevice.class))) .thenReturn(BluetoothHeadset.STATE_AUDIO_DISCONNECTED); if (audioOnDevice != null) { when(mHeadsetProxy.getActiveDevice()).thenReturn(audioOnDevice); when(mHeadsetProxy.getAudioState(audioOnDevice)) Loading Loading @@ -634,6 +636,22 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { .setExpectedBluetoothInteraction(NONE) .setExpectedFinalStateName(BluetoothRouteManager.AUDIO_OFF_STATE_NAME) .build()); result.add(new BluetoothRouteTestParametersBuilder() .setName("connect BT to an already active device when in audio off.") .setInitialBluetoothState(BluetoothRouteManager.AUDIO_OFF_STATE_NAME) .setAudioOnDevice(DEVICE2) .setActiveDevice(DEVICE2) .setConnectedDevices(DEVICE2, DEVICE3) .setHearingAidBtDevices(Collections.singletonList(DEVICE2)) .setMessageType(BluetoothRouteManager.CONNECT_HFP) .setMessageDevice(DEVICE2) .setExpectedListenerUpdates(ListenerUpdate.AUDIO_CONNECTED) .setExpectedBluetoothInteraction(NONE) .setExpectedFinalStateName(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX + ":" + DEVICE2) .build()); return result; } } tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java +6 −3 Original line number Diff line number Diff line Loading @@ -54,9 +54,11 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; Loading Loading @@ -486,9 +488,10 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase { CallAudioRouteStateMachine.ACTIVE_FOCUS); waitForHandlerAction(stateMachine.getHandler(), TEST_TIMEOUT); // Make sure that we've successfully switched to the active BT route without actually // calling connectAudio. verify(mockBluetoothRouteManager, never()).connectBluetoothAudio(nullable(String.class)); // Make sure that we've successfully switched to the active BT route and that we've // called connectAudio on the right device. verify(mockBluetoothRouteManager, atLeastOnce()) .connectBluetoothAudio(eq(bluetoothDevice1.getAddress())); assertTrue(stateMachine.isInActiveState()); } Loading Loading
src/com/android/server/telecom/CallAudioRouteStateMachine.java +6 −3 Original line number Diff line number Diff line Loading @@ -1607,10 +1607,13 @@ public class CallAudioRouteStateMachine extends StateMachine { BluetoothDevice connectedDevice = mBluetoothRouteManager.getBluetoothAudioConnectedDevice(); if (address == null && connectedDevice != null) { // null means connect to any device, so don't bother reconnecting. Also, send a // message to ourselves telling us that BT audio is already connected. Log.i(this, "HFP audio already on. Skipping connecting."); // null means connect to any device, so if we're already connected to some device, // that means we can just tell ourselves that it's connected. // Do still try to connect audio though, so that BluetoothRouteManager knows that // there's an active call. Log.i(this, "Bluetooth audio already on."); sendInternalMessage(BT_AUDIO_CONNECTED); mBluetoothRouteManager.connectBluetoothAudio(connectedDevice.getAddress()); return; } if (connectedDevice == null || !Objects.equals(address, connectedDevice.getAddress())) { Loading
src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -645,6 +645,16 @@ public class BluetoothRouteManager extends StateMachine { Log.i(this, "No device with address %s available. Using %s instead.", address, actualAddress); } BluetoothDevice alreadyConnectedDevice = getBluetoothAudioConnectedDevice(); if (alreadyConnectedDevice != null && alreadyConnectedDevice.getAddress().equals( actualAddress)) { Log.i(this, "trying to connect to already connected device -- skipping connection" + " and going into the actual connected state."); transitionToActualState(); return null; } if (!mDeviceManager.connectAudio(actualAddress)) { boolean shouldRetry = retryCount < MAX_CONNECTION_RETRIES; Log.w(LOG_TAG, "Could not connect to %s. Will %s", actualAddress, Loading
tests/src/com/android/server/telecom/tests/BluetoothRouteTransitionTests.java +18 −0 Original line number Diff line number Diff line Loading @@ -346,6 +346,8 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { when(mDeviceManager.getConnectedDevices()).thenReturn(Arrays.asList(devices)); when(mHeadsetProxy.getConnectedDevices()).thenReturn(Arrays.asList(devices)); when(mHeadsetProxy.getActiveDevice()).thenReturn(activeDevice); when(mHeadsetProxy.getAudioState(nullable(BluetoothDevice.class))) .thenReturn(BluetoothHeadset.STATE_AUDIO_DISCONNECTED); if (audioOnDevice != null) { when(mHeadsetProxy.getActiveDevice()).thenReturn(audioOnDevice); when(mHeadsetProxy.getAudioState(audioOnDevice)) Loading Loading @@ -634,6 +636,22 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { .setExpectedBluetoothInteraction(NONE) .setExpectedFinalStateName(BluetoothRouteManager.AUDIO_OFF_STATE_NAME) .build()); result.add(new BluetoothRouteTestParametersBuilder() .setName("connect BT to an already active device when in audio off.") .setInitialBluetoothState(BluetoothRouteManager.AUDIO_OFF_STATE_NAME) .setAudioOnDevice(DEVICE2) .setActiveDevice(DEVICE2) .setConnectedDevices(DEVICE2, DEVICE3) .setHearingAidBtDevices(Collections.singletonList(DEVICE2)) .setMessageType(BluetoothRouteManager.CONNECT_HFP) .setMessageDevice(DEVICE2) .setExpectedListenerUpdates(ListenerUpdate.AUDIO_CONNECTED) .setExpectedBluetoothInteraction(NONE) .setExpectedFinalStateName(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX + ":" + DEVICE2) .build()); return result; } }
tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java +6 −3 Original line number Diff line number Diff line Loading @@ -54,9 +54,11 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; Loading Loading @@ -486,9 +488,10 @@ public class CallAudioRouteStateMachineTest extends TelecomTestCase { CallAudioRouteStateMachine.ACTIVE_FOCUS); waitForHandlerAction(stateMachine.getHandler(), TEST_TIMEOUT); // Make sure that we've successfully switched to the active BT route without actually // calling connectAudio. verify(mockBluetoothRouteManager, never()).connectBluetoothAudio(nullable(String.class)); // Make sure that we've successfully switched to the active BT route and that we've // called connectAudio on the right device. verify(mockBluetoothRouteManager, atLeastOnce()) .connectBluetoothAudio(eq(bluetoothDevice1.getAddress())); assertTrue(stateMachine.isInActiveState()); } Loading