Merge "Modify rule of remote media session UI" into rvc-dev

This commit is contained in:
tim peng
2020-05-04 08:47:41 +00:00
committed by Android (Google) Code Review
6 changed files with 137 additions and 123 deletions

View File

@@ -31,6 +31,7 @@ import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaRoute2ProviderService;
import android.media.RoutingSessionInfo;
import android.net.Uri;
import com.android.settings.testutils.shadow.ShadowAudioManager;
@@ -191,4 +192,21 @@ public class MediaDeviceUpdateWorkerTest {
verify(mResolver, never()).notifyChange(URI, null);
}
@Test
public void getActiveRemoteMediaSession_verifyList() {
mMediaDeviceUpdateWorker.mLocalMediaManager = mock(LocalMediaManager.class);
final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>();
final RoutingSessionInfo remoteSessionInfo = mock(RoutingSessionInfo.class);
final RoutingSessionInfo localSessionInfo = mock(RoutingSessionInfo.class);
when(remoteSessionInfo.isSystemSession()).thenReturn(false);
when(localSessionInfo.isSystemSession()).thenReturn(true);
routingSessionInfos.add(remoteSessionInfo);
routingSessionInfos.add(localSessionInfo);
when(mMediaDeviceUpdateWorker.mLocalMediaManager.getActiveMediaSession()).thenReturn(
routingSessionInfos);
assertThat(mMediaDeviceUpdateWorker.getActiveRemoteMediaDevice()).containsExactly(
remoteSessionInfo);
}
}

View File

