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

Commit 0c179872 authored by Hyundo Moon's avatar Hyundo Moon Committed by Android (Google) Code Review
Browse files

Merge "Remove route features from RoutingSessionInfo related APIs"

parents 0622f209 dc79a7a8
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -24,8 +24,7 @@ import android.media.IMediaRoute2ProviderClient;
 */
oneway interface IMediaRoute2Provider {
    void setClient(IMediaRoute2ProviderClient client);
    void requestCreateSession(String packageName, String routeId,
            String routeFeature, long requestId);
    void requestCreateSession(String packageName, String routeId, long requestId);
    void releaseSession(String sessionId);

    void selectRoute(String sessionId, String routeId);
+3 −3
Original line number Diff line number Diff line
@@ -47,12 +47,12 @@ interface IMediaRouterService {
    List<MediaRoute2Info> getSystemRoutes();
    void registerClient2(IMediaRouter2Client client, String packageName);
    void unregisterClient2(IMediaRouter2Client client);
    void sendControlRequest(IMediaRouter2Client client, in MediaRoute2Info route, in Intent request);
    void sendControlRequest(IMediaRouter2Client client, in MediaRoute2Info route,
            in Intent request);
    void requestSetVolume2(IMediaRouter2Client client, in MediaRoute2Info route, int volume);
    void requestUpdateVolume2(IMediaRouter2Client client, in MediaRoute2Info route, int direction);

    void requestCreateSession(IMediaRouter2Client client, in MediaRoute2Info route,
            String routeFeature, int requestId);
    void requestCreateSession(IMediaRouter2Client client, in MediaRoute2Info route, int requestId);
    void setDiscoveryRequest2(IMediaRouter2Client client, in RouteDiscoveryPreference preference);
    void selectRoute(IMediaRouter2Client client, String sessionId, in MediaRoute2Info route);
    void deselectRoute(IMediaRouter2Client client, String sessionId, in MediaRoute2Info route);
+8 −11
Original line number Diff line number Diff line
@@ -161,8 +161,8 @@ public abstract class MediaRoute2ProviderService extends Service {
     * @param sessionInfo information of the new session.
     *                    The {@link RoutingSessionInfo#getId() id} of the session must be unique.
     * @param requestId id of the previous request to create this session provided in
     *                  {@link #onCreateSession(String, String, String, long)}
     * @see #onCreateSession(String, String, String, long)
     *                  {@link #onCreateSession(String, String, long)}
     * @see #onCreateSession(String, String, long)
     * @hide
     */
    public final void notifySessionCreated(@NonNull RoutingSessionInfo sessionInfo,
@@ -196,8 +196,8 @@ public abstract class MediaRoute2ProviderService extends Service {
     * Notifies clients of that the session could not be created.
     *
     * @param requestId id of the previous request to create the session provided in
     *                  {@link #onCreateSession(String, String, String, long)}.
     * @see #onCreateSession(String, String, String, long)
     *                  {@link #onCreateSession(String, String, long)}.
     * @see #onCreateSession(String, String, long)
     * @hide
     */
    public final void notifySessionCreationFailed(long requestId) {
@@ -289,16 +289,15 @@ public abstract class MediaRoute2ProviderService extends Service {
     *
     * @param packageName the package name of the application that selected the route
     * @param routeId the id of the route initially being connected
     * @param routeFeature the route feature of the new session
     * @param requestId the id of this session creation request
     *
     * @see RoutingSessionInfo.Builder#Builder(String, String, String)
     * @see RoutingSessionInfo.Builder#Builder(String, String)
     * @see RoutingSessionInfo.Builder#addSelectedRoute(String)
     * @see RoutingSessionInfo.Builder#setControlHints(Bundle)
     * @hide
     */
    public abstract void onCreateSession(@NonNull String packageName, @NonNull String routeId,
            @NonNull String routeFeature, long requestId);
            long requestId);

    /**
     * Called when the session should be released. A client of the session or system can request
@@ -433,14 +432,12 @@ public abstract class MediaRoute2ProviderService extends Service {
        }

        @Override
        public void requestCreateSession(String packageName, String routeId,
                String routeFeature, long requestId) {
        public void requestCreateSession(String packageName, String routeId, long requestId) {
            if (!checkCallerisSystem()) {
                return;
            }
            mHandler.sendMessage(obtainMessage(MediaRoute2ProviderService::onCreateSession,
                    MediaRoute2ProviderService.this, packageName, routeId, routeFeature,
                    requestId));
                    MediaRoute2ProviderService.this, packageName, routeId, requestId));
        }

        @Override
+10 −41
Original line number Diff line number Diff line
@@ -284,26 +284,20 @@ public class MediaRouter2 {
     * Requests the media route provider service to create a session with the given route.
     *
     * @param route the route you want to create a session with.
     * @param routeFeature the route feature of the session. Should not be empty.
     *
     * @see SessionCallback#onSessionCreated
     * @see SessionCallback#onSessionCreationFailed
     * @hide
     */
    @NonNull
    public void requestCreateSession(@NonNull MediaRoute2Info route,
            @NonNull String routeFeature) {
    public void requestCreateSession(@NonNull MediaRoute2Info route) {
        Objects.requireNonNull(route, "route must not be null");
        if (TextUtils.isEmpty(routeFeature)) {
            throw new IllegalArgumentException("routeFeature must not be empty");
        }
        // TODO: Check the given route exists
        // TODO: Check the route supports the given routeFeature

        final int requestId;
        requestId = mSessionCreationRequestCnt.getAndIncrement();

        SessionCreationRequest request = new SessionCreationRequest(requestId, route, routeFeature);
        SessionCreationRequest request = new SessionCreationRequest(requestId, route);
        mSessionCreationRequests.add(request);

        Client2 client;
@@ -312,7 +306,7 @@ public class MediaRouter2 {
        }
        if (client != null) {
            try {
                mMediaRouterService.requestCreateSession(client, route, routeFeature, requestId);
                mMediaRouterService.requestCreateSession(client, route, requestId);
            } catch (RemoteException ex) {
                Log.e(TAG, "Unable to request to create session.", ex);
                mHandler.sendMessage(obtainMessage(MediaRouter2::createControllerOnHandler,
@@ -468,27 +462,18 @@ public class MediaRouter2 {
            mSessionCreationRequests.remove(matchingRequest);

            MediaRoute2Info requestedRoute = matchingRequest.mRoute;
            String requestedRouteFeature = matchingRequest.mRouteFeature;

            if (sessionInfo == null) {
                // TODO: We may need to distinguish between failure and rejection.
                //       One way can be introducing 'reason'.
                notifySessionCreationFailed(requestedRoute, requestedRouteFeature);
                return;
            } else if (!TextUtils.equals(requestedRouteFeature,
                    sessionInfo.getRouteFeature())) {
                Log.w(TAG, "The session has different route feature from what we requested. "
                        + "(requested=" + requestedRouteFeature
                        + ", actual=" + sessionInfo.getRouteFeature()
                        + ")");
                notifySessionCreationFailed(requestedRoute, requestedRouteFeature);
                notifySessionCreationFailed(requestedRoute);
                return;
            } else if (!sessionInfo.getSelectedRoutes().contains(requestedRoute.getId())) {
                Log.w(TAG, "The session does not contain the requested route. "
                        + "(requestedRouteId=" + requestedRoute.getId()
                        + ", actualRoutes=" + sessionInfo.getSelectedRoutes()
                        + ")");
                notifySessionCreationFailed(requestedRoute, requestedRouteFeature);
                notifySessionCreationFailed(requestedRoute);
                return;
            } else if (!TextUtils.equals(requestedRoute.getProviderId(),
                    sessionInfo.getProviderId())) {
@@ -496,7 +481,7 @@ public class MediaRouter2 {
                        + "(requested route's providerId=" + requestedRoute.getProviderId()
                        + ", actual providerId=" + sessionInfo.getProviderId()
                        + ")");
                notifySessionCreationFailed(requestedRoute, requestedRouteFeature);
                notifySessionCreationFailed(requestedRoute);
                return;
            }
        }
@@ -617,10 +602,10 @@ public class MediaRouter2 {
        }
    }

    private void notifySessionCreationFailed(MediaRoute2Info route, String routeFeature) {
    private void notifySessionCreationFailed(MediaRoute2Info route) {
        for (SessionCallbackRecord record: mSessionCallbackRecords) {
            record.mExecutor.execute(
                    () -> record.mSessionCallback.onSessionCreationFailed(route, routeFeature));
                    () -> record.mSessionCallback.onSessionCreationFailed(route));
        }
    }

@@ -688,10 +673,8 @@ public class MediaRouter2 {
         * Called when the session creation request failed.
         *
         * @param requestedRoute the route info which was used for the request
         * @param requestedRouteFeature the route feature which was used for the request
         */
        public void onSessionCreationFailed(@NonNull MediaRoute2Info requestedRoute,
                @NonNull String requestedRouteFeature) {}
        public void onSessionCreationFailed(@NonNull MediaRoute2Info requestedRoute) {}

        /**
         * Called when the session info has changed.
@@ -752,16 +735,6 @@ public class MediaRouter2 {
            }
        }

        /**
         * @return the feature which is used by the session mainly.
         */
        @NonNull
        public String getRouteFeature() {
            synchronized (mControllerLock) {
                return mSessionInfo.getRouteFeature();
            }
        }

        /**
         * @return the control hints used to control routing session if available.
         */
@@ -1012,7 +985,6 @@ public class MediaRouter2 {
            StringBuilder result = new StringBuilder()
                    .append("RoutingController{ ")
                    .append("sessionId=").append(getSessionId())
                    .append(", routeFeature=").append(getRouteFeature())
                    .append(", selectedRoutes={")
                    .append(selectedRoutes)
                    .append("}")
@@ -1122,13 +1094,10 @@ public class MediaRouter2 {

    final class SessionCreationRequest {
        public final MediaRoute2Info mRoute;
        public final String mRouteFeature;
        public final int mRequestId;

        SessionCreationRequest(int requestId, @NonNull MediaRoute2Info route,
                @NonNull String routeFeature) {
        SessionCreationRequest(int requestId, @NonNull MediaRoute2Info route) {
            mRoute = route;
            mRouteFeature = routeFeature;
            mRequestId = requestId;
        }
    }
+4 −27
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ public final class RoutingSessionInfo implements Parcelable {

    final String mId;
    final String mClientPackageName;
    final String mRouteFeature;
    @Nullable
    final String mProviderId;
    final List<String> mSelectedRoutes;
@@ -66,7 +65,6 @@ public final class RoutingSessionInfo implements Parcelable {

        mId = builder.mId;
        mClientPackageName = builder.mClientPackageName;
        mRouteFeature = builder.mRouteFeature;
        mProviderId = builder.mProviderId;

        // TODO: Needs to check that the routes already have unique IDs.
@@ -87,7 +85,6 @@ public final class RoutingSessionInfo implements Parcelable {

        mId = ensureString(src.readString());
        mClientPackageName = ensureString(src.readString());
        mRouteFeature = ensureString(src.readString());
        mProviderId = src.readString();

        mSelectedRoutes = ensureList(src.createStringArrayList());
@@ -119,7 +116,7 @@ public final class RoutingSessionInfo implements Parcelable {
     * In order to ensure uniqueness in {@link MediaRouter2} side, the value of this method
     * can be different from what was set in {@link MediaRoute2ProviderService}.
     *
     * @see Builder#Builder(String, String, String)
     * @see Builder#Builder(String, String)
     */
    @NonNull
    public String getId() {
@@ -131,7 +128,7 @@ public final class RoutingSessionInfo implements Parcelable {
    }

    /**
     * Gets the original id set by {@link Builder#Builder(String, String, String)}.
     * Gets the original id set by {@link Builder#Builder(String, String)}.
     * @hide
     */
    @NonNull
@@ -147,15 +144,6 @@ public final class RoutingSessionInfo implements Parcelable {
        return mClientPackageName;
    }

    /**
     * Gets the route feature of the session.
     * Routes that don't have the feature can't be selected into the session.
     */
    @NonNull
    public String getRouteFeature() {
        return mRouteFeature;
    }

    /**
     * Gets the provider id of the session.
     * @hide
@@ -214,7 +202,6 @@ public final class RoutingSessionInfo implements Parcelable {
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString(mId);
        dest.writeString(mClientPackageName);
        dest.writeString(mRouteFeature);
        dest.writeString(mProviderId);
        dest.writeStringList(mSelectedRoutes);
        dest.writeStringList(mSelectableRoutes);
@@ -235,7 +222,6 @@ public final class RoutingSessionInfo implements Parcelable {
        RoutingSessionInfo other = (RoutingSessionInfo) obj;
        return Objects.equals(mId, other.mId)
                && Objects.equals(mClientPackageName, other.mClientPackageName)
                && Objects.equals(mRouteFeature, other.mRouteFeature)
                && Objects.equals(mProviderId, other.mProviderId)
                && Objects.equals(mSelectedRoutes, other.mSelectedRoutes)
                && Objects.equals(mSelectableRoutes, other.mSelectableRoutes)
@@ -245,7 +231,7 @@ public final class RoutingSessionInfo implements Parcelable {

    @Override
    public int hashCode() {
        return Objects.hash(mId, mClientPackageName, mRouteFeature, mProviderId,
        return Objects.hash(mId, mClientPackageName, mProviderId,
                mSelectedRoutes, mSelectableRoutes, mDeselectableRoutes, mTransferrableRoutes);
    }

@@ -254,7 +240,6 @@ public final class RoutingSessionInfo implements Parcelable {
        StringBuilder result = new StringBuilder()
                .append("RoutingSessionInfo{ ")
                .append("sessionId=").append(mId)
                .append(", routeFeature=").append(mRouteFeature)
                .append(", selectedRoutes={")
                .append(String.join(",", mSelectedRoutes))
                .append("}")
@@ -295,7 +280,6 @@ public final class RoutingSessionInfo implements Parcelable {
    public static final class Builder {
        final String mId;
        final String mClientPackageName;
        final String mRouteFeature;
        String mProviderId;
        final List<String> mSelectedRoutes;
        final List<String> mSelectableRoutes;
@@ -314,22 +298,16 @@ public final class RoutingSessionInfo implements Parcelable {
         * @param id ID of the session. Must not be empty.
         * @param clientPackageName package name of the client app which uses this session.
         *                          If is is unknown, then just use an empty string.
         * @param routeFeature the route feature of session. Must not be empty.
         * @see MediaRoute2Info#getId()
         */
        public Builder(@NonNull String id, @NonNull String clientPackageName,
                @NonNull String routeFeature) {
        public Builder(@NonNull String id, @NonNull String clientPackageName) {
            if (TextUtils.isEmpty(id)) {
                throw new IllegalArgumentException("id must not be empty");
            }
            Objects.requireNonNull(clientPackageName, "clientPackageName must not be null");
            if (TextUtils.isEmpty(routeFeature)) {
                throw new IllegalArgumentException("routeFeature must not be empty");
            }

            mId = id;
            mClientPackageName = clientPackageName;
            mRouteFeature = routeFeature;
            mSelectedRoutes = new ArrayList<>();
            mSelectableRoutes = new ArrayList<>();
            mDeselectableRoutes = new ArrayList<>();
@@ -347,7 +325,6 @@ public final class RoutingSessionInfo implements Parcelable {

            mId = sessionInfo.mId;
            mClientPackageName = sessionInfo.mClientPackageName;
            mRouteFeature = sessionInfo.mRouteFeature;
            mProviderId = sessionInfo.mProviderId;

            mSelectedRoutes = new ArrayList<>(sessionInfo.mSelectedRoutes);
Loading