Loading flags/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ aconfig_declarations { "telecom_callaudiomodestatemachine_flags.aconfig", "telecom_calllog_flags.aconfig", "telecom_resolve_hidden_dependencies.aconfig", "telecom_bluetoothroutemanager_flags.aconfig", ], } flags/telecom_bluetoothroutemanager_flags.aconfig 0 → 100644 +9 −0 Original line number Diff line number Diff line package: "com.android.server.telecom.flags" flag { name: "use_actual_address_to_enter_connecting_state" namespace: "telecom" description: "Fix bugs that may add bluetooth device with null address." bug: "306113816" } src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java +7 −2 Original line number Diff line number Diff line Loading @@ -393,8 +393,13 @@ public class BluetoothRouteManager extends StateMachine { String actualAddress = connectBtAudio(address, true /* switchingBtDevices*/); if (actualAddress != null) { if (mFeatureFlags.useActualAddressToEnterConnectingState()) { transitionTo(getConnectingStateForAddress(actualAddress, "AudioConnected/CONNECT_BT")); } else { transitionTo(getConnectingStateForAddress(address, "AudioConnected/CONNECT_BT")); } } else { Log.w(LOG_TAG, "Tried to connect to %s but failed" + " to connect to any BT device.", (String) args.arg2); Loading tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -185,6 +185,33 @@ public class BluetoothRouteManagerTest extends TelecomTestCase { sm.quitNow(); } @SmallTest @Test public void testConnectBtWithoutAddress() { when(mFeatureFlags.useActualAddressToEnterConnectingState()).thenReturn(true); BluetoothRouteManager sm = setupStateMachine( BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX, DEVICE1); setupConnectedDevices(new BluetoothDevice[]{DEVICE1, DEVICE2}, null, null, null, null, null); when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis( nullable(ContentResolver.class))).thenReturn(0L); when(mBluetoothHeadset.connectAudio()).thenReturn(BluetoothStatusCodes.ERROR_UNKNOWN); executeRoutingAction(sm, BluetoothRouteManager.CONNECT_BT, null); // Wait 3 times: the first connection attempt is accounted for in executeRoutingAction, // so wait twice for the retry attempt, again to make sure there are only three attempts, // and once more for good luck. waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); verifyConnectionAttempt(DEVICE1, 1); assertEquals(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX + ":" + DEVICE1.getAddress(), sm.getCurrentState().getName()); sm.getHandler().removeMessages(BluetoothRouteManager.CONNECTION_TIMEOUT); sm.quitNow(); } private BluetoothRouteManager setupStateMachine(String initialState, BluetoothDevice initialDevice) { resetMocks(); Loading Loading
flags/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ aconfig_declarations { "telecom_callaudiomodestatemachine_flags.aconfig", "telecom_calllog_flags.aconfig", "telecom_resolve_hidden_dependencies.aconfig", "telecom_bluetoothroutemanager_flags.aconfig", ], }
flags/telecom_bluetoothroutemanager_flags.aconfig 0 → 100644 +9 −0 Original line number Diff line number Diff line package: "com.android.server.telecom.flags" flag { name: "use_actual_address_to_enter_connecting_state" namespace: "telecom" description: "Fix bugs that may add bluetooth device with null address." bug: "306113816" }
src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java +7 −2 Original line number Diff line number Diff line Loading @@ -393,8 +393,13 @@ public class BluetoothRouteManager extends StateMachine { String actualAddress = connectBtAudio(address, true /* switchingBtDevices*/); if (actualAddress != null) { if (mFeatureFlags.useActualAddressToEnterConnectingState()) { transitionTo(getConnectingStateForAddress(actualAddress, "AudioConnected/CONNECT_BT")); } else { transitionTo(getConnectingStateForAddress(address, "AudioConnected/CONNECT_BT")); } } else { Log.w(LOG_TAG, "Tried to connect to %s but failed" + " to connect to any BT device.", (String) args.arg2); Loading
tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -185,6 +185,33 @@ public class BluetoothRouteManagerTest extends TelecomTestCase { sm.quitNow(); } @SmallTest @Test public void testConnectBtWithoutAddress() { when(mFeatureFlags.useActualAddressToEnterConnectingState()).thenReturn(true); BluetoothRouteManager sm = setupStateMachine( BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX, DEVICE1); setupConnectedDevices(new BluetoothDevice[]{DEVICE1, DEVICE2}, null, null, null, null, null); when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis( nullable(ContentResolver.class))).thenReturn(0L); when(mBluetoothHeadset.connectAudio()).thenReturn(BluetoothStatusCodes.ERROR_UNKNOWN); executeRoutingAction(sm, BluetoothRouteManager.CONNECT_BT, null); // Wait 3 times: the first connection attempt is accounted for in executeRoutingAction, // so wait twice for the retry attempt, again to make sure there are only three attempts, // and once more for good luck. waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); verifyConnectionAttempt(DEVICE1, 1); assertEquals(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX + ":" + DEVICE1.getAddress(), sm.getCurrentState().getName()); sm.getHandler().removeMessages(BluetoothRouteManager.CONNECTION_TIMEOUT); sm.quitNow(); } private BluetoothRouteManager setupStateMachine(String initialState, BluetoothDevice initialDevice) { resetMocks(); Loading