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

Commit e0757c58 authored by Kyunglyul Hyun's avatar Kyunglyul Hyun Committed by Android (Google) Code Review
Browse files

Merge "MediaRouter: Add MediaRoute2Info#isSystemRoute"

parents 802d773c 96d36cee
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -26737,6 +26737,7 @@ package android.media {
    method public int getVolume();
    method public int getVolume();
    method public int getVolumeHandling();
    method public int getVolumeHandling();
    method public int getVolumeMax();
    method public int getVolumeMax();
    method public boolean isSystemRoute();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field public static final int CONNECTION_STATE_CONNECTED = 2; // 0x2
    field public static final int CONNECTION_STATE_CONNECTED = 2; // 0x2
    field public static final int CONNECTION_STATE_CONNECTING = 1; // 0x1
    field public static final int CONNECTION_STATE_CONNECTING = 1; // 0x1
+29 −1
Original line number Original line Diff line number Diff line
@@ -198,6 +198,7 @@ public final class MediaRoute2Info implements Parcelable {
    final List<String> mFeatures;
    final List<String> mFeatures;
    @DeviceType
    @DeviceType
    final int mDeviceType;
    final int mDeviceType;
    final boolean mIsSystem;
    final Uri mIconUri;
    final Uri mIconUri;
    final CharSequence mDescription;
    final CharSequence mDescription;
    @ConnectionState
    @ConnectionState
@@ -214,6 +215,7 @@ public final class MediaRoute2Info implements Parcelable {
        mName = builder.mName;
        mName = builder.mName;
        mFeatures = builder.mFeatures;
        mFeatures = builder.mFeatures;
        mDeviceType = builder.mDeviceType;
        mDeviceType = builder.mDeviceType;
        mIsSystem = builder.mIsSystem;
        mIconUri = builder.mIconUri;
        mIconUri = builder.mIconUri;
        mDescription = builder.mDescription;
        mDescription = builder.mDescription;
        mConnectionState = builder.mConnectionState;
        mConnectionState = builder.mConnectionState;
@@ -230,6 +232,7 @@ public final class MediaRoute2Info implements Parcelable {
        mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mFeatures = in.createStringArrayList();
        mFeatures = in.createStringArrayList();
        mDeviceType = in.readInt();
        mDeviceType = in.readInt();
        mIsSystem = in.readBoolean();
        mIconUri = in.readParcelable(null);
        mIconUri = in.readParcelable(null);
        mDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mConnectionState = in.readInt();
        mConnectionState = in.readInt();
@@ -287,6 +290,17 @@ public final class MediaRoute2Info implements Parcelable {
        return mDeviceType;
        return mDeviceType;
    }
    }


    /**
     * Returns whether the route is a system route or not.
     * <p>
     * System routes are media routes directly controlled by the system
     * such as phone speaker, wired headset, and Bluetooth devices.
     * </p>
     */
    public boolean isSystemRoute() {
        return mIsSystem;
    }

    /**
    /**
     * Gets the URI of the icon representing this route.
     * Gets the URI of the icon representing this route.
     * <p>
     * <p>
@@ -425,6 +439,7 @@ public final class MediaRoute2Info implements Parcelable {
                && Objects.equals(mName, other.mName)
                && Objects.equals(mName, other.mName)
                && Objects.equals(mFeatures, other.mFeatures)
                && Objects.equals(mFeatures, other.mFeatures)
                && (mDeviceType == other.mDeviceType)
                && (mDeviceType == other.mDeviceType)
                && (mIsSystem == other.mIsSystem)
                && Objects.equals(mIconUri, other.mIconUri)
                && Objects.equals(mIconUri, other.mIconUri)
                && Objects.equals(mDescription, other.mDescription)
                && Objects.equals(mDescription, other.mDescription)
                && (mConnectionState == other.mConnectionState)
                && (mConnectionState == other.mConnectionState)
@@ -438,7 +453,7 @@ public final class MediaRoute2Info implements Parcelable {
    @Override
    @Override
    public int hashCode() {
    public int hashCode() {
        // Note: mExtras is not included.
        // Note: mExtras is not included.
        return Objects.hash(mId, mName, mFeatures, mDeviceType, mIconUri, mDescription,
        return Objects.hash(mId, mName, mFeatures, mDeviceType, mIsSystem, mIconUri, mDescription,
                mConnectionState, mClientPackageName, mVolumeHandling, mVolumeMax, mVolume,
                mConnectionState, mClientPackageName, mVolumeHandling, mVolumeMax, mVolume,
                mProviderId);
                mProviderId);
    }
    }
@@ -475,6 +490,7 @@ public final class MediaRoute2Info implements Parcelable {
        TextUtils.writeToParcel(mName, dest, flags);
        TextUtils.writeToParcel(mName, dest, flags);
        dest.writeStringList(mFeatures);
        dest.writeStringList(mFeatures);
        dest.writeInt(mDeviceType);
        dest.writeInt(mDeviceType);
        dest.writeBoolean(mIsSystem);
        dest.writeParcelable(mIconUri, flags);
        dest.writeParcelable(mIconUri, flags);
        TextUtils.writeToParcel(mDescription, dest, flags);
        TextUtils.writeToParcel(mDescription, dest, flags);
        dest.writeInt(mConnectionState);
        dest.writeInt(mConnectionState);
@@ -496,6 +512,7 @@ public final class MediaRoute2Info implements Parcelable {


        @DeviceType
        @DeviceType
        int mDeviceType = DEVICE_TYPE_UNKNOWN;
        int mDeviceType = DEVICE_TYPE_UNKNOWN;
        boolean mIsSystem;
        Uri mIconUri;
        Uri mIconUri;
        CharSequence mDescription;
        CharSequence mDescription;
        @ConnectionState
        @ConnectionState
@@ -542,6 +559,7 @@ public final class MediaRoute2Info implements Parcelable {
            mName = routeInfo.mName;
            mName = routeInfo.mName;
            mFeatures = new ArrayList<>(routeInfo.mFeatures);
            mFeatures = new ArrayList<>(routeInfo.mFeatures);
            mDeviceType = routeInfo.mDeviceType;
            mDeviceType = routeInfo.mDeviceType;
            mIsSystem = routeInfo.mIsSystem;
            mIconUri = routeInfo.mIconUri;
            mIconUri = routeInfo.mIconUri;
            mDescription = routeInfo.mDescription;
            mDescription = routeInfo.mDescription;
            mConnectionState = routeInfo.mConnectionState;
            mConnectionState = routeInfo.mConnectionState;
@@ -609,6 +627,16 @@ public final class MediaRoute2Info implements Parcelable {
            return this;
            return this;
        }
        }


        /**
         * Sets whether the route is a system route or not.
         * @hide
         */
        @NonNull
        public Builder setSystemRoute(boolean isSystem) {
            mIsSystem = isSystem;
            return this;
        }

        /**
        /**
         * Sets the URI of the icon representing this route.
         * Sets the URI of the icon representing this route.
         * <p>
         * <p>
+17 −0
Original line number Original line Diff line number Diff line
@@ -179,6 +179,23 @@ public final class MediaRoute2ProviderInfo implements Parcelable {
            return this;
            return this;
        }
        }


        /**
         * Sets whether the provider provides system routes or not
         */
        @NonNull
        public Builder setSystemRouteProvider(boolean isSystem) {
            int count = mRoutes.size();
            for (int i = 0; i < count; i++) {
                MediaRoute2Info route = mRoutes.valueAt(i);
                if (route.isSystemRoute() != isSystem) {
                    mRoutes.setValueAt(i, new MediaRoute2Info.Builder(route)
                            .setSystemRoute(isSystem)
                            .build());
                }
            }
            return this;
        }

        /**
        /**
         * Adds a route to the provider
         * Adds a route to the provider
         */
         */
+12 −1
Original line number Original line Diff line number Diff line
@@ -230,7 +230,11 @@ public class MediaRouter2 {
    /**
    /**
     * Gets the unmodifiable list of {@link MediaRoute2Info routes} currently
     * Gets the unmodifiable list of {@link MediaRoute2Info routes} currently
     * known to the media router.
     * known to the media router.
     * <p>
     * {@link MediaRoute2Info#isSystemRoute() System routes} such as phone speaker,
     * Bluetooth devices are always included in the list.
     * Please note that the list can be changed before callbacks are invoked.
     * Please note that the list can be changed before callbacks are invoked.
     * </p>
     *
     *
     * @return the list of routes that contains at least one of the route features in discovery
     * @return the list of routes that contains at least one of the route features in discovery
     * preferences registered by the application
     * preferences registered by the application
@@ -243,7 +247,8 @@ public class MediaRouter2 {


                List<MediaRoute2Info> filteredRoutes = new ArrayList<>();
                List<MediaRoute2Info> filteredRoutes = new ArrayList<>();
                for (MediaRoute2Info route : mRoutes.values()) {
                for (MediaRoute2Info route : mRoutes.values()) {
                    if (route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
                    if (route.isSystemRoute()
                            || route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
                        filteredRoutes.add(route);
                        filteredRoutes.add(route);
                    }
                    }
                }
                }
@@ -307,12 +312,18 @@ public class MediaRouter2 {
     * with the given route.
     * with the given route.
     *
     *
     * @param route the route you want to create a controller with.
     * @param route the route you want to create a controller with.
     * @throws IllegalArgumentException if the given route is
     * {@link MediaRoute2Info#isSystemRoute() system route}
     *
     *
     * @see RoutingControllerCallback#onControllerCreated
     * @see RoutingControllerCallback#onControllerCreated
     * @see RoutingControllerCallback#onControllerCreationFailed
     * @see RoutingControllerCallback#onControllerCreationFailed
     */
     */
    public void requestCreateController(@NonNull MediaRoute2Info route) {
    public void requestCreateController(@NonNull MediaRoute2Info route) {
        Objects.requireNonNull(route, "route must not be null");
        Objects.requireNonNull(route, "route must not be null");
        if (route.isSystemRoute()) {
            throw new IllegalArgumentException("Can't create a route controller with "
                    + "a system route. Use getSystemController().");
        }
        // TODO: Check the given route exists
        // TODO: Check the given route exists


        final int requestId;
        final int requestId;
+4 −3
Original line number Original line Diff line number Diff line
@@ -161,14 +161,15 @@ public class MediaRouter2Manager {
    public List<MediaRoute2Info> getAvailableRoutes(@NonNull String packageName) {
    public List<MediaRoute2Info> getAvailableRoutes(@NonNull String packageName) {
        Objects.requireNonNull(packageName, "packageName must not be null");
        Objects.requireNonNull(packageName, "packageName must not be null");


        List<MediaRoute2Info> routes = new ArrayList<>();

        List<String> preferredFeatures = mPreferredFeaturesMap.get(packageName);
        List<String> preferredFeatures = mPreferredFeaturesMap.get(packageName);
        if (preferredFeatures == null) {
        if (preferredFeatures == null) {
            return Collections.emptyList();
            preferredFeatures = Collections.emptyList();
        }
        }
        List<MediaRoute2Info> routes = new ArrayList<>();
        synchronized (mRoutesLock) {
        synchronized (mRoutesLock) {
            for (MediaRoute2Info route : mRoutes.values()) {
            for (MediaRoute2Info route : mRoutes.values()) {
                if (route.hasAnyFeatures(preferredFeatures)) {
                if (route.isSystemRoute() || route.hasAnyFeatures(preferredFeatures)) {
                    routes.add(route);
                    routes.add(route);
                }
                }
            }
            }
Loading