Add remote volume slider conditionally.

Issue before this CL:
RemoteVolumePreferenceController only return available when
it is casting, otherwise return CONDITIONALLY_UNAVAILABLE.
However slice database only index available controllers and keep
this cache. So remote slider won't be indexed if it is not casting
at that time.

As a tmp fix, this CL make controller always return available
unsearchable to make it indexed by database. However only add
that slice if it is casting.

Bug: 130124950
Test: RunSettingsRoboTests
Change-Id: I191144844d6ba7ccbe3dc1c9d19801adb978abc6
This commit is contained in:
Lei Yu
2019-04-12 14:23:33 -07:00
parent fd3cf32ad8
commit c1dbd34b9d
3 changed files with 36 additions and 13 deletions

View File

@@ -29,10 +29,12 @@ import android.media.session.MediaSession;
import android.media.session.MediaSessionManager;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -50,9 +52,9 @@ public class RemoteVolumePreferenceControllerTest {
private MediaSessionManager mMediaSessionManager;
@Mock
private MediaController mMediaController;
@Mock
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ISessionController mStub;
@Mock
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ISessionController mStub2;
private MediaSession.Token mToken;
private MediaSession.Token mToken2;
@@ -78,22 +80,30 @@ public class RemoteVolumePreferenceControllerTest {
mPlaybackInfo = new MediaController.PlaybackInfo(
MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE, 0, MAX_POS, CURRENT_POS, null);
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getSessionToken()).thenReturn(mToken);
}
@Test
public void isAvailable_containRemoteMedia_returnTrue() {
public void getActiveRemoteToken_containRemoteMedia_returnToken() {
when(mMediaController.getPlaybackInfo()).thenReturn(
new MediaController.PlaybackInfo(MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE,
0, 0, 0, null));
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.getActiveRemoteToken(mContext)).isEqualTo(mToken);
}
@Test
public void isAvailable_noRemoteMedia_returnFalse() {
public void getActiveRemoteToken_noRemoteMedia_returnNull() {
when(mMediaController.getPlaybackInfo()).thenReturn(
new MediaController.PlaybackInfo(MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
0, 0, 0, null));
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getActiveRemoteToken(mContext)).isNull();
}
@Test
public void isAvailable_returnAvailableUnsearchable() {
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
}
@Test