diff options
| author | 2024-02-14 10:04:48 +0000 | |
|---|---|---|
| committer | 2024-02-14 10:04:48 +0000 | |
| commit | e48ea8e75a955e322ef8993edd0dcfaf4eb58331 (patch) | |
| tree | cfaf39539b3e21e96f81824949e8209468f95df7 | |
| parent | c4ce460e59eba7462887425881ce25c87f0e1299 (diff) | |
| parent | 9b1b98e9dd25cbcfa31c007d70de8b1a51f7e4a4 (diff) | |
Merge "Add package name to LocalRouter#getSystemSessionInfo" into main
| -rw-r--r-- | media/java/android/media/MediaRouter2.java | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java index 7fa3ed654ebc..144b01a438a2 100644 --- a/media/java/android/media/MediaRouter2.java +++ b/media/java/android/media/MediaRouter2.java @@ -1017,7 +1017,8 @@ public final class MediaRouter2 { updateRoutesOnHandler(currentRoutes); RoutingSessionInfo oldInfo = mSystemController.getRoutingSessionInfo(); - mSystemController.setRoutingSessionInfo(currentSystemSessionInfo); + mSystemController.setRoutingSessionInfo(ensureClientPackageNameForSystemSession( + currentSystemSessionInfo, mContext.getPackageName())); if (!oldInfo.equals(currentSystemSessionInfo)) { notifyControllerUpdated(mSystemController); } @@ -1440,6 +1441,25 @@ public final class MediaRouter2 { } } + /** + * Sets the routing session's {@linkplain RoutingSessionInfo#getClientPackageName() client + * package name} to {@code packageName} if empty and returns the session. + * + * <p>This method must only be used for {@linkplain RoutingSessionInfo#isSystemSession() + * system routing sessions}. + */ + private static RoutingSessionInfo ensureClientPackageNameForSystemSession( + @NonNull RoutingSessionInfo sessionInfo, @NonNull String packageName) { + if (!sessionInfo.isSystemSession() + || !TextUtils.isEmpty(sessionInfo.getClientPackageName())) { + return sessionInfo; + } + + return new RoutingSessionInfo.Builder(sessionInfo) + .setClientPackageName(packageName) + .build(); + } + /** Callback for receiving events about media route discovery. */ public abstract static class RouteCallback { /** @@ -2891,25 +2911,6 @@ public final class MediaRouter2 { } /** - * Sets the routing session's {@linkplain RoutingSessionInfo#getClientPackageName() client - * package name} to {@link #mClientPackageName} if empty and returns the session. - * - * <p>This method must only be used for {@linkplain RoutingSessionInfo#isSystemSession() - * system routing sessions}. - */ - private RoutingSessionInfo ensureClientPackageNameForSystemSession( - RoutingSessionInfo sessionInfo) { - if (!sessionInfo.isSystemSession() - || !TextUtils.isEmpty(sessionInfo.getClientPackageName())) { - return sessionInfo; - } - - return new RoutingSessionInfo.Builder(sessionInfo) - .setClientPackageName(mClientPackageName) - .build(); - } - - /** * Requests the release of a {@linkplain RoutingSessionInfo routing session}. Calls {@link * #onSessionReleasedOnHandler(RoutingSessionInfo)} on success. * @@ -2997,7 +2998,7 @@ public final class MediaRouter2 { RoutingController oldController; if (oldSession.isSystemSession()) { mSystemController.setRoutingSessionInfo( - ensureClientPackageNameForSystemSession(oldSession)); + ensureClientPackageNameForSystemSession(oldSession, mClientPackageName)); oldController = mSystemController; } else { oldController = new RoutingController(oldSession); @@ -3006,7 +3007,7 @@ public final class MediaRouter2 { RoutingController newController; if (newSession.isSystemSession()) { mSystemController.setRoutingSessionInfo( - ensureClientPackageNameForSystemSession(newSession)); + ensureClientPackageNameForSystemSession(newSession, mClientPackageName)); newController = mSystemController; } else { newController = new RoutingController(newSession); @@ -3033,7 +3034,7 @@ public final class MediaRouter2 { RoutingController controller; if (session.isSystemSession()) { mSystemController.setRoutingSessionInfo( - ensureClientPackageNameForSystemSession(session)); + ensureClientPackageNameForSystemSession(session, mClientPackageName)); controller = mSystemController; } else { controller = new RoutingController(session); @@ -3303,7 +3304,8 @@ public final class MediaRouter2 { public RoutingSessionInfo getSystemSessionInfo() { RoutingSessionInfo currentSystemSessionInfo = null; try { - currentSystemSessionInfo = mMediaRouterService.getSystemSessionInfo(); + currentSystemSessionInfo = ensureClientPackageNameForSystemSession( + mMediaRouterService.getSystemSessionInfo(), mContext.getPackageName()); } catch (RemoteException ex) { ex.rethrowFromSystemServer(); } |