summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--media/java/android/media/MediaRouter2.java36
1 files changed, 22 insertions, 14 deletions
diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java
index 5e235515c852..89792c7638cb 100644
--- a/media/java/android/media/MediaRouter2.java
+++ b/media/java/android/media/MediaRouter2.java
@@ -18,8 +18,8 @@ package android.media;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import static com.android.media.flags.Flags.FLAG_ENABLE_BUILT_IN_SPEAKER_ROUTE_SUITABILITY_STATUSES;
-import static com.android.media.flags.Flags.FLAG_ENABLE_RLP_CALLBACKS_IN_MEDIA_ROUTER2;
import static com.android.media.flags.Flags.FLAG_ENABLE_CROSS_USER_ROUTING_IN_MEDIA_ROUTER2;
+import static com.android.media.flags.Flags.FLAG_ENABLE_RLP_CALLBACKS_IN_MEDIA_ROUTER2;
import android.Manifest;
import android.annotation.CallbackExecutor;
@@ -344,25 +344,13 @@ public final class MediaRouter2 {
mImpl = new LocalMediaRouter2Impl(mContext.getPackageName());
mHandler = new Handler(Looper.getMainLooper());
- List<MediaRoute2Info> currentSystemRoutes = null;
- try {
- currentSystemRoutes = mMediaRouterService.getSystemRoutes();
- } catch (RemoteException ex) {
- ex.rethrowFromSystemServer();
- }
-
- if (currentSystemRoutes == null || currentSystemRoutes.isEmpty()) {
- throw new RuntimeException("Null or empty currentSystemRoutes. Something is wrong.");
- }
+ loadSystemRoutes();
RoutingSessionInfo currentSystemSessionInfo = mImpl.getSystemSessionInfo();
if (currentSystemSessionInfo == null) {
throw new RuntimeException("Null currentSystemSessionInfo. Something is wrong.");
}
- for (MediaRoute2Info route : currentSystemRoutes) {
- mRoutes.put(route.getId(), route);
- }
mSystemController = new SystemRoutingController(currentSystemSessionInfo);
}
@@ -374,6 +362,8 @@ public final class MediaRouter2 {
IMediaRouterService.Stub.asInterface(
ServiceManager.getService(Context.MEDIA_ROUTER_SERVICE));
+ loadSystemRoutes();
+
mSystemController =
new SystemRoutingController(
ProxyMediaRouter2Impl.getSystemSessionInfoImpl(
@@ -381,6 +371,24 @@ public final class MediaRouter2 {
mImpl = new ProxyMediaRouter2Impl(context, clientPackageName, user);
}
+ @GuardedBy("mLock")
+ private void loadSystemRoutes() {
+ List<MediaRoute2Info> currentSystemRoutes = null;
+ try {
+ currentSystemRoutes = mMediaRouterService.getSystemRoutes();
+ } catch (RemoteException ex) {
+ ex.rethrowFromSystemServer();
+ }
+
+ if (currentSystemRoutes == null || currentSystemRoutes.isEmpty()) {
+ throw new RuntimeException("Null or empty currentSystemRoutes. Something is wrong.");
+ }
+
+ for (MediaRoute2Info route : currentSystemRoutes) {
+ mRoutes.put(route.getId(), route);
+ }
+ }
+
/**
* Gets the client package name of the app which this media router controls.
*