Fix output switcher will show 2 media sessions in some use cases
Before this CL, we didn't check whether the remote session existed
in the list before. If the priority of a remote session is higher than
a local session, it causes us to return the local session even if
the list has a remote session.
This CL uses a list to cache package names of remote sessions.
If the local session has the same package name of the remote session
then don't return the local session.
Bug: 169052790
Test: make -j42 RunSettingsRoboTests
Change-Id: I2726a3deb397f646e4c74a8c445dde6fafb694a8
Merged-In: I2726a3deb397f646e4c74a8c445dde6fafb694a8
(cherry picked from commit 3a7293cbbf
)
This commit is contained in:
@@ -25,6 +25,9 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.sound.MediaOutputPreferenceController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utilities that can be shared between {@link MediaOutputIndicatorWorker} and
|
||||
* {@link MediaOutputPreferenceController}.
|
||||
@@ -43,6 +46,7 @@ public class MediaOutputUtils {
|
||||
MediaSessionManager mediaSessionManager) {
|
||||
|
||||
MediaController localController = null;
|
||||
final List<String> remoteMediaSessionLists = new ArrayList<>();
|
||||
for (MediaController controller : mediaSessionManager.getActiveSessions(null)) {
|
||||
final MediaController.PlaybackInfo pi = controller.getPlaybackInfo();
|
||||
if (pi == null) {
|
||||
@@ -69,10 +73,14 @@ public class MediaOutputUtils {
|
||||
controller.getPackageName())) {
|
||||
localController = null;
|
||||
}
|
||||
if (!remoteMediaSessionLists.contains(controller.getPackageName())) {
|
||||
remoteMediaSessionLists.add(controller.getPackageName());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (pi.getPlaybackType() == MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL) {
|
||||
if (localController == null) {
|
||||
if (localController == null
|
||||
&& !remoteMediaSessionLists.contains(controller.getPackageName())) {
|
||||
localController = controller;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user