diff options
4 files changed, 57 insertions, 17 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java index 012d76651b23..b02393b4f73a 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java @@ -488,8 +488,8 @@ public class MediaControlPanel { TextView deviceName = mMediaViewHolder.getSeamlessText(); final MediaDeviceData device = data.getDevice(); - final boolean enabled; - final boolean seamlessDisabled; + final boolean isTapEnabled; + final boolean useDisabledAlpha; final int iconResource; CharSequence deviceString; if (showBroadcastButton) { @@ -499,21 +499,25 @@ public class MediaControlPanel { && TextUtils.equals(device.getName(), MediaDataUtils.getAppLabel(mContext, mPackageName, mContext.getString( R.string.bt_le_audio_broadcast_dialog_unknown_name))); - seamlessDisabled = !mIsCurrentBroadcastedApp; + useDisabledAlpha = !mIsCurrentBroadcastedApp; // Always be enabled if the broadcast button is shown - enabled = true; + isTapEnabled = true; + + // Defaults for broadcasting state deviceString = mContext.getString(R.string.bt_le_audio_broadcast_dialog_unknown_name); iconResource = R.drawable.settings_input_antenna; } else { // Disable clicking on output switcher for invalid devices and resumption controls - seamlessDisabled = (device != null && !device.getEnabled()) || data.getResumption(); - enabled = !seamlessDisabled; + useDisabledAlpha = (device != null && !device.getEnabled()) || data.getResumption(); + isTapEnabled = !useDisabledAlpha; + + // Defaults for non-broadcasting state deviceString = mContext.getString(R.string.media_seamless_other_device); iconResource = R.drawable.ic_media_home_devices; } - mMediaViewHolder.getSeamlessButton().setAlpha(seamlessDisabled ? DISABLED_ALPHA : 1.0f); - seamlessView.setEnabled(enabled); + mMediaViewHolder.getSeamlessButton().setAlpha(useDisabledAlpha ? DISABLED_ALPHA : 1.0f); + seamlessView.setEnabled(isTapEnabled); if (device != null) { Drawable icon = device.getIcon(); @@ -524,7 +528,9 @@ public class MediaControlPanel { } else { iconView.setImageDrawable(icon); } - deviceString = device.getName(); + if (device.getName() != null) { + deviceString = device.getName(); + } } else { // Set to default icon iconView.setImageResource(iconResource); diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt index 25186597e0e1..b3a4ddf8ec1f 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt @@ -348,7 +348,11 @@ class MediaDeviceManager @Inject constructor( // If we have a controller but get a null route, then don't trust the device val enabled = device != null && (controller == null || route != null) - val name = route?.name?.toString() ?: device?.name + val name = if (controller == null || route != null) { + route?.name?.toString() ?: device?.name + } else { + null + } current = MediaDeviceData(enabled, device?.iconWithoutBackground, name, id = device?.id, showBroadcastButton = false) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt index 178502269e73..bef46953395b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt @@ -1051,6 +1051,17 @@ public class MediaControlPanelTest : SysuiTestCase() { } @Test + fun bindDeviceWithNullName() { + val fallbackString = context.getResources().getString(R.string.media_seamless_other_device) + player.attachPlayer(viewHolder) + val state = mediaData.copy(device = device.copy(name = null)) + player.bindPlayer(state, PACKAGE) + assertThat(seamless.isEnabled()).isTrue() + assertThat(seamlessText.getText()).isEqualTo(fallbackString) + assertThat(seamless.contentDescription).isEqualTo(fallbackString) + } + + @Test fun bindDeviceResumptionPlayer() { player.attachPlayer(viewHolder) val state = mediaData.copy(resumption = true) diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/MediaDeviceManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/MediaDeviceManagerTest.kt index ee104262dc29..121c8946d164 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/MediaDeviceManagerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/MediaDeviceManagerTest.kt @@ -59,8 +59,8 @@ import org.mockito.Mockito.reset import org.mockito.Mockito.times import org.mockito.Mockito.verify import org.mockito.Mockito.verifyNoMoreInteractions -import org.mockito.junit.MockitoJUnit import org.mockito.Mockito.`when` as whenever +import org.mockito.junit.MockitoJUnit private const val KEY = "TEST_KEY" private const val KEY_OLD = "TEST_KEY_OLD" @@ -402,9 +402,10 @@ public class MediaDeviceManagerTest : SysuiTestCase() { manager.onMediaDataLoaded(KEY, null, mediaData) fakeBgExecutor.runAllReady() fakeFgExecutor.runAllReady() - // THEN the device is disabled + // THEN the device is disabled and name is set to null val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() + assertThat(data.name).isNull() } @Test @@ -421,9 +422,10 @@ public class MediaDeviceManagerTest : SysuiTestCase() { deviceCallback.onSelectedDeviceStateChanged(device, 1) fakeBgExecutor.runAllReady() fakeFgExecutor.runAllReady() - // THEN the device is disabled + // THEN the device is disabled and name is set to null val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() + assertThat(data.name).isNull() } @Test @@ -440,9 +442,24 @@ public class MediaDeviceManagerTest : SysuiTestCase() { deviceCallback.onDeviceListUpdate(mutableListOf(device)) fakeBgExecutor.runAllReady() fakeFgExecutor.runAllReady() - // THEN the device is disabled + // THEN the device is disabled and name is set to null val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() + assertThat(data.name).isNull() + } + + @Test + fun mr2ReturnsRouteWithNullName_useLocalDeviceName() { + // GIVEN that MR2Manager returns a routing session that does not have a name + whenever(route.name).thenReturn(null) + // WHEN a notification is added + manager.onMediaDataLoaded(KEY, null, mediaData) + fakeBgExecutor.runAllReady() + fakeFgExecutor.runAllReady() + // THEN the device is enabled and uses the current connected device name + val data = captureDeviceData(KEY) + assertThat(data.name).isEqualTo(DEVICE_NAME) + assertThat(data.enabled).isTrue() } @Test @@ -647,12 +664,14 @@ public class MediaDeviceManagerTest : SysuiTestCase() { override fun onPlaybackStopped(reason: Int, broadcastId: Int) {} override fun onBroadcastUpdated(reason: Int, broadcastId: Int) {} override fun onBroadcastUpdateFailed(reason: Int, broadcastId: Int) {} - override fun onBroadcastMetadataChanged(broadcastId: Int, - metadata: BluetoothLeBroadcastMetadata) {} + override fun onBroadcastMetadataChanged( + broadcastId: Int, + metadata: BluetoothLeBroadcastMetadata + ) {} } bluetoothLeBroadcast.registerCallback(fakeFgExecutor, callback) - return callback; + return callback } fun setupLeAudioConfiguration(isLeAudio: Boolean) { |