Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b1b98e9 authored by Alex Dadukin's avatar Alex Dadukin
Browse files

Add package name to LocalRouter#getSystemSessionInfo

Test: atest MediaRouter2Test SystemMediaRouter2Test
Bug: b/324359100
Change-Id: I47522397fb1885d94b833892de344f26fe7181ba
parent 70eb6511
Loading
Loading
Loading
Loading
+26 −24
Original line number Diff line number Diff line
@@ -868,7 +868,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);
        }
@@ -1291,6 +1292,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 {
        /**
@@ -2658,25 +2678,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.
@@ -2765,7 +2766,7 @@ public final class MediaRouter2 {
            RoutingController oldController;
            if (oldSession.isSystemSession()) {
                mSystemController.setRoutingSessionInfo(
                        ensureClientPackageNameForSystemSession(oldSession));
                        ensureClientPackageNameForSystemSession(oldSession, mClientPackageName));
                oldController = mSystemController;
            } else {
                oldController = new RoutingController(oldSession);
@@ -2774,7 +2775,7 @@ public final class MediaRouter2 {
            RoutingController newController;
            if (newSession.isSystemSession()) {
                mSystemController.setRoutingSessionInfo(
                        ensureClientPackageNameForSystemSession(newSession));
                        ensureClientPackageNameForSystemSession(newSession, mClientPackageName));
                newController = mSystemController;
            } else {
                newController = new RoutingController(newSession);
@@ -2801,7 +2802,7 @@ public final class MediaRouter2 {
            RoutingController controller;
            if (session.isSystemSession()) {
                mSystemController.setRoutingSessionInfo(
                        ensureClientPackageNameForSystemSession(session));
                        ensureClientPackageNameForSystemSession(session, mClientPackageName));
                controller = mSystemController;
            } else {
                controller = new RoutingController(session);
@@ -3059,7 +3060,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();
            }