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

Commit 9664a1c8 authored by Shenqiu Zhang's avatar Shenqiu Zhang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "shenqiuz-get_provider_package_name" into main

* changes:
  Add API MediaRoute2Info#getProviderPackageName()
  Add aconfig flag to enable the MediaRoute2Info#getProviderPackageName() API
parents 924b1c22 05ffa42e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24940,6 +24940,7 @@ package android.media {
    method @Nullable public android.net.Uri getIconUri();
    method @NonNull public String getId();
    method @NonNull public CharSequence getName();
    method @FlaggedApi("com.android.media.flags.enable_media_route_2_info_provider_package_name") @Nullable public String getProviderPackageName();
    method @FlaggedApi("com.android.media.flags.enable_route_visibility_control_api") @NonNull public java.util.List<java.util.Set<java.lang.String>> getRequiredPermissions();
    method @FlaggedApi("com.android.media.flags.enable_built_in_speaker_route_suitability_statuses") public int getSuitabilityStatus();
    method @FlaggedApi("com.android.media.flags.enable_mirroring_in_media_router_2") public int getSupportedRoutingTypes();
+29 −18
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.media.audio.Flags.FLAG_ENABLE_MULTICHANNEL_GROUP_DEVICE;

import static com.android.media.flags.Flags.FLAG_ENABLE_AUDIO_POLICIES_DEVICE_AND_BLUETOOTH_CONTROLLER;
import static com.android.media.flags.Flags.FLAG_ENABLE_BUILT_IN_SPEAKER_ROUTE_SUITABILITY_STATUSES;
import static com.android.media.flags.Flags.FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME;
import static com.android.media.flags.Flags.FLAG_ENABLE_MIRRORING_IN_MEDIA_ROUTER_2;
import static com.android.media.flags.Flags.FLAG_ENABLE_NEW_MEDIA_ROUTE_2_INFO_TYPES;
import static com.android.media.flags.Flags.FLAG_ENABLE_NEW_WIRED_MEDIA_ROUTE_2_INFO_TYPES;
@@ -631,7 +632,7 @@ public final class MediaRoute2Info implements Parcelable {
    @ConnectionState
    private final int mConnectionState;
    private final String mClientPackageName;
    private final String mPackageName;
    private final String mProviderPackageName;
    @PlaybackVolume private final int mVolumeHandling;
    private final int mVolumeMax;
    private final int mVolume;
@@ -655,7 +656,7 @@ public final class MediaRoute2Info implements Parcelable {
        mDescription = builder.mDescription;
        mConnectionState = builder.mConnectionState;
        mClientPackageName = builder.mClientPackageName;
        mPackageName = builder.mPackageName;
        mProviderPackageName = builder.mProviderPackageName;
        mVolumeHandling = builder.mVolumeHandling;
        mVolumeMax = builder.mVolumeMax;
        mVolume = builder.mVolume;
@@ -681,7 +682,7 @@ public final class MediaRoute2Info implements Parcelable {
        mDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mConnectionState = in.readInt();
        mClientPackageName = in.readString();
        mPackageName = in.readString();
        mProviderPackageName = in.readString();
        mVolumeHandling = in.readInt();
        mVolumeMax = in.readInt();
        mVolume = in.readInt();
@@ -801,14 +802,19 @@ public final class MediaRoute2Info implements Parcelable {
    }

    /**
     * Gets the package name of the provider that published the route.
     * <p>
     * It is set by the system service.
     * @hide
     * Gets the package name of the {@link MediaRoute2ProviderService provider} that published the
     * route, or null if it has not yet been populated.
     *
     * <p>The package name of the route provider is populated by the system as part of {@link
     * MediaRoute2ProviderService#notifyRoutes(java.util.Collection)}. As a result, it's expectable
     * that a {@link MediaRoute2Info} instance that hasn't yet been published will have a null
     * provider package name. Otherwise, routes obtained via {@link MediaRouter2} should have a
     * populated provider package name.
     */
    @FlaggedApi(FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME)
    @Nullable
    public String getPackageName() {
        return mPackageName;
    public String getProviderPackageName() {
        return mProviderPackageName;
    }

    /**
@@ -943,10 +949,13 @@ public final class MediaRoute2Info implements Parcelable {

    /**
     * Returns whether this route is visible to the package with the given name.
     *
     * @hide
     */
    @FlaggedApi(FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME)
    public boolean isVisibleTo(String packageName) {
        return !mIsVisibilityRestricted || getPackageName().equals(packageName)
        return !mIsVisibilityRestricted
                || TextUtils.equals(getProviderPackageName(), packageName)
                || mAllowedPackages.contains(packageName);
    }

@@ -1020,7 +1029,7 @@ public final class MediaRoute2Info implements Parcelable {
        pw.println(indent + "mDescription=" + mDescription);
        pw.println(indent + "mConnectionState=" + mConnectionState);
        pw.println(indent + "mClientPackageName=" + mClientPackageName);
        pw.println(indent + "mPackageName=" + mPackageName);
        pw.println(indent + "mProviderPackageName=" + mProviderPackageName);

        dumpVolume(pw, indent);

@@ -1059,7 +1068,7 @@ public final class MediaRoute2Info implements Parcelable {
                && Objects.equals(mDescription, other.mDescription)
                && (mConnectionState == other.mConnectionState)
                && Objects.equals(mClientPackageName, other.mClientPackageName)
                && Objects.equals(mPackageName, other.mPackageName)
                && Objects.equals(mProviderPackageName, other.mProviderPackageName)
                && (mVolumeHandling == other.mVolumeHandling)
                && (mVolumeMax == other.mVolumeMax)
                && (mVolume == other.mVolume)
@@ -1086,7 +1095,7 @@ public final class MediaRoute2Info implements Parcelable {
                mDescription,
                mConnectionState,
                mClientPackageName,
                mPackageName,
                mProviderPackageName,
                mVolumeHandling,
                mVolumeMax,
                mVolume,
@@ -1162,7 +1171,7 @@ public final class MediaRoute2Info implements Parcelable {
        TextUtils.writeToParcel(mDescription, dest, flags);
        dest.writeInt(mConnectionState);
        dest.writeString(mClientPackageName);
        dest.writeString(mPackageName);
        dest.writeString(mProviderPackageName);
        dest.writeInt(mVolumeHandling);
        dest.writeInt(mVolumeMax);
        dest.writeInt(mVolume);
@@ -1314,7 +1323,7 @@ public final class MediaRoute2Info implements Parcelable {
        @ConnectionState
        private int mConnectionState;
        private String mClientPackageName;
        private String mPackageName;
        private String mProviderPackageName;
        @PlaybackVolume private int mVolumeHandling = PLAYBACK_VOLUME_FIXED;
        private int mVolumeMax;
        private int mVolume;
@@ -1387,7 +1396,7 @@ public final class MediaRoute2Info implements Parcelable {
            mDescription = routeInfo.mDescription;
            mConnectionState = routeInfo.mConnectionState;
            mClientPackageName = routeInfo.mClientPackageName;
            mPackageName = routeInfo.mPackageName;
            mProviderPackageName = routeInfo.mProviderPackageName;
            mVolumeHandling = routeInfo.mVolumeHandling;
            mVolumeMax = routeInfo.mVolumeMax;
            mVolume = routeInfo.mVolume;
@@ -1534,11 +1543,13 @@ public final class MediaRoute2Info implements Parcelable {

        /**
         * Sets the package name of the route.
         *
         * @hide
         */
        // It is set by the MediaRouterService.
        @NonNull
        public Builder setPackageName(@NonNull String packageName) {
            mPackageName = packageName;
        public Builder setProviderPackageName(@NonNull String providerPackageName) {
            mProviderPackageName = providerPackageName;
            return this;
        }

+10 −9
Original line number Diff line number Diff line
@@ -152,11 +152,11 @@ public final class MediaRoute2ProviderInfo implements Parcelable {

        /**
         * Sets the package name and unique id of the provider info.
         * <p>
         * The unique id is automatically set by
         * {@link com.android.server.media.MediaRouterService} and used to identify providers.
         * The id set by {@link MediaRoute2ProviderService} will be ignored.
         * </p>
         *
         * <p>The unique id is automatically set by {@link
         * com.android.server.media.MediaRouterService} and used to identify providers. The id set
         * by {@link MediaRoute2ProviderService} will be ignored.
         *
         * @hide
         */
        @NonNull
@@ -168,8 +168,9 @@ public final class MediaRoute2ProviderInfo implements Parcelable {

            final ArrayMap<String, MediaRoute2Info> newRoutes = new ArrayMap<>();
            for (Map.Entry<String, MediaRoute2Info> entry : mRoutes.entrySet()) {
                MediaRoute2Info routeWithProviderId = new MediaRoute2Info.Builder(entry.getValue())
                        .setPackageName(packageName)
                MediaRoute2Info routeWithProviderId =
                        new MediaRoute2Info.Builder(entry.getValue())
                                .setProviderPackageName(packageName)
                                .setProviderId(mUniqueId)
                                .build();
                newRoutes.put(routeWithProviderId.getOriginalId(), routeWithProviderId);
+10 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.media;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import static com.android.media.flags.Flags.FLAG_ENABLE_BUILT_IN_SPEAKER_ROUTE_SUITABILITY_STATUSES;
import static com.android.media.flags.Flags.FLAG_ENABLE_GET_TRANSFERABLE_ROUTES;
import static com.android.media.flags.Flags.FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME;
import static com.android.media.flags.Flags.FLAG_ENABLE_PRIVILEGED_ROUTING_FOR_MEDIA_ROUTING_CONTROL;
import static com.android.media.flags.Flags.FLAG_ENABLE_RLP_CALLBACKS_IN_MEDIA_ROUTER2;
import static com.android.media.flags.Flags.FLAG_ENABLE_SCREEN_OFF_SCANNING;
@@ -1398,6 +1399,7 @@ public final class MediaRouter2 {
        requestCreateController(controller, route, managerRequestId);
    }

    @FlaggedApi(FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME)
    private List<MediaRoute2Info> getSortedRoutes(
            List<MediaRoute2Info> routes, List<String> packageOrder) {
        if (packageOrder.isEmpty()) {
@@ -1412,11 +1414,13 @@ public final class MediaRouter2 {
        ArrayList<MediaRoute2Info> sortedRoutes = new ArrayList<>(routes);
        // take the negative for descending order
        sortedRoutes.sort(
                Comparator.comparingInt(r -> -packagePriority.getOrDefault(r.getPackageName(), 0)));
                Comparator.comparingInt(
                        r -> -packagePriority.getOrDefault(r.getProviderPackageName(), 0)));
        return sortedRoutes;
    }

    @GuardedBy("mLock")
    @FlaggedApi(FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME)
    private List<MediaRoute2Info> filterRoutesWithCompositePreferenceLocked(
            List<MediaRoute2Info> routes) {

@@ -1429,10 +1433,10 @@ public final class MediaRouter2 {
                continue;
            }
            if (!mDiscoveryPreference.getAllowedPackages().isEmpty()
                    && (route.getPackageName() == null
                    && (route.getProviderPackageName() == null
                            || !mDiscoveryPreference
                                    .getAllowedPackages()
                                    .contains(route.getPackageName()))) {
                                    .contains(route.getProviderPackageName()))) {
                continue;
            }
            if (mDiscoveryPreference.shouldRemoveDuplicates()) {
@@ -3643,6 +3647,7 @@ public final class MediaRouter2 {
            }
        }

        @FlaggedApi(FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME)
        @Override
        public List<MediaRoute2Info> filterRoutesWithIndividualPreference(
                List<MediaRoute2Info> routes, RouteDiscoveryPreference discoveryPreference) {
@@ -3652,10 +3657,10 @@ public final class MediaRouter2 {
                    continue;
                }
                if (!discoveryPreference.getAllowedPackages().isEmpty()
                        && (route.getPackageName() == null
                        && (route.getProviderPackageName() == null
                                || !discoveryPreference
                                        .getAllowedPackages()
                                        .contains(route.getPackageName()))) {
                                        .contains(route.getProviderPackageName()))) {
                    continue;
                }
                filteredRoutes.add(route);
+13 −6
Original line number Diff line number Diff line
@@ -20,9 +20,11 @@ import static android.media.MediaRouter2.SCANNING_STATE_NOT_SCANNING;
import static android.media.MediaRouter2.SCANNING_STATE_WHILE_INTERACTIVE;

import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import static com.android.media.flags.Flags.FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME;

import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -285,6 +287,7 @@ public final class MediaRouter2Manager {
                (route) -> sessionInfo.isSystemSession() ^ route.isSystemRoute());
    }

    @FlaggedApi(FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME)
    private List<MediaRoute2Info> getSortedRoutes(RouteDiscoveryPreference preference) {
        if (!preference.shouldRemoveDuplicates()) {
            synchronized (mRoutesLock) {
@@ -302,12 +305,15 @@ public final class MediaRouter2Manager {
            routes = new ArrayList<>(mRoutes.values());
        }
        // take the negative for descending order
        routes.sort(Comparator.comparingInt(
                r -> -packagePriority.getOrDefault(r.getPackageName(), 0)));
        routes.sort(
                Comparator.comparingInt(
                        r -> -packagePriority.getOrDefault(r.getProviderPackageName(), 0)));
        return routes;
    }

    private List<MediaRoute2Info> getFilteredRoutes(@NonNull RoutingSessionInfo sessionInfo,
    @FlaggedApi(FLAG_ENABLE_MEDIA_ROUTE_2_INFO_PROVIDER_PACKAGE_NAME)
    private List<MediaRoute2Info> getFilteredRoutes(
            @NonNull RoutingSessionInfo sessionInfo,
            boolean includeSelectedRoutes,
            @Nullable Predicate<MediaRoute2Info> additionalFilter) {
        Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
@@ -336,9 +342,10 @@ public final class MediaRouter2Manager {
                continue;
            }
            if (!discoveryPreference.getAllowedPackages().isEmpty()
                    && (route.getPackageName() == null
                    || !discoveryPreference.getAllowedPackages()
                    .contains(route.getPackageName()))) {
                    && (route.getProviderPackageName() == null
                            || !discoveryPreference
                                    .getAllowedPackages()
                                    .contains(route.getProviderPackageName()))) {
                continue;
            }
            if (additionalFilter != null && !additionalFilter.test(route)) {
Loading