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

Commit 0098d4f8 authored by Wenyu Zhang's avatar Wenyu Zhang
Browse files

Extract getSystemProvider method

No functional change. Prepare for introducing singleton system provider.

Change-Id: I27b41ec7eef634056b3523f5a8b12d80fffb2bd6
Bug: b/372868909
Test: Locally, presubmit
Flag: EXEMPT no functional change
parent 2462b4d1
Loading
Loading
Loading
Loading
+20 −14
Original line number Diff line number Diff line
@@ -2535,6 +2535,10 @@ class MediaRouter2ServiceImpl {

        private boolean mRunning;

        private SystemMediaRoute2Provider getSystemProvider() {
            return mSystemProvider;
        }

        // TODO: (In Android S+) Pull out SystemMediaRoute2Provider out of UserHandler.
        UserHandler(
                @NonNull MediaRouter2ServiceImpl service,
@@ -2549,19 +2553,19 @@ class MediaRouter2ServiceImpl {
                                    service.mContext, UserHandle.of(userRecord.mUserId), looper)
                            : new SystemMediaRoute2Provider(
                                    service.mContext, UserHandle.of(userRecord.mUserId), looper);
            mRouteProviders.add(mSystemProvider);
            mRouteProviders.add(getSystemProvider());
            mWatcher = new MediaRoute2ProviderWatcher(service.mContext, this,
                    this, mUserRecord.mUserId);
        }

        void init() {
            mSystemProvider.setCallback(this);
            getSystemProvider().setCallback(this);
        }

        private void start() {
            if (!mRunning) {
                mRunning = true;
                mSystemProvider.start();
                getSystemProvider().start();
                mWatcher.start();
            }
        }
@@ -2570,7 +2574,7 @@ class MediaRouter2ServiceImpl {
            if (mRunning) {
                mRunning = false;
                mWatcher.stop(); // also stops all providers
                mSystemProvider.stop();
                getSystemProvider().stop();
            }
        }

@@ -2662,7 +2666,7 @@ class MediaRouter2ServiceImpl {
            String indent = prefix + "  ";
            pw.println(indent + "mRunning=" + mRunning);

            mSystemProvider.dump(pw, prefix);
            getSystemProvider().dump(pw, prefix);
            mWatcher.dump(pw, prefix);
        }

@@ -2755,7 +2759,7 @@ class MediaRouter2ServiceImpl {
                    hasAddedOrModifiedRoutes,
                    hasRemovedRoutes,
                    provider.mIsSystemRouteProvider,
                    mSystemProvider.getDefaultRoute());
                    getSystemProvider().getDefaultRoute());
        }

        private static String getPackageNameFromNullableRecord(
@@ -2969,7 +2973,8 @@ class MediaRouter2ServiceImpl {
            }

            // Bypass checking router if it's the system session (routerRecord should be null)
            if (TextUtils.equals(getProviderId(uniqueSessionId), mSystemProvider.getUniqueId())) {
            if (TextUtils.equals(
                    getProviderId(uniqueSessionId), getSystemProvider().getUniqueId())) {
                return true;
            }

@@ -3100,7 +3105,7 @@ class MediaRouter2ServiceImpl {
                    && !matchingRequest.mRouterRecord.hasSystemRoutingPermission()) {
                // The router lacks permission to modify system routing, so we hide system routing
                // session info from them.
                sessionInfo = mSystemProvider.getDefaultSessionInfo();
                sessionInfo = getSystemProvider().getDefaultSessionInfo();
            }
            matchingRequest.mRouterRecord.notifySessionCreated(
                    toOriginalRequestId(uniqueRequestId), sessionInfo);
@@ -3114,13 +3119,13 @@ class MediaRouter2ServiceImpl {
            }

            // For system provider, notify all routers.
            if (provider == mSystemProvider) {
            if (provider == getSystemProvider()) {
                if (mServiceRef.get() == null) {
                    return;
                }
                notifySessionInfoChangedToRouters(getRouterRecords(true), sessionInfo);
                notifySessionInfoChangedToRouters(
                        getRouterRecords(false), mSystemProvider.getDefaultSessionInfo());
                        getRouterRecords(false), getSystemProvider().getDefaultSessionInfo());
                return;
            }

@@ -3256,7 +3261,8 @@ class MediaRouter2ServiceImpl {
            MediaRoute2ProviderInfo systemProviderInfo = null;
            for (MediaRoute2ProviderInfo providerInfo : mLastProviderInfos) {
                // TODO: Create MediaRoute2ProviderInfo#isSystemProvider()
                if (TextUtils.equals(providerInfo.getUniqueId(), mSystemProvider.getUniqueId())) {
                if (TextUtils.equals(
                        providerInfo.getUniqueId(), getSystemProvider().getUniqueId())) {
                    // Adding routes from system provider will be handled below, so skip it here.
                    systemProviderInfo = providerInfo;
                    continue;
@@ -3272,10 +3278,10 @@ class MediaRouter2ServiceImpl {
                    // This shouldn't happen.
                    Slog.wtf(TAG, "System route provider not found.");
                }
                currentSystemSessionInfo = mSystemProvider.getSessionInfos().get(0);
                currentSystemSessionInfo = getSystemProvider().getSessionInfos().get(0);
            } else {
                currentRoutes.add(mSystemProvider.getDefaultRoute());
                currentSystemSessionInfo = mSystemProvider.getDefaultSessionInfo();
                currentRoutes.add(getSystemProvider().getDefaultRoute());
                currentSystemSessionInfo = getSystemProvider().getDefaultSessionInfo();
            }

            if (!currentRoutes.isEmpty()) {