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
Merged-In: I80479d35b2bb2e353cf41f41f457f2dfd15cadbf
(cherry picked from commit e16a8077b5)
This commit is contained in:
@@ -22,14 +22,13 @@ import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.session.MediaController;
|
||||
import android.media.session.MediaSessionManager;
|
||||
import android.media.session.PlaybackState;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.media.MediaOutputUtils;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||
@@ -51,7 +50,8 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
||||
|
||||
public MediaOutputPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mMediaController = getActiveLocalMediaController();
|
||||
mMediaController = MediaOutputUtils.getActiveLocalMediaController(context.getSystemService(
|
||||
MediaSessionManager.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,26 +141,4 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user