@@ -24,7 +24,7 @@ import static com.android.settings.slices.CustomSliceRegistry.REMOTE_MEDIA_SLICE
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.media.RoutingSessionInfo;
import android.net.Uri;
import androidx.slice.Slice;
@@ -43,7 +44,6 @@ import androidx.slice.widget.SliceLiveData;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settingslib.media.LocalMediaManager;
import com.android.settingslib.media.MediaDevice;
import org.junit.Before;
import org.junit.Test;
@@ -64,19 +64,16 @@ import java.util.List;
public class RemoteMediaSliceTest {
private static final String MEDIA_ID = "media_id";
private static final String TEST_PACKAGE_LABEL = "music";
private static final String TEST_DEVICE_1_ID = "test_device_1_id";
private static final String TEST_DEVICE_1_NAME = "test_device_1_name";
private static final String TEST_SESSION_1_ID = "test_session_1_id";
private static final String TEST_SESSION_1_NAME = "test_session_1_name";
private static final int TEST_VOLUME = 3;
private static MediaDeviceUpdateWorker sMediaDeviceUpdateWorker;
@Mock
private LocalMediaManager mLocalMediaManager;
@Mock
private MediaDevice mDevice;
private final List<MediaDevice> mDevices = new ArrayList<>();
private final List<RoutingSessionInfo> mRoutingSessionInfos = new ArrayList<>();
private Context mContext;
private RemoteMediaSlice mRemoteMediaSlice;
@@ -93,44 +90,42 @@ public class RemoteMediaSliceTest {
sMediaDeviceUpdateWorker = spy(new MediaDeviceUpdateWorker(mContext,
REMOTE_MEDIA_SLICE_URI));
sMediaDeviceUpdateWorker.mLocalMediaManager = mLocalMediaManager;
when(sMediaDeviceUpdateWorker.getActiveMediaDevice(
MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE)).thenReturn(mDevices);
when(mDevice.getId()).thenReturn(TEST_DEVICE_1_ID);
when(mDevice.getName()).thenReturn(TEST_DEVICE_1_NAME);
when(mDevice.getMaxVolume()).thenReturn(100);
when(mDevice.getCurrentVolume()).thenReturn(10);
when(mDevice.getClientAppLabel()).thenReturn(TEST_PACKAGE_LABEL);
final RoutingSessionInfo remoteSessionInfo = mock(RoutingSessionInfo.class);
when(remoteSessionInfo.getId()).thenReturn(TEST_SESSION_1_ID);
when(remoteSessionInfo.getName()).thenReturn(TEST_SESSION_1_NAME);
when(remoteSessionInfo.getVolumeMax()).thenReturn(100);
when(remoteSessionInfo.getVolume()).thenReturn(10);
when(remoteSessionInfo.isSystemSession()).thenReturn(false);
mRoutingSessionInfos.add(remoteSessionInfo);
when(sMediaDeviceUpdateWorker.getActiveRemoteMediaDevice()).thenReturn(
mRoutingSessionInfos);
}
@Test
public void onNotifyChange_noId_doNothing() {
mDevices.add(mDevice);
when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(mDevice);
sMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
final Intent intent = new Intent();
intent.putExtra(EXTRA_RANGE_VALUE, TEST_VOLUME);
mRemoteMediaSlice.onNotifyChange(intent);
verify(mDevice, never()).requestSetVolume(anyInt());
verify(sMediaDeviceUpdateWorker, never())
.adjustSessionVolume(TEST_SESSION_1_ID, TEST_VOLUME);
}
@Test
public void onNotifyChange_verifyAdjustVolume() {
mDevices.add(mDevice);
when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(mDevice);
sMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
final Intent intent = new Intent();
intent.putExtra(MEDIA_ID, TEST_DEVICE_1_ID);
intent.putExtra(MEDIA_ID, TEST_SESSION_1_ID);
intent.putExtra(EXTRA_RANGE_VALUE, TEST_VOLUME);
mRemoteMediaSlice.onNotifyChange(intent);
verify(mDevice).requestSetVolume(TEST_VOLUME);
verify(sMediaDeviceUpdateWorker).adjustSessionVolume(TEST_SESSION_1_ID, TEST_VOLUME);
}
@Test
public void getSlice_noActiveDevice_checkRowNumber() {
public void getSlice_noActiveSession_checkRowNumber() {
mRoutingSessionInfos.clear();
final Slice slice = mRemoteMediaSlice.getSlice();
final int rows = SliceQuery.findAll(slice, FORMAT_SLICE, HINT_LIST_ITEM, null).size();
@@ -138,8 +133,7 @@ public class RemoteMediaSliceTest {
}
@Test
public void getSlice_withActiveDevice_checkRowNumber() {
mDevices.add(mDevice);
public void getSlice_withActiveSession_checkRowNumber() {
final Slice slice = mRemoteMediaSlice.getSlice();
final int rows = SliceQuery.findAll(slice, FORMAT_SLICE, HINT_LIST_ITEM, null).size();
@@ -148,15 +142,13 @@ public class RemoteMediaSliceTest {
}
@Test
public void getSlice_withActiveDevice_checkTitle() {
mDevices.add(mDevice);
public void getSlice_withActiveSession_checkTitle() {
final Slice slice = mRemoteMediaSlice.getSlice();
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
final SliceAction primaryAction = metadata.getPrimaryAction();
assertThat(primaryAction.getTitle().toString()).isEqualTo(mContext.getText(
com.android.settings.R.string.remote_media_volume_option_title)
+ " (" + TEST_PACKAGE_LABEL + ")");
com.android.settings.R.string.remote_media_volume_option_title));
}
@Implements(SliceBackgroundWorker.class)

View File

@@ -21,11 +21,13 @@ import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_U
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.RoutingSessionInfo;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
@@ -36,7 +38,6 @@ import com.android.settings.R;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.media.LocalMediaManager;
import com.android.settingslib.media.MediaDevice;
import org.junit.Before;
import org.junit.Test;
@@ -55,24 +56,21 @@ import java.util.List;
public class RemoteVolumeGroupControllerTest {
private static final String KEY_REMOTE_VOLUME_GROUP = "remote_media_group";
private static final String TEST_PACKAGE_LABEL = "music";
private static final String TEST_DEVICE_1_ID = "test_device_1_id";
private static final String TEST_DEVICE_1_NAME = "test_device_1_name";
private static final String TEST_SESSION_1_ID = "test_session_1_id";
private static final String TEST_SESSION_1_NAME = "test_session_1_name";
private static final int CURRENT_VOLUME = 30;
private static final int MAX_VOLUME = 100;
@Mock
private LocalMediaManager mLocalMediaManager;
@Mock
private MediaDevice mDevice;
@Mock
private PreferenceScreen mScreen;
@Mock
private PreferenceManager mPreferenceManager;
@Mock
private SharedPreferences mSharedPreferences;
private final List<MediaDevice> mDevices = new ArrayList<>();
private final List<RoutingSessionInfo> mRoutingSessionInfos = new ArrayList<>();
private Context mContext;
private RemoteVolumeGroupController mController;
@@ -89,92 +87,88 @@ public class RemoteVolumeGroupControllerTest {
when(mPreferenceCategory.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mPreferenceManager.getSharedPreferences()).thenReturn(mSharedPreferences);
when(mLocalMediaManager.getActiveMediaDevice(
MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE)).thenReturn(mDevices);
when(mDevice.getId()).thenReturn(TEST_DEVICE_1_ID);
when(mDevice.getName()).thenReturn(TEST_DEVICE_1_NAME);
when(mDevice.getMaxVolume()).thenReturn(MAX_VOLUME);
when(mDevice.getCurrentVolume()).thenReturn(CURRENT_VOLUME);
when(mDevice.getClientAppLabel()).thenReturn(TEST_PACKAGE_LABEL);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(
mPreferenceCategory);
final RoutingSessionInfo remoteSessionInfo = mock(RoutingSessionInfo.class);
when(remoteSessionInfo.getId()).thenReturn(TEST_SESSION_1_ID);
when(remoteSessionInfo.getName()).thenReturn(TEST_SESSION_1_NAME);
when(remoteSessionInfo.getVolumeMax()).thenReturn(MAX_VOLUME);
when(remoteSessionInfo.getVolume()).thenReturn(CURRENT_VOLUME);
when(remoteSessionInfo.isSystemSession()).thenReturn(false);
mRoutingSessionInfos.add(remoteSessionInfo);
when(mLocalMediaManager.getActiveMediaSession()).thenReturn(mRoutingSessionInfos);
}
@Test
public void getAvailabilityStatus_withActiveDevice_returnAvailableUnsearchable() {
mDevices.add(mDevice);
public void getAvailabilityStatus_withActiveSession_returnAvailableUnsearchable() {
mController.displayPreference(mScreen);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test
public void getAvailabilityStatus_noActiveDevice_returnConditionallyUnavailable() {
public void getAvailabilityStatus_noActiveSession_returnConditionallyUnavailable() {
mRoutingSessionInfos.clear();
mController.displayPreference(mScreen);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
public void displayPreference_noActiveDevice_checkPreferenceCount() {
public void displayPreference_noActiveSession_checkPreferenceCount() {
mRoutingSessionInfos.clear();
mController.displayPreference(mScreen);
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(0);
}
@Test
public void displayPreference_withActiveDevice_checkPreferenceCount() {
mDevices.add(mDevice);
public void displayPreference_withActiveSession_checkPreferenceCount() {
mController.displayPreference(mScreen);
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2);
}
@Test
public void displayPreference_withActiveDevice_checkSeekBarTitle() {
mDevices.add(mDevice);
public void displayPreference_withActiveSession_checkSeekBarTitle() {
mController.displayPreference(mScreen);
final Preference preference = mPreferenceCategory.findPreference(TEST_DEVICE_1_ID);
final Preference preference = mPreferenceCategory.findPreference(TEST_SESSION_1_ID);
assertThat(preference.getTitle()).isEqualTo(mContext.getText(
R.string.remote_media_volume_option_title) + " (" + TEST_PACKAGE_LABEL + ")");
R.string.remote_media_volume_option_title));
}
@Test
public void displayPreference_withActiveDevice_checkSeekBarMaxVolume() {
mDevices.add(mDevice);
public void displayPreference_withActiveSession_checkSeekBarMaxVolume() {
mController.displayPreference(mScreen);
final SeekBarPreference preference = mPreferenceCategory.findPreference(TEST_DEVICE_1_ID);
final SeekBarPreference preference = mPreferenceCategory.findPreference(TEST_SESSION_1_ID);
assertThat(preference.getMax()).isEqualTo(MAX_VOLUME);
}
@Test
public void displayPreference_withActiveDevice_checkSeekBarCurrentVolume() {
mDevices.add(mDevice);
public void displayPreference_withActiveSession_checkSeekBarCurrentVolume() {
mController.displayPreference(mScreen);
final SeekBarPreference preference = mPreferenceCategory.findPreference(TEST_DEVICE_1_ID);
final SeekBarPreference preference = mPreferenceCategory.findPreference(TEST_SESSION_1_ID);
assertThat(preference.getProgress()).isEqualTo(CURRENT_VOLUME);
}
@Test
public void displayPreference_withActiveDevice_checkSwitcherPreferenceTitle() {
mDevices.add(mDevice);
public void displayPreference_withActiveSession_checkSwitcherPreferenceTitle() {
mController.displayPreference(mScreen);
final Preference preference = mPreferenceCategory.findPreference(
RemoteVolumeGroupController.SWITCHER_PREFIX + TEST_DEVICE_1_ID);
RemoteVolumeGroupController.SWITCHER_PREFIX + TEST_SESSION_1_ID);
assertThat(preference.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title));
}
@Test
public void displayPreference_withActiveDevice_checkSwitcherPreferenceSummary() {
mDevices.add(mDevice);
public void displayPreference_withActiveSession_checkSwitcherPreferenceSummary() {
mController.displayPreference(mScreen);
final Preference preference = mPreferenceCategory.findPreference(
RemoteVolumeGroupController.SWITCHER_PREFIX + TEST_DEVICE_1_ID);
RemoteVolumeGroupController.SWITCHER_PREFIX + TEST_SESSION_1_ID);
assertThat(preference.getSummary()).isEqualTo(TEST_DEVICE_1_NAME);
assertThat(preference.getSummary()).isEqualTo(TEST_SESSION_1_NAME);
}
}