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

@@ -43,7 +43,6 @@ public class RemoteVolumePreferenceController extends VolumeSeekBarPreferenceCon
@VisibleForTesting
static final int REMOTE_VOLUME = 100;
private MediaSessionManager mMediaSessionManager;
private MediaSessions mMediaSessions;
@VisibleForTesting
MediaSession.Token mActiveToken;
@@ -86,28 +85,39 @@ public class RemoteVolumePreferenceController extends VolumeSeekBarPreferenceCon
public RemoteVolumePreferenceController(Context context) {
super(context, KEY_REMOTE_VOLUME);
mMediaSessionManager = context.getSystemService(MediaSessionManager.class);
mMediaSessions = new MediaSessions(context, Looper.getMainLooper(), mCallbacks);
updateToken(getActiveRemoteToken(mContext));
}
@Override
public int getAvailabilityStatus() {
final List<MediaController> controllers = mMediaSessionManager.getActiveSessions(null);
// Always return true to make it indexed in database
return AVAILABLE_UNSEARCHABLE;
}
/**
* Return {@link android.media.session.MediaSession.Token} for active remote token, or
* {@code null} if there is no active remote token.
*/
public static MediaSession.Token getActiveRemoteToken(Context context) {
final MediaSessionManager sessionManager = context.getSystemService(
MediaSessionManager.class);
final List<MediaController> controllers = sessionManager.getActiveSessions(null);
for (MediaController mediaController : controllers) {
final MediaController.PlaybackInfo pi = mediaController.getPlaybackInfo();
if (isRemote(pi)) {
updateToken(mediaController.getSessionToken());
return AVAILABLE;
return mediaController.getSessionToken();
}
}
// No active remote media at this point
return CONDITIONALLY_UNAVAILABLE;
return null;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference.setVisible(mActiveToken != null);
if (mMediaController != null) {
updatePreference(mPreference, mActiveToken, mMediaController.getPlaybackInfo());
}