Loading src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +19 −3 Original line number Diff line number Diff line Loading @@ -568,7 +568,7 @@ public class BluetoothDeviceManager { // Connect audio to the bluetooth device at address, checking to see whether it's // le audio, hearing aid or a HFP device, and using the proper BT API. public boolean connectAudio(String address) { public boolean connectAudio(String address, boolean switchingBtDevices) { if (mLeAudioDevicesByAddress.containsKey(address)) { if (mBluetoothLeAudioService == null) { Log.w(this, "Attempting to turn on audio when the le audio service is null"); Loading @@ -577,8 +577,16 @@ public class BluetoothDeviceManager { BluetoothDevice device = mLeAudioDevicesByAddress.get(address); if (mBluetoothAdapter.setActiveDevice( device, BluetoothAdapter.ACTIVE_DEVICE_ALL)) { /* ACTION_ACTIVE_DEVICE_CHANGED intent will trigger setting communication device. * Only after receiving ACTION_ACTIVE_DEVICE_CHANGED it is known that device that * will be audio switched to is available to be choose as communication device */ if (!switchingBtDevices) { return setLeAudioCommunicationDevice(); } return true; } return false; } else if (mHearingAidDevicesByAddress.containsKey(address)) { if (mBluetoothHearingAid == null) { Loading @@ -588,8 +596,16 @@ public class BluetoothDeviceManager { if (mBluetoothAdapter.setActiveDevice( mHearingAidDevicesByAddress.get(address), BluetoothAdapter.ACTIVE_DEVICE_ALL)) { /* ACTION_ACTIVE_DEVICE_CHANGED intent will trigger setting communication device. * Only after receiving ACTION_ACTIVE_DEVICE_CHANGED it is known that device that * will be audio switched to is available to be choose as communication device */ if (!switchingBtDevices) { return setHearingAidCommunicationDevice(); } return true; } return false; } else if (mHfpDevicesByAddress.containsKey(address)) { BluetoothDevice device = mHfpDevicesByAddress.get(address); Loading src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -714,7 +714,7 @@ public class BluetoothRouteManager extends StateMachine { return null; } if (!mDeviceManager.connectAudio(actualAddress)) { if (!mDeviceManager.connectAudio(actualAddress, switchingBtDevices)) { boolean shouldRetry = retryCount < MAX_CONNECTION_RETRIES; Log.w(LOG_TAG, "Could not connect to %s. Will %s", actualAddress, shouldRetry ? "retry" : "not retry"); Loading tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +36 −5 Original line number Diff line number Diff line Loading @@ -381,7 +381,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { BluetoothDeviceManager.DEVICE_TYPE_HEADSET)); when(mAdapter.setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true); mBluetoothDeviceManager.connectAudio(device1.getAddress()); mBluetoothDeviceManager.connectAudio(device1.getAddress(), false); verify(mAdapter).setActiveDevice(device1, BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL); verify(mAdapter, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL)); Loading Loading @@ -410,12 +410,15 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { when(mockAudioManager.setCommunicationDevice(eq(mockAudioDeviceInfo))) .thenReturn(true); mBluetoothDeviceManager.connectAudio(device5.getAddress()); mBluetoothDeviceManager.connectAudio(device5.getAddress(), false); verify(mAdapter).setActiveDevice(device5, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mBluetoothHeadset, never()).connectAudio(); verify(mAdapter, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL)); receiverUnderTest.onReceive(mContext, buildActiveDeviceChangeActionIntent(device5, BluetoothDeviceManager.DEVICE_TYPE_HEARING_AID)); when(mockAudioManager.getCommunicationDevice()).thenReturn(mockAudioDeviceInfo); mBluetoothDeviceManager.disconnectAudio(); verify(mockAudioManager).clearCommunicationDevice(); Loading @@ -442,12 +445,15 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { when(mockAudioManager.setCommunicationDevice(mockAudioDeviceInfo)) .thenReturn(true); mBluetoothDeviceManager.connectAudio(device5.getAddress()); mBluetoothDeviceManager.connectAudio(device5.getAddress(), false); verify(mAdapter).setActiveDevice(device5, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mBluetoothHeadset, never()).connectAudio(); verify(mAdapter, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL)); receiverUnderTest.onReceive(mContext, buildActiveDeviceChangeActionIntent(device5, BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); mBluetoothDeviceManager.disconnectAudio(); verify(mockAudioManager).clearCommunicationDevice(); } Loading @@ -466,7 +472,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { leAudioCallbacksTest.getValue().onGroupNodeAdded(device6, 1); when(mAdapter.setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true); mBluetoothDeviceManager.connectAudio(device5.getAddress()); mBluetoothDeviceManager.connectAudio(device5.getAddress(), false); verify(mAdapter).setActiveDevice(device5, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mBluetoothHeadset, never()).connectAudio(); verify(mAdapter, never()).setActiveDevice(nullable(BluetoothDevice.class), Loading @@ -479,7 +485,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { buildConnectionActionIntent(BluetoothHeadset.STATE_DISCONNECTED, device5, BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); mBluetoothDeviceManager.connectAudio(device6.getAddress()); mBluetoothDeviceManager.connectAudio(device6.getAddress(), false); verify(mAdapter).setActiveDevice(device6, BluetoothAdapter.ACTIVE_DEVICE_ALL); } Loading Loading @@ -525,6 +531,31 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { return i; } private Intent buildActiveDeviceChangeActionIntent(BluetoothDevice device, int deviceType) { String intentString; switch (deviceType) { case BluetoothDeviceManager.DEVICE_TYPE_HEADSET: intentString = BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED; break; case BluetoothDeviceManager.DEVICE_TYPE_HEARING_AID: intentString = BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED; break; case BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO: intentString = BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED; break; default: return null; } Intent i = new Intent(intentString); i.putExtra(BluetoothDevice.EXTRA_DEVICE, device); i.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); return i; } private BluetoothDevice makeBluetoothDevice(String address) { Parcel p1 = Parcel.obtain(); p1.writeString(address); Loading tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import java.util.stream.Stream; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.reset; Loading Loading @@ -245,6 +246,7 @@ public class BluetoothRouteManagerTest extends TelecomTestCase { } private void verifyConnectionAttempt(BluetoothDevice device, int numTimes) { verify(mDeviceManager, times(numTimes)).connectAudio(device.getAddress()); verify(mDeviceManager, times(numTimes)).connectAudio(eq(device.getAddress()), anyBoolean()); } } tests/src/com/android/server/telecom/tests/BluetoothRouteTransitionTests.java +10 −5 Original line number Diff line number Diff line Loading @@ -359,18 +359,22 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { switch (mParams.expectedBluetoothInteraction) { case NONE: verify(mDeviceManager, never()).connectAudio(nullable(String.class)); verify(mDeviceManager, never()).connectAudio(nullable(String.class), any(boolean.class)); break; case CONNECT: verify(mDeviceManager).connectAudio(mParams.expectedConnectionDevice.getAddress()); verify(mDeviceManager).connectAudio(mParams.expectedConnectionDevice.getAddress(), false); verify(mDeviceManager, never()).disconnectAudio(); break; case CONNECT_SWITCH_DEVICE: verify(mDeviceManager).disconnectAudio(); verify(mDeviceManager).connectAudio(mParams.expectedConnectionDevice.getAddress()); verify(mDeviceManager).connectAudio(mParams.expectedConnectionDevice.getAddress(), true); break; case DISCONNECT: verify(mDeviceManager, never()).connectAudio(nullable(String.class)); verify(mDeviceManager, never()).connectAudio(nullable(String.class), any(boolean.class)); verify(mDeviceManager).disconnectAudio(); break; } Loading Loading @@ -402,7 +406,8 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { when(mDeviceManager.getBluetoothHeadset()).thenReturn(mBluetoothHeadset); when(mDeviceManager.getBluetoothHearingAid()).thenReturn(mBluetoothHearingAid); when(mDeviceManager.getLeAudioService()).thenReturn(mBluetoothLeAudio); when(mDeviceManager.connectAudio(nullable(String.class))).thenReturn(true); when(mDeviceManager.connectAudio(nullable(String.class), any(boolean.class))) .thenReturn(true); when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis( nullable(ContentResolver.class))).thenReturn(100000L); when(mTimeoutsAdapter.getBluetoothPendingTimeoutMillis( Loading Loading
src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +19 −3 Original line number Diff line number Diff line Loading @@ -568,7 +568,7 @@ public class BluetoothDeviceManager { // Connect audio to the bluetooth device at address, checking to see whether it's // le audio, hearing aid or a HFP device, and using the proper BT API. public boolean connectAudio(String address) { public boolean connectAudio(String address, boolean switchingBtDevices) { if (mLeAudioDevicesByAddress.containsKey(address)) { if (mBluetoothLeAudioService == null) { Log.w(this, "Attempting to turn on audio when the le audio service is null"); Loading @@ -577,8 +577,16 @@ public class BluetoothDeviceManager { BluetoothDevice device = mLeAudioDevicesByAddress.get(address); if (mBluetoothAdapter.setActiveDevice( device, BluetoothAdapter.ACTIVE_DEVICE_ALL)) { /* ACTION_ACTIVE_DEVICE_CHANGED intent will trigger setting communication device. * Only after receiving ACTION_ACTIVE_DEVICE_CHANGED it is known that device that * will be audio switched to is available to be choose as communication device */ if (!switchingBtDevices) { return setLeAudioCommunicationDevice(); } return true; } return false; } else if (mHearingAidDevicesByAddress.containsKey(address)) { if (mBluetoothHearingAid == null) { Loading @@ -588,8 +596,16 @@ public class BluetoothDeviceManager { if (mBluetoothAdapter.setActiveDevice( mHearingAidDevicesByAddress.get(address), BluetoothAdapter.ACTIVE_DEVICE_ALL)) { /* ACTION_ACTIVE_DEVICE_CHANGED intent will trigger setting communication device. * Only after receiving ACTION_ACTIVE_DEVICE_CHANGED it is known that device that * will be audio switched to is available to be choose as communication device */ if (!switchingBtDevices) { return setHearingAidCommunicationDevice(); } return true; } return false; } else if (mHfpDevicesByAddress.containsKey(address)) { BluetoothDevice device = mHfpDevicesByAddress.get(address); Loading
src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -714,7 +714,7 @@ public class BluetoothRouteManager extends StateMachine { return null; } if (!mDeviceManager.connectAudio(actualAddress)) { if (!mDeviceManager.connectAudio(actualAddress, switchingBtDevices)) { boolean shouldRetry = retryCount < MAX_CONNECTION_RETRIES; Log.w(LOG_TAG, "Could not connect to %s. Will %s", actualAddress, shouldRetry ? "retry" : "not retry"); Loading
tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +36 −5 Original line number Diff line number Diff line Loading @@ -381,7 +381,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { BluetoothDeviceManager.DEVICE_TYPE_HEADSET)); when(mAdapter.setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true); mBluetoothDeviceManager.connectAudio(device1.getAddress()); mBluetoothDeviceManager.connectAudio(device1.getAddress(), false); verify(mAdapter).setActiveDevice(device1, BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL); verify(mAdapter, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL)); Loading Loading @@ -410,12 +410,15 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { when(mockAudioManager.setCommunicationDevice(eq(mockAudioDeviceInfo))) .thenReturn(true); mBluetoothDeviceManager.connectAudio(device5.getAddress()); mBluetoothDeviceManager.connectAudio(device5.getAddress(), false); verify(mAdapter).setActiveDevice(device5, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mBluetoothHeadset, never()).connectAudio(); verify(mAdapter, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL)); receiverUnderTest.onReceive(mContext, buildActiveDeviceChangeActionIntent(device5, BluetoothDeviceManager.DEVICE_TYPE_HEARING_AID)); when(mockAudioManager.getCommunicationDevice()).thenReturn(mockAudioDeviceInfo); mBluetoothDeviceManager.disconnectAudio(); verify(mockAudioManager).clearCommunicationDevice(); Loading @@ -442,12 +445,15 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { when(mockAudioManager.setCommunicationDevice(mockAudioDeviceInfo)) .thenReturn(true); mBluetoothDeviceManager.connectAudio(device5.getAddress()); mBluetoothDeviceManager.connectAudio(device5.getAddress(), false); verify(mAdapter).setActiveDevice(device5, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mBluetoothHeadset, never()).connectAudio(); verify(mAdapter, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL)); receiverUnderTest.onReceive(mContext, buildActiveDeviceChangeActionIntent(device5, BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); mBluetoothDeviceManager.disconnectAudio(); verify(mockAudioManager).clearCommunicationDevice(); } Loading @@ -466,7 +472,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { leAudioCallbacksTest.getValue().onGroupNodeAdded(device6, 1); when(mAdapter.setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true); mBluetoothDeviceManager.connectAudio(device5.getAddress()); mBluetoothDeviceManager.connectAudio(device5.getAddress(), false); verify(mAdapter).setActiveDevice(device5, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mBluetoothHeadset, never()).connectAudio(); verify(mAdapter, never()).setActiveDevice(nullable(BluetoothDevice.class), Loading @@ -479,7 +485,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { buildConnectionActionIntent(BluetoothHeadset.STATE_DISCONNECTED, device5, BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); mBluetoothDeviceManager.connectAudio(device6.getAddress()); mBluetoothDeviceManager.connectAudio(device6.getAddress(), false); verify(mAdapter).setActiveDevice(device6, BluetoothAdapter.ACTIVE_DEVICE_ALL); } Loading Loading @@ -525,6 +531,31 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { return i; } private Intent buildActiveDeviceChangeActionIntent(BluetoothDevice device, int deviceType) { String intentString; switch (deviceType) { case BluetoothDeviceManager.DEVICE_TYPE_HEADSET: intentString = BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED; break; case BluetoothDeviceManager.DEVICE_TYPE_HEARING_AID: intentString = BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED; break; case BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO: intentString = BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED; break; default: return null; } Intent i = new Intent(intentString); i.putExtra(BluetoothDevice.EXTRA_DEVICE, device); i.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); return i; } private BluetoothDevice makeBluetoothDevice(String address) { Parcel p1 = Parcel.obtain(); p1.writeString(address); Loading
tests/src/com/android/server/telecom/tests/BluetoothRouteManagerTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import java.util.stream.Stream; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.reset; Loading Loading @@ -245,6 +246,7 @@ public class BluetoothRouteManagerTest extends TelecomTestCase { } private void verifyConnectionAttempt(BluetoothDevice device, int numTimes) { verify(mDeviceManager, times(numTimes)).connectAudio(device.getAddress()); verify(mDeviceManager, times(numTimes)).connectAudio(eq(device.getAddress()), anyBoolean()); } }
tests/src/com/android/server/telecom/tests/BluetoothRouteTransitionTests.java +10 −5 Original line number Diff line number Diff line Loading @@ -359,18 +359,22 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { switch (mParams.expectedBluetoothInteraction) { case NONE: verify(mDeviceManager, never()).connectAudio(nullable(String.class)); verify(mDeviceManager, never()).connectAudio(nullable(String.class), any(boolean.class)); break; case CONNECT: verify(mDeviceManager).connectAudio(mParams.expectedConnectionDevice.getAddress()); verify(mDeviceManager).connectAudio(mParams.expectedConnectionDevice.getAddress(), false); verify(mDeviceManager, never()).disconnectAudio(); break; case CONNECT_SWITCH_DEVICE: verify(mDeviceManager).disconnectAudio(); verify(mDeviceManager).connectAudio(mParams.expectedConnectionDevice.getAddress()); verify(mDeviceManager).connectAudio(mParams.expectedConnectionDevice.getAddress(), true); break; case DISCONNECT: verify(mDeviceManager, never()).connectAudio(nullable(String.class)); verify(mDeviceManager, never()).connectAudio(nullable(String.class), any(boolean.class)); verify(mDeviceManager).disconnectAudio(); break; } Loading Loading @@ -402,7 +406,8 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase { when(mDeviceManager.getBluetoothHeadset()).thenReturn(mBluetoothHeadset); when(mDeviceManager.getBluetoothHearingAid()).thenReturn(mBluetoothHearingAid); when(mDeviceManager.getLeAudioService()).thenReturn(mBluetoothLeAudio); when(mDeviceManager.connectAudio(nullable(String.class))).thenReturn(true); when(mDeviceManager.connectAudio(nullable(String.class), any(boolean.class))) .thenReturn(true); when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis( nullable(ContentResolver.class))).thenReturn(100000L); when(mTimeoutsAdapter.getBluetoothPendingTimeoutMillis( Loading