From fc0bd90e00ccfadc45f0704f39cb5df57d63e041 Mon Sep 17 00:00:00 2001 From: changbetty Date: Mon, 13 Jun 2022 08:51:06 +0000 Subject: [PATCH] [LE Audio] To enable the broadcast button when media is playing on BT LE device Bug: 235192905 Test: atest -c MediaOutputDialogTest Change-Id: I05d0dff2df6acd515ba4f1dba337b4b890b07150 --- .../media/dialog/MediaOutputController.java | 4 ++++ .../media/dialog/MediaOutputDialog.java | 7 ++++++- .../media/dialog/MediaOutputDialogTest.java | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java index 9329b1bfc2a3a..8b94cb3a1eafd 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java @@ -795,6 +795,10 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, || features.contains(MediaRoute2Info.FEATURE_REMOTE_GROUP_PLAYBACK)); } + boolean isBluetoothLeDevice(@NonNull MediaDevice device) { + return device.isBLEDevice(); + } + boolean isBroadcastSupported() { LocalBluetoothLeBroadcast broadcast = mLocalBluetoothManager.getProfileManager().getLeAudioBroadcastProfile(); diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java index 9248433a4a903..a6cf408e00998 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java @@ -99,7 +99,12 @@ public class MediaOutputDialog extends MediaOutputBaseDialog { @Override public boolean isBroadcastSupported() { - return mMediaOutputController.isBroadcastSupported(); + boolean isBluetoothLeDevice = false; + if (mMediaOutputController.getCurrentConnectedMediaDevice() != null) { + isBluetoothLeDevice = mMediaOutputController.isBluetoothLeDevice( + mMediaOutputController.getCurrentConnectedMediaDevice()); + } + return mMediaOutputController.isBroadcastSupported() && isBluetoothLeDevice; } @Override diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java index e6ad6edcec45d..d09c92a3d730e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java @@ -136,15 +136,30 @@ public class MediaOutputDialogTest extends SysuiTestCase { mFeatures.add(MediaRoute2Info.FEATURE_REMOTE_GROUP_PLAYBACK); assertThat(mMediaOutputDialog.getStopButtonVisibility()).isEqualTo(View.VISIBLE); + } - mFeatures.clear(); + @Test + public void getStopButtonVisibility_remoteBLEDevice_returnVisible() { when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( mLocalBluetoothLeBroadcast); when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false); when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PLAYING); + when(mMediaDevice.isBLEDevice()).thenReturn(true); + assertThat(mMediaOutputDialog.getStopButtonVisibility()).isEqualTo(View.VISIBLE); } + @Test + public void getStopButtonVisibility_remoteNonBLEDevice_returnGone() { + when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( + mLocalBluetoothLeBroadcast); + when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false); + when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PLAYING); + when(mMediaDevice.isBLEDevice()).thenReturn(false); + + assertThat(mMediaOutputDialog.getStopButtonVisibility()).isEqualTo(View.GONE); + } + @Test public void getStopButtonVisibility_localDevice_returnGone() { mFeatures.add(MediaRoute2Info.FEATURE_LOCAL_PLAYBACK);