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

Commit 9d1ff5e4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "MediaRouter2: Add requestCreateSession"

parents f98220ef 63a05405
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.media.IMediaRoute2ProviderClient;
 */
oneway interface IMediaRoute2Provider {
    void setClient(IMediaRoute2ProviderClient client);
    void requestCreateSession(String packageName, String routeId, String controlCategory,
            int requestId);
    void requestSelectRoute(String packageName, String id, int seq);
    void unselectRoute(String packageName, String id);
    void notifyControlRequestSent(String id, in Intent request);
+5 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.media;

import android.media.MediaRoute2ProviderInfo;
import android.media.MediaRoute2Info;
import android.media.RouteSessionInfo;
import android.os.Bundle;

/**
@@ -25,5 +26,8 @@ import android.os.Bundle;
 */
oneway interface IMediaRoute2ProviderClient {
    void updateProviderInfo(in MediaRoute2ProviderInfo info);
    void notifyRouteSelected(String packageName, String routeId, in Bundle controlHints, int seq);
    void notifyRouteSelected(String packageName, String routeId, in @nullable Bundle controlHints,
            int seq);
    void notifySessionCreated(in @nullable RouteSessionInfo sessionInfo,
            in @nullable Bundle controlHints, int requestId);
}
+3 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.media;

import android.media.MediaRoute2Info;
import android.media.RouteSessionInfo;
import android.os.Bundle;

/**
@@ -27,5 +28,6 @@ oneway interface IMediaRouter2Client {
    void notifyRoutesAdded(in List<MediaRoute2Info> routes);
    void notifyRoutesRemoved(in List<MediaRoute2Info> routes);
    void notifyRoutesChanged(in List<MediaRoute2Info> routes);
    void notifyRouteSelected(in MediaRoute2Info route, int reason, in Bundle controlHints);
    void notifySessionCreated(in @nullable RouteSessionInfo sessionInfo,
            in @nullable Bundle controlHints, int requestId);
}
+3 −7
Original line number Diff line number Diff line
@@ -48,13 +48,9 @@ interface IMediaRouterService {
    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);
    /**
     * Changes the selected route of the client.
     *
     * @param client the client that changes it's selected route
     * @param route the route to be selected
     */
    void requestSelectRoute2(IMediaRouter2Client client, in @nullable MediaRoute2Info route);

    void requestCreateSession(IMediaRouter2Client client, in MediaRoute2Info route,
            String controlCategory, int requestId);
    void setControlCategories(IMediaRouter2Client client, in List<String> categories);

    void registerManager(IMediaRouter2Manager manager, String packageName);
+32 −12
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ public abstract class MediaRoute2ProviderService extends Service {
    private final Handler mHandler;
    private final Object mSessionLock = new Object();
    private ProviderStub mStub;
    // TODO: Rename this to mService (and accordingly IMediaRoute2ProviderClient to something else)
    private IMediaRoute2ProviderClient mClient;
    private MediaRoute2ProviderInfo mProviderInfo;

@@ -166,19 +167,29 @@ public abstract class MediaRoute2ProviderService extends Service {
     * Notifies clients of that the session is created and ready for use. If the session can be
     * controlled, pass a {@link Bundle} that contains how to control it.
     *
     * @param sessionId id of the session
     * @param sessionInfo information of the new session.
     *                    Pass {@code null} to reject the request or inform clients that
     *                    session creation has failed.
     * @param controlHints a {@link Bundle} that contains how to control the session.
     * @param requestId id of the previous request to create this session
     */
    //TODO: fail reason?
    public final void notifySessionCreated(int sessionId, @Nullable RouteSessionInfo sessionInfo,
            @Nullable Bundle controlHints) {
        //TODO: validate sessionId (it must be in "waiting list")
    public final void notifySessionCreated(@Nullable RouteSessionInfo sessionInfo,
            @Nullable Bundle controlHints, int requestId) {
        //TODO: validate sessionInfo.getSessionId() (it must be in "waiting list")
        if (sessionInfo != null) {
            synchronized (mSessionLock) {
            mSessionInfo.put(sessionId, sessionInfo);
            //TODO: notify media router service of session creation.
                mSessionInfo.put(sessionInfo.getSessionId(), sessionInfo);
            }
        }

        if (mClient == null) {
            return;
        }
        try {
            mClient.notifySessionCreated(sessionInfo, controlHints, requestId);
        } catch (RemoteException ex) {
            Log.w(TAG, "Failed to notify session created.");
        }
    }

@@ -203,18 +214,19 @@ public abstract class MediaRoute2ProviderService extends Service {
    /**
     * Called when a session should be created.
     * You should create and maintain your own session and notifies the client of
     * session info. Call {@link #notifySessionCreated(int, RouteSessionInfo, Bundle)}
     * to notify the information of a new session.
     * session info. Call {@link #notifySessionCreated(RouteSessionInfo, Bundle, int)}
     * with the given {@code requestId} to notify the information of a new session.
     * If you can't create the session or want to reject the request, pass {@code null}
     * as session info in {@link #notifySessionCreated(int, RouteSessionInfo, Bundle)}.
     * as session info in {@link #notifySessionCreated(RouteSessionInfo, Bundle, int)}
     * with the given {@code requestId}.
     *
     * @param packageName the package name of the application that selected the route
     * @param routeId the id of the route initially being connected
     * @param controlCategory the control category of the new session
     * @param sessionId the id of a new session
     * @param requestId the id of this session creation request
     */
    public abstract void onCreateSession(@NonNull String packageName, @NonNull String routeId,
            @NonNull String controlCategory, int sessionId);
            @NonNull String controlCategory, int requestId);

    /**
     * Called when a session is about to be destroyed.
@@ -338,6 +350,14 @@ public abstract class MediaRoute2ProviderService extends Service {
                    MediaRoute2ProviderService.this, client));
        }

        @Override
        public void requestCreateSession(String packageName, String routeId, String controlCategory,
                int requestId) {
            mHandler.sendMessage(obtainMessage(MediaRoute2ProviderService::onCreateSession,
                    MediaRoute2ProviderService.this, packageName, routeId, controlCategory,
                    requestId));
        }

        @Override
        public void requestSelectRoute(String packageName, String routeId, int seq) {
            //TODO: call onCreateSession instead
Loading