Add stop casting button for output switch

This CL add a customize button to stop casting when media
is transferred to info device.

This CL include following change:
- Add new methods to PanelContent.java. Let panels to
  customize "see more button".
- MediaOutputPanel will check which device is used to
  transfer media currently. The customize button will
  shown on when transfer device is info device.
  Then user can use this button to stop casting.
- Add test case.

Bug: 147856563
Test: make -j42 RunSettingsRoboTests
Change-Id: I8b201a10339f39f1d938d99b5659a82014e5bb89
This commit is contained in:
hughchen
2020-01-17 15:19:04 +08:00
parent 14b758f1c8
commit 201b48b885
6 changed files with 245 additions and 8 deletions

View File

@@ -21,7 +21,9 @@ import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -32,6 +34,9 @@ import android.net.Uri;
import com.android.settings.R;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settingslib.media.InfoMediaDevice;
import com.android.settingslib.media.LocalMediaManager;
import com.android.settingslib.media.PhoneMediaDevice;
import org.junit.Before;
import org.junit.Test;
@@ -58,6 +63,11 @@ public class MediaOutputPanelTest {
@Mock
private MediaMetadata mMediaMetadata;
@Mock
private LocalMediaManager mLocalMediaManager;
@Mock
private PanelCustomizedButtonCallback mCallback;
private MediaOutputPanel mPanel;
private Context mContext;
private List<MediaController> mMediaControllers = new ArrayList<>();
@@ -67,12 +77,16 @@ public class MediaOutputPanelTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mMediaControllers.add(mMediaController);
when(mMediaController.getPackageName()).thenReturn(TEST_PACKAGENAME);
when(mMediaSessionManager.getActiveSessions(any())).thenReturn(mMediaControllers);
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(MediaSessionManager.class)).thenReturn(mMediaSessionManager);
mPanel = MediaOutputPanel.create(mContext, TEST_PACKAGENAME);
mPanel.mLocalMediaManager = mLocalMediaManager;
mPanel.registerCallback(mCallback);
}
@Test
@@ -94,6 +108,63 @@ public class MediaOutputPanelTest {
assertThat(mPanel.getSeeMoreIntent()).isNull();
}
@Test
public void onStart_shouldRegisterCallback() {
mPanel.onStart();
verify(mLocalMediaManager).registerCallback(any());
verify(mLocalMediaManager).startScan();
}
@Test
public void onStop_shouldUnregisterCallback() {
mPanel.onStop();
verify(mLocalMediaManager).unregisterCallback(any());
verify(mLocalMediaManager).stopScan();
}
@Test
public void onSelectedDeviceStateChanged_shouldDispatchCustomButtonStateChanged() {
mPanel.onSelectedDeviceStateChanged(null, 0);
verify(mCallback).onCustomizedButtonStateChanged();
}
@Test
public void onDeviceListUpdate_shouldDispatchCustomButtonStateChanged() {
mPanel.onDeviceListUpdate(null);
verify(mCallback).onCustomizedButtonStateChanged();
}
@Test
public void onDeviceAttributesChanged_shouldDispatchCustomButtonStateChanged() {
mPanel.onDeviceAttributesChanged();
verify(mCallback).onCustomizedButtonStateChanged();
}
@Test
public void currentConnectDeviceIsInfoDevice_useCustomButtonIsTrue() {
final InfoMediaDevice infoMediaDevice = mock(InfoMediaDevice.class);
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(infoMediaDevice);
mPanel.onDeviceAttributesChanged();
assertThat(mPanel.isCustomizedButtonUsed()).isTrue();
}
@Test
public void currentConnectDeviceIsNotInfoDevice_useCustomButtonIsFalse() {
final PhoneMediaDevice phoneMediaDevice = mock(PhoneMediaDevice.class);
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(phoneMediaDevice);
mPanel.onDeviceAttributesChanged();
assertThat(mPanel.isCustomizedButtonUsed()).isFalse();
}
@Test
public void getTitle_withMetadata_returnArtistName() {
when(mMediaMetadata.getString(MediaMetadata.METADATA_KEY_ARTIST)).thenReturn(TEST_ARTIST);