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

Commit 25c8e167 authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Revert "Add support for system-wide mirroring"

This reverts commit fc62ef1c.

Reason for revert: We don't want to support global routing for the first iteration.

Test: atest CtsMediaRouterTestCases:android.media.router.cts.SystemMediaRoutingTest
Bug: b/362507305
Bug: b/413313659
Change-Id: Ic4f1d01f630f3872634ff604fadc42bdafbf71a6
parent bfe173d4
Loading
Loading
Loading
Loading
+0 −10
Original line number Original line Diff line number Diff line
@@ -179,16 +179,6 @@ flag {
    }
    }
}
}


flag {
    name: "enable_per_app_mirroring_in_media_router_2"
    namespace: "media_better_together"
    description: "Enables MediaRouter2 app-specific mirroring. Requires enable_mirroring_in_media_router_2."
    bug: "413313659"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
flag {
    name: "enable_prevention_of_keep_alive_route_providers"
    name: "enable_prevention_of_keep_alive_route_providers"
    namespace: "media_solutions"
    namespace: "media_solutions"
+18 −60
Original line number Original line Diff line number Diff line
@@ -43,7 +43,6 @@ import android.util.Log;
import android.util.LongSparseArray;
import android.util.LongSparseArray;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.media.flags.Flags;
import com.android.server.media.MediaRoute2ProviderServiceProxy.SystemMediaSessionCallback;
import com.android.server.media.MediaRoute2ProviderServiceProxy.SystemMediaSessionCallback;


import java.util.Collections;
import java.util.Collections;
@@ -61,9 +60,6 @@ import java.util.stream.Stream;


    private static final String UNIQUE_SYSTEM_ID_PREFIX = "SYSTEM";
    private static final String UNIQUE_SYSTEM_ID_PREFIX = "SYSTEM";
    private static final String UNIQUE_SYSTEM_ID_SEPARATOR = "-";
    private static final String UNIQUE_SYSTEM_ID_SEPARATOR = "-";
    private static final boolean FORCE_GLOBAL_ROUTING_SESSION =
            !Flags.enablePerAppMirroringInMediaRouter2();
    private static final String PACKAGE_NAME_FOR_GLOBAL_SESSION = "";


    /**
    /**
     * The portion of {@link RoutingSessionInfo#getVolumeMax()} that changes as a result of a volume
     * The portion of {@link RoutingSessionInfo#getVolumeMax()} that changes as a result of a volume
@@ -130,9 +126,6 @@ import java.util.stream.Stream;
            String routeOriginalId,
            String routeOriginalId,
            int transferReason) {
            int transferReason) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (FORCE_GLOBAL_ROUTING_SESSION) {
                clientPackageName = PACKAGE_NAME_FOR_GLOBAL_SESSION;
            }
            var targetProviderProxyId = mOriginalRouteIdToProviderId.get(routeOriginalId);
            var targetProviderProxyId = mOriginalRouteIdToProviderId.get(routeOriginalId);
            var targetProviderProxyRecord = mProxyRecords.get(targetProviderProxyId);
            var targetProviderProxyRecord = mProxyRecords.get(targetProviderProxyId);
            // Holds the target route, if it's managed by a provider service. Holds null otherwise.
            // Holds the target route, if it's managed by a provider service. Holds null otherwise.
@@ -140,7 +133,7 @@ import java.util.stream.Stream;
                    targetProviderProxyRecord != null
                    targetProviderProxyRecord != null
                            ? targetProviderProxyRecord.getRouteByOriginalId(routeOriginalId)
                            ? targetProviderProxyRecord.getRouteByOriginalId(routeOriginalId)
                            : null;
                            : null;
            var existingSessionRecord = getSessionRecordByPackageName(clientPackageName);
            var existingSessionRecord = mPackageNameToSessionRecord.get(clientPackageName);
            if (existingSessionRecord != null) {
            if (existingSessionRecord != null) {
                var existingSession = existingSessionRecord.mSourceSessionInfo;
                var existingSession = existingSessionRecord.mSourceSessionInfo;
                if (targetProviderProxyId != null
                if (targetProviderProxyId != null
@@ -221,7 +214,7 @@ import java.util.stream.Stream;
            if (systemSession == null) {
            if (systemSession == null) {
                return null;
                return null;
            }
            }
            var overridingSession = getSessionRecordByPackageName(packageName);
            var overridingSession = mPackageNameToSessionRecord.get(packageName);
            if (overridingSession != null) {
            if (overridingSession != null) {
                var builder =
                var builder =
                        new RoutingSessionInfo.Builder(overridingSession.mTranslatedSessionInfo)
                        new RoutingSessionInfo.Builder(overridingSession.mTranslatedSessionInfo)
@@ -267,7 +260,7 @@ import java.util.stream.Stream;
            return;
            return;
        }
        }
        synchronized (mLock) {
        synchronized (mLock) {
            var sessionRecord = getSessionRecordByOriginalId(sessionOriginalId);
            var sessionRecord = mSessionOriginalIdToSessionRecord.get(sessionOriginalId);
            var proxyRecord = sessionRecord != null ? sessionRecord.getProxyRecord() : null;
            var proxyRecord = sessionRecord != null ? sessionRecord.getProxyRecord() : null;
            if (proxyRecord != null) {
            if (proxyRecord != null) {
                proxyRecord.mProxy.setSessionVolume(
                proxyRecord.mProxy.setSessionVolume(
@@ -279,13 +272,13 @@ import java.util.stream.Stream;
    }
    }


    @Override
    @Override
    public void selectRoute(long requestId, String sessionId, String routeId) {
    public void selectRoute(long requestId, String sessionOriginalId, String routeId) {
        if (SYSTEM_SESSION_ID.equals(sessionId)) {
        if (SYSTEM_SESSION_ID.equals(sessionOriginalId)) {
            super.selectRoute(requestId, sessionId, routeId);
            super.selectRoute(requestId, sessionOriginalId, routeId);
            return;
            return;
        }
        }
        synchronized (mLock) {
        synchronized (mLock) {
            var sessionRecord = getSessionRecordByOriginalId(sessionId);
            var sessionRecord = mSessionOriginalIdToSessionRecord.get(sessionOriginalId);
            var proxyRecord = sessionRecord != null ? sessionRecord.getProxyRecord() : null;
            var proxyRecord = sessionRecord != null ? sessionRecord.getProxyRecord() : null;
            if (proxyRecord != null) {
            if (proxyRecord != null) {
                var targetSourceRouteId =
                var targetSourceRouteId =
@@ -301,13 +294,13 @@ import java.util.stream.Stream;
    }
    }


    @Override
    @Override
    public void deselectRoute(long requestId, String sessionId, String routeId) {
    public void deselectRoute(long requestId, String sessionOriginalId, String routeId) {
        if (SYSTEM_SESSION_ID.equals(sessionId)) {
        if (SYSTEM_SESSION_ID.equals(sessionOriginalId)) {
            super.selectRoute(requestId, sessionId, routeId);
            super.selectRoute(requestId, sessionOriginalId, routeId);
            return;
            return;
        }
        }
        synchronized (mLock) {
        synchronized (mLock) {
            var sessionRecord = getSessionRecordByOriginalId(sessionId);
            var sessionRecord = mSessionOriginalIdToSessionRecord.get(sessionOriginalId);
            var proxyRecord = sessionRecord != null ? sessionRecord.getProxyRecord() : null;
            var proxyRecord = sessionRecord != null ? sessionRecord.getProxyRecord() : null;
            if (proxyRecord != null) {
            if (proxyRecord != null) {
                var targetSourceRouteId =
                var targetSourceRouteId =
@@ -322,23 +315,6 @@ import java.util.stream.Stream;
        notifyRequestFailed(requestId, MediaRoute2ProviderService.REASON_ROUTE_NOT_AVAILABLE);
        notifyRequestFailed(requestId, MediaRoute2ProviderService.REASON_ROUTE_NOT_AVAILABLE);
    }
    }


    @GuardedBy("mLock")
    private SystemMediaSessionRecord getSessionRecordByOriginalId(String sessionOriginalId) {
        if (FORCE_GLOBAL_ROUTING_SESSION) {
            return getSessionRecordByPackageName(PACKAGE_NAME_FOR_GLOBAL_SESSION);
        } else {
            return mSessionOriginalIdToSessionRecord.get(sessionOriginalId);
        }
    }

    @GuardedBy("mLock")
    private SystemMediaSessionRecord getSessionRecordByPackageName(String clientPackageName) {
        if (FORCE_GLOBAL_ROUTING_SESSION) {
            clientPackageName = PACKAGE_NAME_FOR_GLOBAL_SESSION;
        }
        return mPackageNameToSessionRecord.get(clientPackageName);
    }

    /**
    /**
     * Returns the uid that corresponds to the given name and user handle, or {@link
     * Returns the uid that corresponds to the given name and user handle, or {@link
     * Process#INVALID_UID} if a uid couldn't be found.
     * Process#INVALID_UID} if a uid couldn't be found.
@@ -396,34 +372,16 @@ import java.util.stream.Stream;
     */
     */
    private void updateSessionInfo() {
    private void updateSessionInfo() {
        synchronized (mLock) {
        synchronized (mLock) {
            var globalSessionInfoRecord =
            var systemSessionInfo = mSystemSessionInfo;
                    getSessionRecordByPackageName(PACKAGE_NAME_FOR_GLOBAL_SESSION);
            if (systemSessionInfo == null) {
            var globalSessionInfo =
                    globalSessionInfoRecord != null
                            ? globalSessionInfoRecord.mTranslatedSessionInfo
                            : null;
            if (globalSessionInfo == null) {
                globalSessionInfo = mSystemSessionInfo;
            }
            if (globalSessionInfo == null) {
                // The system session info hasn't been initialized yet. Do nothing.
                // The system session info hasn't been initialized yet. Do nothing.
                return;
                return;
            }
            }
            var builder = new RoutingSessionInfo.Builder(globalSessionInfo);
            var builder = new RoutingSessionInfo.Builder(systemSessionInfo);
            if (globalSessionInfo == mSystemSessionInfo) {
                // The session is the system one. So we make all the service-provided routes
                // available for transfer. The system transferable routes are already there.
            mProxyRecords.values().stream()
            mProxyRecords.values().stream()
                    .flatMap(ProviderProxyRecord::getRoutesStream)
                    .flatMap(ProviderProxyRecord::getRoutesStream)
                    .map(MediaRoute2Info::getOriginalId)
                    .map(MediaRoute2Info::getOriginalId)
                    .forEach(builder::addTransferableRoute);
                    .forEach(builder::addTransferableRoute);
            } else {
                // The session is service-provided. So we add the system-provided routes as
                // transferable.
                mLastSystemProviderInfo.getRoutes().stream()
                        .map(MediaRoute2Info::getOriginalId)
                        .forEach(builder::addTransferableRoute);
            }
            mSessionInfos.clear();
            mSessionInfos.clear();
            mSessionInfos.add(builder.build());
            mSessionInfos.add(builder.build());
            for (var sessionRecords : mPackageNameToSessionRecord.values()) {
            for (var sessionRecords : mPackageNameToSessionRecord.values()) {