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

Commit 919bed66 authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Make dedup id mandatory for multiple routing type support

This enables identifying a mirroring MR2Info object and the
corresponding "remote one" as the same physical receiver device.

Bug: b/396403760
Bug: b/362507305
Test: atest CtsMediaBetterTogetherTestCases:android.media.router.cts.SystemMediaRoutingTest
Flag: com.android.media.flags.enable_mirroring_in_media_router_2
Change-Id: I54bf41ff9d5f6d87191a9862069fd9e3781ff152
parent 3e2aa3a1
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -759,12 +759,29 @@ public abstract class MediaRoute2ProviderService extends Service {

    /**
     * Updates routes of the provider and notifies the system media router service.
     *
     * @throws IllegalArgumentException If {@code routes} contains a route that {@link
     *     MediaRoute2Info#getSupportedRoutingTypes() supports} both system media routing and remote
     *     routing but doesn't contain any {@link MediaRoute2Info#getDeduplicationIds()
     *     deduplication ids}.
     */
    public final void notifyRoutes(@NonNull Collection<MediaRoute2Info> routes) {
        requireNonNull(routes, "routes must not be null");
        List<MediaRoute2Info> sanitizedRoutes = new ArrayList<>(routes.size());

        for (MediaRoute2Info route : routes) {
            if (Flags.enableMirroringInMediaRouter2()
                    && route.supportsRemoteRouting()
                    && route.supportsSystemMediaRouting()
                    && route.getDeduplicationIds().isEmpty()) {
                String errorMessage =
                        TextUtils.formatSimple(
                                "Route with id='%s' name='%s' supports both system media and remote"
                                    + " type routing, but doesn't contain a deduplication id, which"
                                    + " it needs. You can add the route id as a deduplication id.",
                                route.getOriginalId(), route.getName());
                throw new IllegalArgumentException(errorMessage);
            }
            if (route.isSystemRouteType()) {
                Log.w(
                        TAG,
+8 −0
Original line number Diff line number Diff line
@@ -983,6 +983,14 @@ final class MediaRoute2ProviderServiceProxy extends MediaRoute2Provider {
            Objects.requireNonNull(providerInfo, "providerInfo must not be null");

            for (MediaRoute2Info route : providerInfo.getRoutes()) {
                if (Flags.enableMirroringInMediaRouter2()
                        && route.supportsRemoteRouting()
                        && route.supportsSystemMediaRouting()
                        && route.getDeduplicationIds().isEmpty()) {
                    // This code is not accessible if the app is using the public API.
                    throw new SecurityException("Route is missing deduplication id: " + route);
                }

                if (route.isSystemRoute()) {
                    throw new SecurityException(
                            "Only the system is allowed to publish system routes. "