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

Commit 41165af8 authored by Iván Budnik's avatar Iván Budnik
Browse files

Initialize mSystemController before creating ProxyMediaRouter2Impl

This change removes the NPE that occurred when
ProxyMediaRouter2Impl started receiving updates from MR2ServiceImpl
before mSystemController was initialized. See the attached bug for
detailed information.

Bug: 302164392
Test: atest SystemMediaRouter2Test
Change-Id: I05459e6326949e97762419c00b72d7b254b4cef0
parent 0067d893
Loading
Loading
Loading
Loading
+22 −8
Original line number Diff line number Diff line
@@ -310,8 +310,11 @@ public final class MediaRouter2 {
                IMediaRouterService.Stub.asInterface(
                        ServiceManager.getService(Context.MEDIA_ROUTER_SERVICE));

        mSystemController =
                new SystemRoutingController(
                        ProxyMediaRouter2Impl.getSystemSessionInfoImpl(
                                mMediaRouterService, clientPackageName));
        mImpl = new ProxyMediaRouter2Impl(context, clientPackageName);
        mSystemController = new SystemRoutingController(mImpl.getSystemSessionInfo());
    }

    /**
@@ -2057,13 +2060,7 @@ public final class MediaRouter2 {

        @Override
        public RoutingSessionInfo getSystemSessionInfo() {
            RoutingSessionInfo result;
            try {
                result = mMediaRouterService.getSystemSessionInfoForPackage(mClientPackageName);
            } catch (RemoteException ex) {
                throw ex.rethrowFromSystemServer();
            }
            return ensureClientPackageNameForSystemSession(result);
            return getSystemSessionInfoImpl(mMediaRouterService, mClientPackageName);
        }

        /**
@@ -2427,6 +2424,23 @@ public final class MediaRouter2 {
            releaseSession(controller.getRoutingSessionInfo());
        }

        /**
         * Retrieves the system session info for the given package.
         *
         * <p>The returned routing session is guaranteed to have a non-null {@link
         * RoutingSessionInfo#getClientPackageName() client package name}.
         *
         * <p>Extracted into a static method to allow calling this from the constructor.
         */
        /* package */ static RoutingSessionInfo getSystemSessionInfoImpl(
                @NonNull IMediaRouterService service, @NonNull String clientPackageName) {
            try {
                return service.getSystemSessionInfoForPackage(clientPackageName);
            } catch (RemoteException ex) {
                throw ex.rethrowFromSystemServer();
            }
        }

        /**
         * Sets the routing session's {@linkplain RoutingSessionInfo#getClientPackageName() client
         * package name} to {@link #mClientPackageName} if empty and returns the session.