Fix output switcher will show 2 media session when remote playing

Before this CL, output switcher will show 2 media sessions when
some apps are remote playing. The root cause is some apps will
also create local media sessions when they cast media to remote
playing.

This CL add condition to only show remote sessions on output switcher
if apps both have remote and local sessions.

Bug: 169052790
Test: make -j42 RunSettingsRoboTests
Change-Id: I80479d35b2bb2e353cf41f41f457f2dfd15cadbf
This commit is contained in:
Hugh Chen
2020-10-07 15:55:51 +08:00
parent 79dc82fb6f
commit e16a8077b5
6 changed files with 274 additions and 44 deletions

View File

@@ -25,7 +25,6 @@ import android.content.IntentFilter;
import android.media.AudioManager;
import android.media.session.MediaController;
import android.media.session.MediaSessionManager;
import android.media.session.PlaybackState;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
@@ -53,6 +52,7 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
LocalMediaManager.DeviceCallback {
private static final String TAG = "MediaOutputIndWorker";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private final DevicesChangedBroadcastReceiver mReceiver;
private final Context mContext;
@@ -127,24 +127,8 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
@Nullable
MediaController getActiveLocalMediaController() {
final MediaSessionManager mMediaSessionManager = mContext.getSystemService(
MediaSessionManager.class);
for (MediaController controller : mMediaSessionManager.getActiveSessions(null)) {
final MediaController.PlaybackInfo pi = controller.getPlaybackInfo();
if (pi == null) {
return null;
}
final PlaybackState playbackState = controller.getPlaybackState();
if (playbackState == null) {
return null;
}
if (pi.getPlaybackType() == MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL
&& playbackState.getState() == PlaybackState.STATE_PLAYING) {
return controller;
}
}
return null;
return MediaOutputUtils.getActiveLocalMediaController(mContext.getSystemService(
MediaSessionManager.class));
}
@Override