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

@@ -30,6 +30,7 @@ import android.net.Uri;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -51,6 +52,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
implements LocalMediaManager.DeviceCallback {
private static final String TAG = "MediaDeviceUpdateWorker";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
protected final Context mContext;
protected final Collection<MediaDevice> mMediaDevices = new CopyOnWriteArrayList<>();
private final DevicesChangedBroadcastReceiver mReceiver;
@@ -213,6 +217,10 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
final List<RoutingSessionInfo> sessionInfos = new ArrayList<>();
for (RoutingSessionInfo info : mLocalMediaManager.getActiveMediaSession()) {
if (!info.isSystemSession()) {
if (DEBUG) {
Log.d(TAG, "getActiveRemoteMediaDevice() info : " + info.toString()
+ ", package name : " + info.getClientPackageName());
}
sessionInfos.add(info);
}
}