Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +5 −2 Original line number Diff line number Diff line Loading @@ -125,13 +125,16 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, private final NearbyMediaDevicesManager mNearbyMediaDevicesManager; private final Map<String, Integer> mNearbyDeviceInfoMap = new ConcurrentHashMap<>(); private boolean mIsRefreshing = false; private boolean mNeedRefresh = false; @VisibleForTesting boolean mIsRefreshing = false; @VisibleForTesting boolean mNeedRefresh = false; private MediaController mMediaController; @VisibleForTesting Callback mCallback; @VisibleForTesting LocalMediaManager mLocalMediaManager; @VisibleForTesting private MediaOutputMetricLogger mMetricLogger; private int mCurrentState; Loading packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java +106 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.WallpaperColors; import android.graphics.Bitmap; import android.graphics.drawable.Icon; import android.testing.AndroidTestingRunner; import android.view.View; Loading Loading @@ -101,6 +103,18 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mMediaOutputAdapter.getItemCount()).isEqualTo(mMediaDevices.size() + 1); } @Test public void getItemId_validPosition_returnCorrespondingId() { assertThat(mMediaOutputAdapter.getItemId(0)).isEqualTo(mMediaDevices.get( 0).getId().hashCode()); } @Test public void getItemId_invalidPosition_returnPosition() { int invalidPosition = mMediaDevices.size() + 1; assertThat(mMediaOutputAdapter.getItemId(invalidPosition)).isEqualTo(invalidPosition); } @Test public void onBindViewHolder_bindPairNew_verifyView() { mMediaOutputAdapter.onBindViewHolder(mViewHolder, 2); Loading Loading @@ -154,6 +168,33 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE); } @Test public void onBindViewHolder_bindConnectedDeviceWithMutingExpectedDeviceExist_verifyView() { when(mMediaOutputController.hasMutingExpectedDevice()).thenReturn(true); when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(false); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0); assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1); } @Test public void onBindViewHolder_isMutingExpectedDevice_verifyView() { when(mMediaDevice1.isMutingExpectedDevice()).thenReturn(true); when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(false); when(mMediaOutputController.isActiveRemoteDevice(mMediaDevice1)).thenReturn(false); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0); assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1); } @Test public void onBindViewHolder_initSeekbar_setsVolume() { when(mMediaDevice1.getMaxVolume()).thenReturn(TEST_MAX_VOLUME); Loading @@ -164,6 +205,20 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mSeekBar.getVolume()).isEqualTo(TEST_CURRENT_VOLUME); } @Test public void onBindViewHolder_bindSelectableDevice_verifyView() { List<MediaDevice> selectableDevices = new ArrayList<>(); selectableDevices.add(mMediaDevice2); when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(selectableDevices); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 1); assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_2); } @Test public void onBindViewHolder_bindNonActiveConnectedDevice_verifyView() { mMediaOutputAdapter.onBindViewHolder(mViewHolder, 1); Loading Loading @@ -222,6 +277,22 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); } @Test public void onBindViewHolder_bindGroupingDevice_verifyView() { when(mMediaOutputController.isAnyDeviceTransferring()).thenReturn(false); when(mMediaDevice1.getState()).thenReturn( LocalMediaManager.MediaDeviceState.STATE_GROUPING); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0); assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1); assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mSubTitleText.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); } @Test public void onBindViewHolder_inTransferring_bindNonTransferringDevice_verifyView() { when(mMediaOutputController.isAnyDeviceTransferring()).thenReturn(true); Loading Loading @@ -255,6 +326,31 @@ public class MediaOutputAdapterTest extends SysuiTestCase { verify(mMediaOutputController).connectDevice(mMediaDevice2); } @Test public void onItemClick_clicksWithMutingExpectedDeviceExist_cancelsMuteAwaitConnection() { when(mMediaOutputController.isAnyDeviceTransferring()).thenReturn(false); when(mMediaOutputController.hasMutingExpectedDevice()).thenReturn(true); when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(false); when(mMediaDevice1.isMutingExpectedDevice()).thenReturn(false); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0); mViewHolder.mContainerLayout.performClick(); verify(mMediaOutputController).cancelMuteAwaitConnection(); } @Test public void onItemClick_clicksSelectableDevice_triggerGrouping() { List<MediaDevice> selectableDevices = new ArrayList<>(); selectableDevices.add(mMediaDevice2); when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(selectableDevices); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 1); mViewHolder.mContainerLayout.performClick(); verify(mMediaOutputController).addDeviceToPlayMedia(mMediaDevice2); } @Test public void onItemClick_onGroupActionTriggered_verifySeekbarDisabled() { when(mMediaOutputController.getSelectedMediaDevice()).thenReturn(mMediaDevices); Loading @@ -280,4 +376,14 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mSeekBar.isEnabled()).isTrue(); } @Test public void updateColorScheme_triggerController() { WallpaperColors wallpaperColors = WallpaperColors.fromBitmap( Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)); mMediaOutputAdapter.updateColorScheme(wallpaperColors, true); verify(mMediaOutputController).setCurrentColorScheme(wallpaperColors, true); } } packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java +245 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.app.KeyguardManager; import android.app.Notification; import android.content.Context; import android.graphics.drawable.Icon; import android.media.AudioDeviceAttributes; import android.media.AudioManager; import android.media.MediaDescription; import android.media.MediaMetadata; Loading Loading @@ -169,6 +170,15 @@ public class MediaOutputControllerTest extends SysuiTestCase { verify(mLocalMediaManager).startScan(); } @Test public void start_LocalMediaManagerIsNull_verifyNotStartScan() { mMediaOutputController.mLocalMediaManager = null; mMediaOutputController.start(mCb); verify(mLocalMediaManager, never()).registerCallback(mMediaOutputController); verify(mLocalMediaManager, never()).startScan(); } @Test public void stop_verifyLocalMediaManagerDeinit() { mMediaOutputController.start(mCb); Loading Loading @@ -278,6 +288,203 @@ public class MediaOutputControllerTest extends SysuiTestCase { verify(mCb).onDeviceListChanged(); } @Test public void onDeviceListUpdate_isRefreshing_updatesNeedRefreshToTrue() { mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.mIsRefreshing = true; mMediaOutputController.onDeviceListUpdate(mMediaDevices); assertThat(mMediaOutputController.mNeedRefresh).isTrue(); } @Test public void cancelMuteAwaitConnection_cancelsWithMediaManager() { when(mAudioManager.getMutingExpectedDevice()).thenReturn(mock(AudioDeviceAttributes.class)); mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.cancelMuteAwaitConnection(); verify(mAudioManager).cancelMuteAwaitConnection(any()); } @Test public void cancelMuteAwaitConnection_audioManagerIsNull_noAction() { when(mAudioManager.getMutingExpectedDevice()).thenReturn(null); mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.cancelMuteAwaitConnection(); verify(mAudioManager, never()).cancelMuteAwaitConnection(any()); } @Test public void getAppSourceName_packageNameIsNull_returnsNull() { MediaOutputController testMediaOutputController = new MediaOutputController(mSpyContext, "", mMediaSessionManager, mLocalBluetoothManager, mStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager, mKeyguardManager); testMediaOutputController.start(mCb); reset(mCb); testMediaOutputController.getAppSourceName(); assertThat(testMediaOutputController.getAppSourceName()).isNull(); } @Test public void isActiveItem_deviceNotConnected_returnsFalse() { when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice2); assertThat(mMediaOutputController.isActiveItem(mMediaDevice1)).isFalse(); } @Test public void getNotificationSmallIcon_packageNameIsNull_returnsNull() { MediaOutputController testMediaOutputController = new MediaOutputController(mSpyContext, "", mMediaSessionManager, mLocalBluetoothManager, mStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager, mKeyguardManager); testMediaOutputController.start(mCb); reset(mCb); testMediaOutputController.getAppSourceName(); assertThat(testMediaOutputController.getNotificationSmallIcon()).isNull(); } @Test public void refreshDataSetIfNeeded_needRefreshIsTrue_setsToFalse() { mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.mNeedRefresh = true; mMediaOutputController.refreshDataSetIfNeeded(); assertThat(mMediaOutputController.mNeedRefresh).isFalse(); } @Test public void isCurrentConnectedDeviceRemote_containsFeatures_returnsTrue() { when(mMediaDevice1.getFeatures()).thenReturn( ImmutableList.of(MediaRoute2Info.FEATURE_REMOTE_PLAYBACK)); when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice1); assertThat(mMediaOutputController.isCurrentConnectedDeviceRemote()).isTrue(); } @Test public void addDeviceToPlayMedia_triggersFromLocalMediaManager() { MediaOutputController testMediaOutputController = new MediaOutputController(mSpyContext, null, mMediaSessionManager, mLocalBluetoothManager, mStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager, mKeyguardManager); LocalMediaManager testLocalMediaManager = spy(testMediaOutputController.mLocalMediaManager); testMediaOutputController.mLocalMediaManager = testLocalMediaManager; testMediaOutputController.addDeviceToPlayMedia(mMediaDevice2); verify(testLocalMediaManager).addDeviceToPlayMedia(mMediaDevice2); } @Test public void removeDeviceFromPlayMedia_triggersFromLocalMediaManager() { MediaOutputController testMediaOutputController = new MediaOutputController(mSpyContext, null, mMediaSessionManager, mLocalBluetoothManager, mStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager, mKeyguardManager); LocalMediaManager testLocalMediaManager = spy(testMediaOutputController.mLocalMediaManager); testMediaOutputController.mLocalMediaManager = testLocalMediaManager; testMediaOutputController.removeDeviceFromPlayMedia(mMediaDevice2); verify(testLocalMediaManager).removeDeviceFromPlayMedia(mMediaDevice2); } @Test public void getDeselectableMediaDevice_triggersFromLocalMediaManager() { mMediaOutputController.getDeselectableMediaDevice(); verify(mLocalMediaManager).getDeselectableMediaDevice(); } @Test public void adjustSessionVolume_adjustWithoutId_triggersFromLocalMediaManager() { int testVolume = 10; mMediaOutputController.adjustSessionVolume(testVolume); verify(mLocalMediaManager).adjustSessionVolume(testVolume); } @Test public void getSessionVolumeMax_triggersFromLocalMediaManager() { mMediaOutputController.getSessionVolumeMax(); verify(mLocalMediaManager).getSessionVolumeMax(); } @Test public void getSessionVolume_triggersFromLocalMediaManager() { mMediaOutputController.getSessionVolume(); verify(mLocalMediaManager).getSessionVolume(); } @Test public void getSessionName_triggersFromLocalMediaManager() { mMediaOutputController.getSessionName(); verify(mLocalMediaManager).getSessionName(); } @Test public void releaseSession_triggersFromLocalMediaManager() { mMediaOutputController.releaseSession(); verify(mLocalMediaManager).releaseSession(); } @Test public void isAnyDeviceTransferring_noDevicesStateIsConnecting_returnsFalse() { mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.onDeviceListUpdate(mMediaDevices); assertThat(mMediaOutputController.isAnyDeviceTransferring()).isFalse(); } @Test public void isAnyDeviceTransferring_deviceStateIsConnecting_returnsTrue() { when(mMediaDevice1.getState()).thenReturn( LocalMediaManager.MediaDeviceState.STATE_CONNECTING); mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.onDeviceListUpdate(mMediaDevices); assertThat(mMediaOutputController.isAnyDeviceTransferring()).isTrue(); } @Test public void isPlaying_stateIsNull() { when(mMediaController.getPlaybackState()).thenReturn(null); assertThat(mMediaOutputController.isPlaying()).isFalse(); } @Test public void onSelectedDeviceStateChanged_verifyCallback() { when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice2); Loading Loading @@ -534,6 +741,44 @@ public class MediaOutputControllerTest extends SysuiTestCase { assertThat(mMediaOutputController.getNotificationIcon()).isNull(); } @Test public void getNotificationSmallIcon_withoutSmallIcon_returnsNull() { final List<NotificationEntry> entryList = new ArrayList<>(); final NotificationEntry entry = mock(NotificationEntry.class); final StatusBarNotification sbn = mock(StatusBarNotification.class); final Notification notification = mock(Notification.class); entryList.add(entry); when(mNotifCollection.getAllNotifs()).thenReturn(entryList); when(entry.getSbn()).thenReturn(sbn); when(sbn.getNotification()).thenReturn(notification); when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME); when(notification.isMediaNotification()).thenReturn(true); when(notification.getSmallIcon()).thenReturn(null); assertThat(mMediaOutputController.getNotificationSmallIcon()).isNull(); } @Test public void getNotificationSmallIcon_withPackageNameAndMediaSession_returnsIconCompat() { final List<NotificationEntry> entryList = new ArrayList<>(); final NotificationEntry entry = mock(NotificationEntry.class); final StatusBarNotification sbn = mock(StatusBarNotification.class); final Notification notification = mock(Notification.class); final Icon icon = mock(Icon.class); entryList.add(entry); when(mNotifCollection.getAllNotifs()).thenReturn(entryList); when(entry.getSbn()).thenReturn(sbn); when(sbn.getNotification()).thenReturn(notification); when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME); when(notification.isMediaNotification()).thenReturn(true); when(notification.getSmallIcon()).thenReturn(icon); assertThat(mMediaOutputController.getNotificationSmallIcon()).isInstanceOf( IconCompat.class); } @Test public void isVolumeControlEnabled_isCastWithVolumeFixed_returnsFalse() { when(mMediaDevice1.getDeviceType()).thenReturn( Loading packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java +82 −0 Original line number Diff line number Diff line Loading @@ -25,7 +25,10 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.KeyguardManager; import android.graphics.Bitmap; import android.media.AudioManager; import android.media.MediaDescription; import android.media.MediaMetadata; import android.media.MediaRoute2Info; import android.media.session.MediaController; import android.media.session.MediaSessionManager; Loading @@ -43,6 +46,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.media.LocalMediaManager; import com.android.settingslib.media.MediaDevice; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.animation.DialogLaunchAnimator; import com.android.systemui.broadcast.BroadcastSender; Loading Loading @@ -82,6 +86,8 @@ public class MediaOutputDialogTest extends SysuiTestCase { private final CommonNotifCollection mNotifCollection = mock(CommonNotifCollection.class); private final UiEventLogger mUiEventLogger = mock(UiEventLogger.class); private final DialogLaunchAnimator mDialogLaunchAnimator = mock(DialogLaunchAnimator.class); private final MediaMetadata mMediaMetadata = mock(MediaMetadata.class); private final MediaDescription mMediaDescription = mock(MediaDescription.class); private final NearbyMediaDevicesManager mNearbyMediaDevicesManager = mock( NearbyMediaDevicesManager.class); private final AudioManager mAudioManager = mock(AudioManager.class); Loading @@ -100,6 +106,8 @@ public class MediaOutputDialogTest extends SysuiTestCase { when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState); when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_NONE); when(mMediaController.getPackageName()).thenReturn(TEST_PACKAGE); when(mMediaController.getMetadata()).thenReturn(mMediaMetadata); when(mMediaMetadata.getDescription()).thenReturn(mMediaDescription); mMediaControllers.add(mMediaController); when(mMediaSessionManager.getActiveSessions(any())).thenReturn(mMediaControllers); Loading Loading @@ -206,6 +214,80 @@ public class MediaOutputDialogTest extends SysuiTestCase { assertThat(mMediaOutputDialog.getBroadcastIconVisibility()).isEqualTo(View.GONE); } @Test public void getHeaderIcon_getFromMediaControllerMetaData() { int testWidth = 10; int testHeight = 20; when(mMediaDescription.getIconBitmap()) .thenReturn(Bitmap.createBitmap(testWidth, testHeight, Bitmap.Config.ARGB_8888)); assertThat(mMediaOutputDialog.getHeaderIcon().getBitmap().getHeight()).isEqualTo( testHeight); assertThat(mMediaOutputDialog.getHeaderIcon().getBitmap().getWidth()).isEqualTo(testWidth); } @Test public void getHeaderText_getFromMediaControllerMetaData() { String testTitle = "test title"; when(mMediaDescription.getTitle()) .thenReturn(testTitle); assertThat(mMediaOutputDialog.getHeaderText().toString()).isEqualTo(testTitle); } @Test public void getHeaderSubtitle_getFromMediaControllerMetaData() { String testSubtitle = "test title"; when(mMediaDescription.getSubtitle()) .thenReturn(testSubtitle); assertThat(mMediaOutputDialog.getHeaderSubtitle().toString()).isEqualTo(testSubtitle); } @Test public void getStopButtonText_notSupportsBroadcast_returnsDefaultText() { String stopText = mContext.getText(R.string.keyboard_key_media_stop).toString(); MediaOutputController mockMediaOutputController = mock(MediaOutputController.class); when(mockMediaOutputController.isBroadcastSupported()).thenReturn(false); MediaOutputDialog testDialog = new MediaOutputDialog(mContext, false, mBroadcastSender, mockMediaOutputController, mUiEventLogger); testDialog.show(); assertThat(testDialog.getStopButtonText().toString()).isEqualTo(stopText); } @Test public void getStopButtonText_supportsBroadcast_returnsBroadcastText() { String stopText = mContext.getText(R.string.media_output_broadcast).toString(); MediaDevice mMediaDevice = mock(MediaDevice.class); MediaOutputController mockMediaOutputController = mock(MediaOutputController.class); when(mockMediaOutputController.isBroadcastSupported()).thenReturn(true); when(mockMediaOutputController.getCurrentConnectedMediaDevice()).thenReturn(mMediaDevice); when(mockMediaOutputController.isBluetoothLeDevice(any())).thenReturn(true); when(mockMediaOutputController.isPlaying()).thenReturn(true); when(mockMediaOutputController.isBluetoothLeBroadcastEnabled()).thenReturn(false); MediaOutputDialog testDialog = new MediaOutputDialog(mContext, false, mBroadcastSender, mockMediaOutputController, mUiEventLogger); testDialog.show(); assertThat(testDialog.getStopButtonText().toString()).isEqualTo(stopText); } @Test public void onStopButtonClick_notPlaying_releaseSession() { MediaOutputController mockMediaOutputController = mock(MediaOutputController.class); when(mockMediaOutputController.isBroadcastSupported()).thenReturn(false); when(mockMediaOutputController.getCurrentConnectedMediaDevice()).thenReturn(null); when(mockMediaOutputController.isPlaying()).thenReturn(false); MediaOutputDialog testDialog = new MediaOutputDialog(mContext, false, mBroadcastSender, mockMediaOutputController, mUiEventLogger); testDialog.show(); testDialog.onStopButtonClick(); verify(mockMediaOutputController).releaseSession(); } @Test // Check the visibility metric logging by creating a new MediaOutput dialog, // and verify if the calling times increases. Loading Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +5 −2 Original line number Diff line number Diff line Loading @@ -125,13 +125,16 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, private final NearbyMediaDevicesManager mNearbyMediaDevicesManager; private final Map<String, Integer> mNearbyDeviceInfoMap = new ConcurrentHashMap<>(); private boolean mIsRefreshing = false; private boolean mNeedRefresh = false; @VisibleForTesting boolean mIsRefreshing = false; @VisibleForTesting boolean mNeedRefresh = false; private MediaController mMediaController; @VisibleForTesting Callback mCallback; @VisibleForTesting LocalMediaManager mLocalMediaManager; @VisibleForTesting private MediaOutputMetricLogger mMetricLogger; private int mCurrentState; Loading
packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java +106 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.WallpaperColors; import android.graphics.Bitmap; import android.graphics.drawable.Icon; import android.testing.AndroidTestingRunner; import android.view.View; Loading Loading @@ -101,6 +103,18 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mMediaOutputAdapter.getItemCount()).isEqualTo(mMediaDevices.size() + 1); } @Test public void getItemId_validPosition_returnCorrespondingId() { assertThat(mMediaOutputAdapter.getItemId(0)).isEqualTo(mMediaDevices.get( 0).getId().hashCode()); } @Test public void getItemId_invalidPosition_returnPosition() { int invalidPosition = mMediaDevices.size() + 1; assertThat(mMediaOutputAdapter.getItemId(invalidPosition)).isEqualTo(invalidPosition); } @Test public void onBindViewHolder_bindPairNew_verifyView() { mMediaOutputAdapter.onBindViewHolder(mViewHolder, 2); Loading Loading @@ -154,6 +168,33 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE); } @Test public void onBindViewHolder_bindConnectedDeviceWithMutingExpectedDeviceExist_verifyView() { when(mMediaOutputController.hasMutingExpectedDevice()).thenReturn(true); when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(false); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0); assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1); } @Test public void onBindViewHolder_isMutingExpectedDevice_verifyView() { when(mMediaDevice1.isMutingExpectedDevice()).thenReturn(true); when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(false); when(mMediaOutputController.isActiveRemoteDevice(mMediaDevice1)).thenReturn(false); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0); assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1); } @Test public void onBindViewHolder_initSeekbar_setsVolume() { when(mMediaDevice1.getMaxVolume()).thenReturn(TEST_MAX_VOLUME); Loading @@ -164,6 +205,20 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mSeekBar.getVolume()).isEqualTo(TEST_CURRENT_VOLUME); } @Test public void onBindViewHolder_bindSelectableDevice_verifyView() { List<MediaDevice> selectableDevices = new ArrayList<>(); selectableDevices.add(mMediaDevice2); when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(selectableDevices); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 1); assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_2); } @Test public void onBindViewHolder_bindNonActiveConnectedDevice_verifyView() { mMediaOutputAdapter.onBindViewHolder(mViewHolder, 1); Loading Loading @@ -222,6 +277,22 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); } @Test public void onBindViewHolder_bindGroupingDevice_verifyView() { when(mMediaOutputController.isAnyDeviceTransferring()).thenReturn(false); when(mMediaDevice1.getState()).thenReturn( LocalMediaManager.MediaDeviceState.STATE_GROUPING); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0); assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1); assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mSubTitleText.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE); assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE); } @Test public void onBindViewHolder_inTransferring_bindNonTransferringDevice_verifyView() { when(mMediaOutputController.isAnyDeviceTransferring()).thenReturn(true); Loading Loading @@ -255,6 +326,31 @@ public class MediaOutputAdapterTest extends SysuiTestCase { verify(mMediaOutputController).connectDevice(mMediaDevice2); } @Test public void onItemClick_clicksWithMutingExpectedDeviceExist_cancelsMuteAwaitConnection() { when(mMediaOutputController.isAnyDeviceTransferring()).thenReturn(false); when(mMediaOutputController.hasMutingExpectedDevice()).thenReturn(true); when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(false); when(mMediaDevice1.isMutingExpectedDevice()).thenReturn(false); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0); mViewHolder.mContainerLayout.performClick(); verify(mMediaOutputController).cancelMuteAwaitConnection(); } @Test public void onItemClick_clicksSelectableDevice_triggerGrouping() { List<MediaDevice> selectableDevices = new ArrayList<>(); selectableDevices.add(mMediaDevice2); when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(selectableDevices); mMediaOutputAdapter.onBindViewHolder(mViewHolder, 1); mViewHolder.mContainerLayout.performClick(); verify(mMediaOutputController).addDeviceToPlayMedia(mMediaDevice2); } @Test public void onItemClick_onGroupActionTriggered_verifySeekbarDisabled() { when(mMediaOutputController.getSelectedMediaDevice()).thenReturn(mMediaDevices); Loading @@ -280,4 +376,14 @@ public class MediaOutputAdapterTest extends SysuiTestCase { assertThat(mViewHolder.mSeekBar.isEnabled()).isTrue(); } @Test public void updateColorScheme_triggerController() { WallpaperColors wallpaperColors = WallpaperColors.fromBitmap( Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)); mMediaOutputAdapter.updateColorScheme(wallpaperColors, true); verify(mMediaOutputController).setCurrentColorScheme(wallpaperColors, true); } }
packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java +245 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.app.KeyguardManager; import android.app.Notification; import android.content.Context; import android.graphics.drawable.Icon; import android.media.AudioDeviceAttributes; import android.media.AudioManager; import android.media.MediaDescription; import android.media.MediaMetadata; Loading Loading @@ -169,6 +170,15 @@ public class MediaOutputControllerTest extends SysuiTestCase { verify(mLocalMediaManager).startScan(); } @Test public void start_LocalMediaManagerIsNull_verifyNotStartScan() { mMediaOutputController.mLocalMediaManager = null; mMediaOutputController.start(mCb); verify(mLocalMediaManager, never()).registerCallback(mMediaOutputController); verify(mLocalMediaManager, never()).startScan(); } @Test public void stop_verifyLocalMediaManagerDeinit() { mMediaOutputController.start(mCb); Loading Loading @@ -278,6 +288,203 @@ public class MediaOutputControllerTest extends SysuiTestCase { verify(mCb).onDeviceListChanged(); } @Test public void onDeviceListUpdate_isRefreshing_updatesNeedRefreshToTrue() { mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.mIsRefreshing = true; mMediaOutputController.onDeviceListUpdate(mMediaDevices); assertThat(mMediaOutputController.mNeedRefresh).isTrue(); } @Test public void cancelMuteAwaitConnection_cancelsWithMediaManager() { when(mAudioManager.getMutingExpectedDevice()).thenReturn(mock(AudioDeviceAttributes.class)); mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.cancelMuteAwaitConnection(); verify(mAudioManager).cancelMuteAwaitConnection(any()); } @Test public void cancelMuteAwaitConnection_audioManagerIsNull_noAction() { when(mAudioManager.getMutingExpectedDevice()).thenReturn(null); mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.cancelMuteAwaitConnection(); verify(mAudioManager, never()).cancelMuteAwaitConnection(any()); } @Test public void getAppSourceName_packageNameIsNull_returnsNull() { MediaOutputController testMediaOutputController = new MediaOutputController(mSpyContext, "", mMediaSessionManager, mLocalBluetoothManager, mStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager, mKeyguardManager); testMediaOutputController.start(mCb); reset(mCb); testMediaOutputController.getAppSourceName(); assertThat(testMediaOutputController.getAppSourceName()).isNull(); } @Test public void isActiveItem_deviceNotConnected_returnsFalse() { when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice2); assertThat(mMediaOutputController.isActiveItem(mMediaDevice1)).isFalse(); } @Test public void getNotificationSmallIcon_packageNameIsNull_returnsNull() { MediaOutputController testMediaOutputController = new MediaOutputController(mSpyContext, "", mMediaSessionManager, mLocalBluetoothManager, mStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager, mKeyguardManager); testMediaOutputController.start(mCb); reset(mCb); testMediaOutputController.getAppSourceName(); assertThat(testMediaOutputController.getNotificationSmallIcon()).isNull(); } @Test public void refreshDataSetIfNeeded_needRefreshIsTrue_setsToFalse() { mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.mNeedRefresh = true; mMediaOutputController.refreshDataSetIfNeeded(); assertThat(mMediaOutputController.mNeedRefresh).isFalse(); } @Test public void isCurrentConnectedDeviceRemote_containsFeatures_returnsTrue() { when(mMediaDevice1.getFeatures()).thenReturn( ImmutableList.of(MediaRoute2Info.FEATURE_REMOTE_PLAYBACK)); when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice1); assertThat(mMediaOutputController.isCurrentConnectedDeviceRemote()).isTrue(); } @Test public void addDeviceToPlayMedia_triggersFromLocalMediaManager() { MediaOutputController testMediaOutputController = new MediaOutputController(mSpyContext, null, mMediaSessionManager, mLocalBluetoothManager, mStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager, mKeyguardManager); LocalMediaManager testLocalMediaManager = spy(testMediaOutputController.mLocalMediaManager); testMediaOutputController.mLocalMediaManager = testLocalMediaManager; testMediaOutputController.addDeviceToPlayMedia(mMediaDevice2); verify(testLocalMediaManager).addDeviceToPlayMedia(mMediaDevice2); } @Test public void removeDeviceFromPlayMedia_triggersFromLocalMediaManager() { MediaOutputController testMediaOutputController = new MediaOutputController(mSpyContext, null, mMediaSessionManager, mLocalBluetoothManager, mStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager, mKeyguardManager); LocalMediaManager testLocalMediaManager = spy(testMediaOutputController.mLocalMediaManager); testMediaOutputController.mLocalMediaManager = testLocalMediaManager; testMediaOutputController.removeDeviceFromPlayMedia(mMediaDevice2); verify(testLocalMediaManager).removeDeviceFromPlayMedia(mMediaDevice2); } @Test public void getDeselectableMediaDevice_triggersFromLocalMediaManager() { mMediaOutputController.getDeselectableMediaDevice(); verify(mLocalMediaManager).getDeselectableMediaDevice(); } @Test public void adjustSessionVolume_adjustWithoutId_triggersFromLocalMediaManager() { int testVolume = 10; mMediaOutputController.adjustSessionVolume(testVolume); verify(mLocalMediaManager).adjustSessionVolume(testVolume); } @Test public void getSessionVolumeMax_triggersFromLocalMediaManager() { mMediaOutputController.getSessionVolumeMax(); verify(mLocalMediaManager).getSessionVolumeMax(); } @Test public void getSessionVolume_triggersFromLocalMediaManager() { mMediaOutputController.getSessionVolume(); verify(mLocalMediaManager).getSessionVolume(); } @Test public void getSessionName_triggersFromLocalMediaManager() { mMediaOutputController.getSessionName(); verify(mLocalMediaManager).getSessionName(); } @Test public void releaseSession_triggersFromLocalMediaManager() { mMediaOutputController.releaseSession(); verify(mLocalMediaManager).releaseSession(); } @Test public void isAnyDeviceTransferring_noDevicesStateIsConnecting_returnsFalse() { mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.onDeviceListUpdate(mMediaDevices); assertThat(mMediaOutputController.isAnyDeviceTransferring()).isFalse(); } @Test public void isAnyDeviceTransferring_deviceStateIsConnecting_returnsTrue() { when(mMediaDevice1.getState()).thenReturn( LocalMediaManager.MediaDeviceState.STATE_CONNECTING); mMediaOutputController.start(mCb); reset(mCb); mMediaOutputController.onDeviceListUpdate(mMediaDevices); assertThat(mMediaOutputController.isAnyDeviceTransferring()).isTrue(); } @Test public void isPlaying_stateIsNull() { when(mMediaController.getPlaybackState()).thenReturn(null); assertThat(mMediaOutputController.isPlaying()).isFalse(); } @Test public void onSelectedDeviceStateChanged_verifyCallback() { when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice2); Loading Loading @@ -534,6 +741,44 @@ public class MediaOutputControllerTest extends SysuiTestCase { assertThat(mMediaOutputController.getNotificationIcon()).isNull(); } @Test public void getNotificationSmallIcon_withoutSmallIcon_returnsNull() { final List<NotificationEntry> entryList = new ArrayList<>(); final NotificationEntry entry = mock(NotificationEntry.class); final StatusBarNotification sbn = mock(StatusBarNotification.class); final Notification notification = mock(Notification.class); entryList.add(entry); when(mNotifCollection.getAllNotifs()).thenReturn(entryList); when(entry.getSbn()).thenReturn(sbn); when(sbn.getNotification()).thenReturn(notification); when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME); when(notification.isMediaNotification()).thenReturn(true); when(notification.getSmallIcon()).thenReturn(null); assertThat(mMediaOutputController.getNotificationSmallIcon()).isNull(); } @Test public void getNotificationSmallIcon_withPackageNameAndMediaSession_returnsIconCompat() { final List<NotificationEntry> entryList = new ArrayList<>(); final NotificationEntry entry = mock(NotificationEntry.class); final StatusBarNotification sbn = mock(StatusBarNotification.class); final Notification notification = mock(Notification.class); final Icon icon = mock(Icon.class); entryList.add(entry); when(mNotifCollection.getAllNotifs()).thenReturn(entryList); when(entry.getSbn()).thenReturn(sbn); when(sbn.getNotification()).thenReturn(notification); when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME); when(notification.isMediaNotification()).thenReturn(true); when(notification.getSmallIcon()).thenReturn(icon); assertThat(mMediaOutputController.getNotificationSmallIcon()).isInstanceOf( IconCompat.class); } @Test public void isVolumeControlEnabled_isCastWithVolumeFixed_returnsFalse() { when(mMediaDevice1.getDeviceType()).thenReturn( Loading
packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java +82 −0 Original line number Diff line number Diff line Loading @@ -25,7 +25,10 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.KeyguardManager; import android.graphics.Bitmap; import android.media.AudioManager; import android.media.MediaDescription; import android.media.MediaMetadata; import android.media.MediaRoute2Info; import android.media.session.MediaController; import android.media.session.MediaSessionManager; Loading @@ -43,6 +46,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.media.LocalMediaManager; import com.android.settingslib.media.MediaDevice; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.animation.DialogLaunchAnimator; import com.android.systemui.broadcast.BroadcastSender; Loading Loading @@ -82,6 +86,8 @@ public class MediaOutputDialogTest extends SysuiTestCase { private final CommonNotifCollection mNotifCollection = mock(CommonNotifCollection.class); private final UiEventLogger mUiEventLogger = mock(UiEventLogger.class); private final DialogLaunchAnimator mDialogLaunchAnimator = mock(DialogLaunchAnimator.class); private final MediaMetadata mMediaMetadata = mock(MediaMetadata.class); private final MediaDescription mMediaDescription = mock(MediaDescription.class); private final NearbyMediaDevicesManager mNearbyMediaDevicesManager = mock( NearbyMediaDevicesManager.class); private final AudioManager mAudioManager = mock(AudioManager.class); Loading @@ -100,6 +106,8 @@ public class MediaOutputDialogTest extends SysuiTestCase { when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState); when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_NONE); when(mMediaController.getPackageName()).thenReturn(TEST_PACKAGE); when(mMediaController.getMetadata()).thenReturn(mMediaMetadata); when(mMediaMetadata.getDescription()).thenReturn(mMediaDescription); mMediaControllers.add(mMediaController); when(mMediaSessionManager.getActiveSessions(any())).thenReturn(mMediaControllers); Loading Loading @@ -206,6 +214,80 @@ public class MediaOutputDialogTest extends SysuiTestCase { assertThat(mMediaOutputDialog.getBroadcastIconVisibility()).isEqualTo(View.GONE); } @Test public void getHeaderIcon_getFromMediaControllerMetaData() { int testWidth = 10; int testHeight = 20; when(mMediaDescription.getIconBitmap()) .thenReturn(Bitmap.createBitmap(testWidth, testHeight, Bitmap.Config.ARGB_8888)); assertThat(mMediaOutputDialog.getHeaderIcon().getBitmap().getHeight()).isEqualTo( testHeight); assertThat(mMediaOutputDialog.getHeaderIcon().getBitmap().getWidth()).isEqualTo(testWidth); } @Test public void getHeaderText_getFromMediaControllerMetaData() { String testTitle = "test title"; when(mMediaDescription.getTitle()) .thenReturn(testTitle); assertThat(mMediaOutputDialog.getHeaderText().toString()).isEqualTo(testTitle); } @Test public void getHeaderSubtitle_getFromMediaControllerMetaData() { String testSubtitle = "test title"; when(mMediaDescription.getSubtitle()) .thenReturn(testSubtitle); assertThat(mMediaOutputDialog.getHeaderSubtitle().toString()).isEqualTo(testSubtitle); } @Test public void getStopButtonText_notSupportsBroadcast_returnsDefaultText() { String stopText = mContext.getText(R.string.keyboard_key_media_stop).toString(); MediaOutputController mockMediaOutputController = mock(MediaOutputController.class); when(mockMediaOutputController.isBroadcastSupported()).thenReturn(false); MediaOutputDialog testDialog = new MediaOutputDialog(mContext, false, mBroadcastSender, mockMediaOutputController, mUiEventLogger); testDialog.show(); assertThat(testDialog.getStopButtonText().toString()).isEqualTo(stopText); } @Test public void getStopButtonText_supportsBroadcast_returnsBroadcastText() { String stopText = mContext.getText(R.string.media_output_broadcast).toString(); MediaDevice mMediaDevice = mock(MediaDevice.class); MediaOutputController mockMediaOutputController = mock(MediaOutputController.class); when(mockMediaOutputController.isBroadcastSupported()).thenReturn(true); when(mockMediaOutputController.getCurrentConnectedMediaDevice()).thenReturn(mMediaDevice); when(mockMediaOutputController.isBluetoothLeDevice(any())).thenReturn(true); when(mockMediaOutputController.isPlaying()).thenReturn(true); when(mockMediaOutputController.isBluetoothLeBroadcastEnabled()).thenReturn(false); MediaOutputDialog testDialog = new MediaOutputDialog(mContext, false, mBroadcastSender, mockMediaOutputController, mUiEventLogger); testDialog.show(); assertThat(testDialog.getStopButtonText().toString()).isEqualTo(stopText); } @Test public void onStopButtonClick_notPlaying_releaseSession() { MediaOutputController mockMediaOutputController = mock(MediaOutputController.class); when(mockMediaOutputController.isBroadcastSupported()).thenReturn(false); when(mockMediaOutputController.getCurrentConnectedMediaDevice()).thenReturn(null); when(mockMediaOutputController.isPlaying()).thenReturn(false); MediaOutputDialog testDialog = new MediaOutputDialog(mContext, false, mBroadcastSender, mockMediaOutputController, mUiEventLogger); testDialog.show(); testDialog.onStopButtonClick(); verify(mockMediaOutputController).releaseSession(); } @Test // Check the visibility metric logging by creating a new MediaOutput dialog, // and verify if the calling times increases. Loading