From 623ed192e869d5812c5731ab828639f6d39de8f2 Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Tue, 12 Jul 2022 19:08:35 +0800 Subject: [PATCH] [LeAudio Broadcast] Shows the broadcast icon on output switcher When the devcie is broadcasting, the output switcher UI shows the broadcast icon in the top right corner. Figma: https://www.figma.com/file/3Kf9EnVdbvQKP5Q1CUviTY/LE-Audio?node-id=0%3A1 Screenshot1: show broadcasting icon https://hsv.googleplex.com/4875202925166592?node=10 Screenshot2: hide broadcasting icon https://hsv.googleplex.com/6429825930625024?node=7 Bug: 215469904 Test: [pass] atest MediaOutputDialogTest [pass] atest MediaOutputBaseDialogTest Change-Id: I764f2b0de0d2e008a05b95135507f51ede0b2131 --- .../res/layout/media_output_dialog.xml | 33 ++++++++++++++--- .../media/dialog/MediaOutputBaseDialog.java | 13 +++++++ .../media/dialog/MediaOutputDialog.java | 11 ++++++ .../dialog/MediaOutputBaseDialogTest.java | 35 +++++++++++++++++++ .../media/dialog/MediaOutputDialogTest.java | 33 +++++++++++++++++ 5 files changed, 120 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/res/layout/media_output_dialog.xml b/packages/SystemUI/res/layout/media_output_dialog.xml index 1efb4796b5b79..52140f42eb080 100644 --- a/packages/SystemUI/res/layout/media_output_dialog.xml +++ b/packages/SystemUI/res/layout/media_output_dialog.xml @@ -42,12 +42,35 @@ android:layout_height="wrap_content" android:paddingStart="12dp" android:orientation="vertical"> - + android:orientation="horizontal"> + + + + + + onStopButtonClick()); + + mBroadcastIcon.setVisibility(getBroadcastIconVisibility()); + mBroadcastIcon.setOnClickListener(v -> onBroadcastIconClick()); } private void updateButtonBackgroundColorFilter() { @@ -490,6 +495,14 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements dismiss(); } + public int getBroadcastIconVisibility() { + return View.GONE; + } + + public void onBroadcastIconClick() { + // Do nothing. + } + public boolean isBroadcastSupported() { return false; } 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 a6cf408e00998..afa1dd351787e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java @@ -134,6 +134,17 @@ public class MediaOutputDialog extends MediaOutputBaseDialog { } } + @Override + public int getBroadcastIconVisibility() { + return (isBroadcastSupported() && mMediaOutputController.isBluetoothLeBroadcastEnabled()) + ? View.VISIBLE : View.GONE; + } + + @Override + public void onBroadcastIconClick() { + startLeBroadcastDialog(); + } + @VisibleForTesting public enum MediaOutputEvent implements UiEventLogger.UiEventEnum { @UiEvent(doc = "The MediaOutput dialog became visible on the screen.") diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java index 9eaa20c2afedb..d414660018a8c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java @@ -43,6 +43,8 @@ import android.widget.TextView; import androidx.core.graphics.drawable.IconCompat; import androidx.test.filters.SmallTest; +import com.android.settingslib.bluetooth.CachedBluetoothDevice; +import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; @@ -98,10 +100,17 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase { private CharSequence mHeaderSubtitle; private String mStopText; private boolean mIsBroadcasting; + private boolean mIsBroadcastIconVisibility; + @Before public void setUp() { when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager); + final CachedBluetoothDeviceManager cachedBluetoothDeviceManager = mock( + CachedBluetoothDeviceManager.class); + when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn( + cachedBluetoothDeviceManager); + when(cachedBluetoothDeviceManager.findDevice(any())).thenReturn(null); when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(null); when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState); when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_NONE); @@ -152,6 +161,27 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase { assertThat(view.getVisibility()).isEqualTo(View.GONE); } + @Test + public void refresh_broadcastIconVisibilityOff_broadcastIconLayoutNotVisible() { + mIsBroadcastIconVisibility = false; + + mMediaOutputBaseDialogImpl.refresh(); + final ImageView view = mMediaOutputBaseDialogImpl.mDialogView.requireViewById( + R.id.broadcast_icon); + + assertThat(view.getVisibility()).isEqualTo(View.GONE); + } + @Test + public void refresh_broadcastIconVisibilityOn_broadcastIconLayoutVisible() { + mIsBroadcastIconVisibility = true; + + mMediaOutputBaseDialogImpl.refresh(); + final ImageView view = mMediaOutputBaseDialogImpl.mDialogView.requireViewById( + R.id.broadcast_icon); + + assertThat(view.getVisibility()).isEqualTo(View.VISIBLE); + } + @Test public void refresh_checkTitle() { mHeaderTitle = "test_string"; @@ -308,5 +338,10 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase { public CharSequence getStopButtonText() { return mStopText; } + + @Override + public int getBroadcastIconVisibility() { + return mIsBroadcastIconVisibility ? View.VISIBLE : View.GONE; + } } } 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 c45db05baceea..6afed1a846b07 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 @@ -171,6 +171,39 @@ public class MediaOutputDialogTest extends SysuiTestCase { assertThat(mMediaOutputDialog.getStopButtonVisibility()).isEqualTo(View.GONE); } + @Test + public void getBroadcastIconVisibility_isBroadcasting_returnVisible() { + when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( + mLocalBluetoothLeBroadcast); + when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(true); + when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PLAYING); + when(mMediaDevice.isBLEDevice()).thenReturn(true); + + assertThat(mMediaOutputDialog.getBroadcastIconVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void getBroadcastIconVisibility_noBroadcasting_returnGone() { + 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.getBroadcastIconVisibility()).isEqualTo(View.GONE); + } + + @Test + public void getBroadcastIconVisibility_remoteNonLeDevice_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.getBroadcastIconVisibility()).isEqualTo(View.GONE); + } + @Test // Check the visibility metric logging by creating a new MediaOutput dialog, // and verify if the calling times increases.