Loading services/core/java/com/android/server/media/AudioManagerRouteController.java +1 −1 Original line number Diff line number Diff line Loading @@ -420,7 +420,7 @@ import java.util.Objects; // to derive a name ourselves from the type instead. String deviceName = audioDeviceInfo.getPort().name(); if (!TextUtils.isEmpty(address)) { if (mBluetoothRouteController.containsBondedDeviceWithAddress(address)) { routeId = mBluetoothRouteController.getRouteIdForBluetoothAddress(address); deviceName = mBluetoothRouteController.getNameForBluetoothAddress(address); } Loading services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -141,6 +141,11 @@ import java.util.stream.Collectors; mContext.unregisterReceiver(mDeviceStateChangedReceiver); } /** Returns true if the given address corresponds to a currently-bonded Bluetooth device. */ public synchronized boolean containsBondedDeviceWithAddress(@Nullable String address) { return mAddressToBondedDevice.containsKey(address); } @Nullable public synchronized String getRouteIdForBluetoothAddress(@Nullable String address) { BluetoothDevice bluetoothDevice = mAddressToBondedDevice.get(address); Loading services/tests/media/mediarouterservicetest/src/com/android/server/media/AudioManagerRouteControllerTest.java +54 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,11 @@ public class AudioManagerRouteControllerTest { private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET = createAudioDeviceInfo( AudioSystem.DEVICE_OUT_WIRED_HEADSET, "name_wired_hs", /* address= */ null); private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS = createAudioDeviceInfo( AudioSystem.DEVICE_OUT_WIRED_HEADSET, "name_wired_hs_with_address", /* address= */ "card=1;device=0"); private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_BLUETOOTH_A2DP = createAudioDeviceInfo( AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, "name_a2dp", /* address= */ "12:34:45"); Loading Loading @@ -304,6 +309,55 @@ public class AudioManagerRouteControllerTest { assertThat(selectedRoute.getName().toString()).isEqualTo(FAKE_ROUTE_NAME); } @Test public void getAvailableRoutes_whenAddressIsPopulatedForNonBluetoothDevice_usesCorrectName() { addAvailableAudioDeviceInfo( /* newSelectedDevice= */ FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS, /* newAvailableDevices...= */ FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS, FAKE_AUDIO_DEVICE_INFO_BLUETOOTH_A2DP); List<MediaRoute2Info> availableRoutes = mControllerUnderTest.getAvailableRoutes(); assertThat(availableRoutes.size()).isEqualTo(3); assertThat( getAvailableRouteWithType(MediaRoute2Info.TYPE_WIRED_HEADSET) .getName() .toString()) .isEqualTo( FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS .getProductName() .toString()); assertThat( getAvailableRouteWithType(MediaRoute2Info.TYPE_BLUETOOTH_A2DP) .getName() .toString()) .isEqualTo(FAKE_AUDIO_DEVICE_INFO_BLUETOOTH_A2DP.getProductName().toString()); } @Test public void getAvailableRoutes_whenAddressIsNotPopulatedForNonBluetoothDevice_usesCorrectName() { addAvailableAudioDeviceInfo( /* newSelectedDevice= */ FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET, /* newAvailableDevices...= */ FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET); List<MediaRoute2Info> availableRoutes = mControllerUnderTest.getAvailableRoutes(); assertThat(availableRoutes.size()).isEqualTo(2); assertThat( getAvailableRouteWithType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER) .getName() .toString()) .isEqualTo(FAKE_AUDIO_DEVICE_INFO_BUILTIN_SPEAKER.getProductName().toString()); assertThat( getAvailableRouteWithType(MediaRoute2Info.TYPE_WIRED_HEADSET) .getName() .toString()) .isEqualTo(FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET.getProductName().toString()); } // Internal methods. @NonNull Loading Loading
services/core/java/com/android/server/media/AudioManagerRouteController.java +1 −1 Original line number Diff line number Diff line Loading @@ -420,7 +420,7 @@ import java.util.Objects; // to derive a name ourselves from the type instead. String deviceName = audioDeviceInfo.getPort().name(); if (!TextUtils.isEmpty(address)) { if (mBluetoothRouteController.containsBondedDeviceWithAddress(address)) { routeId = mBluetoothRouteController.getRouteIdForBluetoothAddress(address); deviceName = mBluetoothRouteController.getNameForBluetoothAddress(address); } Loading
services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -141,6 +141,11 @@ import java.util.stream.Collectors; mContext.unregisterReceiver(mDeviceStateChangedReceiver); } /** Returns true if the given address corresponds to a currently-bonded Bluetooth device. */ public synchronized boolean containsBondedDeviceWithAddress(@Nullable String address) { return mAddressToBondedDevice.containsKey(address); } @Nullable public synchronized String getRouteIdForBluetoothAddress(@Nullable String address) { BluetoothDevice bluetoothDevice = mAddressToBondedDevice.get(address); Loading
services/tests/media/mediarouterservicetest/src/com/android/server/media/AudioManagerRouteControllerTest.java +54 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,11 @@ public class AudioManagerRouteControllerTest { private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET = createAudioDeviceInfo( AudioSystem.DEVICE_OUT_WIRED_HEADSET, "name_wired_hs", /* address= */ null); private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS = createAudioDeviceInfo( AudioSystem.DEVICE_OUT_WIRED_HEADSET, "name_wired_hs_with_address", /* address= */ "card=1;device=0"); private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_BLUETOOTH_A2DP = createAudioDeviceInfo( AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, "name_a2dp", /* address= */ "12:34:45"); Loading Loading @@ -304,6 +309,55 @@ public class AudioManagerRouteControllerTest { assertThat(selectedRoute.getName().toString()).isEqualTo(FAKE_ROUTE_NAME); } @Test public void getAvailableRoutes_whenAddressIsPopulatedForNonBluetoothDevice_usesCorrectName() { addAvailableAudioDeviceInfo( /* newSelectedDevice= */ FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS, /* newAvailableDevices...= */ FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS, FAKE_AUDIO_DEVICE_INFO_BLUETOOTH_A2DP); List<MediaRoute2Info> availableRoutes = mControllerUnderTest.getAvailableRoutes(); assertThat(availableRoutes.size()).isEqualTo(3); assertThat( getAvailableRouteWithType(MediaRoute2Info.TYPE_WIRED_HEADSET) .getName() .toString()) .isEqualTo( FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS .getProductName() .toString()); assertThat( getAvailableRouteWithType(MediaRoute2Info.TYPE_BLUETOOTH_A2DP) .getName() .toString()) .isEqualTo(FAKE_AUDIO_DEVICE_INFO_BLUETOOTH_A2DP.getProductName().toString()); } @Test public void getAvailableRoutes_whenAddressIsNotPopulatedForNonBluetoothDevice_usesCorrectName() { addAvailableAudioDeviceInfo( /* newSelectedDevice= */ FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET, /* newAvailableDevices...= */ FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET); List<MediaRoute2Info> availableRoutes = mControllerUnderTest.getAvailableRoutes(); assertThat(availableRoutes.size()).isEqualTo(2); assertThat( getAvailableRouteWithType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER) .getName() .toString()) .isEqualTo(FAKE_AUDIO_DEVICE_INFO_BUILTIN_SPEAKER.getProductName().toString()); assertThat( getAvailableRouteWithType(MediaRoute2Info.TYPE_WIRED_HEADSET) .getName() .toString()) .isEqualTo(FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET.getProductName().toString()); } // Internal methods. @NonNull Loading