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

Commit e6b62384 authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

MediaRouter: move controlHints into RouteSessionInfo

Since RouteSessionInfo and controlHints are passed
simultaenously, move controlHints into the session info
for simplicity.

Test: atest mediaroutertest

Change-Id: Id99e4d71744ab438e8fcd99101895c28e2585662
parent 9d1ff5e4
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -28,6 +28,5 @@ oneway interface IMediaRoute2ProviderClient {
    void updateProviderInfo(in MediaRoute2ProviderInfo info);
    void notifyRouteSelected(String packageName, String routeId, in @nullable Bundle controlHints,
            int seq);
    void notifySessionCreated(in @nullable RouteSessionInfo sessionInfo,
            in @nullable Bundle controlHints, int requestId);
    void notifySessionCreated(in @nullable RouteSessionInfo sessionInfo, int requestId);
}
+1 −2
Original line number Diff line number Diff line
@@ -28,6 +28,5 @@ oneway interface IMediaRouter2Client {
    void notifyRoutesAdded(in List<MediaRoute2Info> routes);
    void notifyRoutesRemoved(in List<MediaRoute2Info> routes);
    void notifyRoutesChanged(in List<MediaRoute2Info> routes);
    void notifySessionCreated(in @nullable RouteSessionInfo sessionInfo,
            in @nullable Bundle controlHints, int requestId);
    void notifySessionCreated(in @nullable RouteSessionInfo sessionInfo, int requestId);
}
+14 −15
Original line number Diff line number Diff line
@@ -142,23 +142,24 @@ public abstract class MediaRoute2ProviderService extends Service {
    }

    /**
     * Sets the information of the session with the given id.
     * If there is no session matched with the given id, it will be ignored.
     * Updates the information of a session.
     * If the session is destroyed or not created before, it will be ignored.
     * A session will be destroyed if it has no selected route.
     * Call {@link #updateProviderInfo(MediaRoute2ProviderInfo)} to notify clients of
     * session info changes.
     *
     * @param sessionId id of the session that should update its information
     * @param sessionInfo new session information
     * @see #notifySessionCreated(RouteSessionInfo, int)
     */
    public final void setSessionInfo(int sessionId, @NonNull RouteSessionInfo sessionInfo) {
    public final void updateSessionInfo(@NonNull RouteSessionInfo sessionInfo) {
        Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
        int sessionId = sessionInfo.getSessionId();

        synchronized (mSessionLock) {
            if (mSessionInfo.containsKey(sessionId)) {
                mSessionInfo.put(sessionId, sessionInfo);
            } else {
                Log.w(TAG, "Ignoring session info update.");
                Log.w(TAG, "Ignoring unknown session info.");
            }
        }
    }
@@ -170,12 +171,10 @@ public abstract class MediaRoute2ProviderService extends Service {
     * @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(@Nullable RouteSessionInfo sessionInfo,
            @Nullable Bundle controlHints, int requestId) {
    public final void notifySessionCreated(@Nullable RouteSessionInfo sessionInfo, int requestId) {
        //TODO: validate sessionInfo.getSessionId() (it must be in "waiting list")
        if (sessionInfo != null) {
            synchronized (mSessionLock) {
@@ -187,7 +186,7 @@ public abstract class MediaRoute2ProviderService extends Service {
            return;
        }
        try {
            mClient.notifySessionCreated(sessionInfo, controlHints, requestId);
            mClient.notifySessionCreated(sessionInfo, requestId);
        } catch (RemoteException ex) {
            Log.w(TAG, "Failed to notify session created.");
        }
@@ -214,10 +213,10 @@ 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(RouteSessionInfo, Bundle, int)}
     * session info. Call {@link #notifySessionCreated(RouteSessionInfo, 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(RouteSessionInfo, Bundle, int)}
     * as session info in {@link #notifySessionCreated(RouteSessionInfo, int)}
     * with the given {@code requestId}.
     *
     * @param packageName the package name of the application that selected the route
@@ -242,20 +241,20 @@ public abstract class MediaRoute2ProviderService extends Service {
    //TODO: make a way to reject the request
    /**
     * Called when a client requests adding a route to a session.
     * After the route is added, call {@link #setSessionInfo(int, RouteSessionInfo)} to update
     * After the route is added, call {@link #updateSessionInfo(RouteSessionInfo)} to update
     * session info and call {@link #updateProviderInfo(MediaRoute2ProviderInfo)} to notify
     * clients of updated session info.
     *
     * @param sessionId id of the session
     * @param routeId id of the route
     * @see #setSessionInfo(int, RouteSessionInfo)
     * @see #updateSessionInfo(RouteSessionInfo)
     */
    public abstract void onAddRoute(int sessionId, @NonNull String routeId);

    //TODO: make a way to reject the request
    /**
     * Called when a client requests removing a route from a session.
     * After the route is removed, call {@link #setSessionInfo(int, RouteSessionInfo)} to update
     * After the route is removed, call {@link #updateSessionInfo(RouteSessionInfo)} to update
     * session info and call {@link #updateProviderInfo(MediaRoute2ProviderInfo)} to notify
     * clients of updated session info.
     *
@@ -267,7 +266,7 @@ public abstract class MediaRoute2ProviderService extends Service {
    //TODO: make a way to reject the request
    /**
     * Called when a client requests transferring a session to a route.
     * After the transfer is finished, call {@link #setSessionInfo(int, RouteSessionInfo)} to update
     * After the transfer is finished, call {@link #updateSessionInfo(RouteSessionInfo)} to update
     * session info and call {@link #updateProviderInfo(MediaRoute2ProviderInfo)} to notify
     * clients of updated session info.
     *
+6 −8
Original line number Diff line number Diff line
@@ -328,7 +328,7 @@ public class MediaRouter2 {
            } catch (RemoteException ex) {
                Log.e(TAG, "Unable to request to create session.", ex);
                mHandler.sendMessage(obtainMessage(MediaRouter2::createControllerOnHandler,
                        MediaRouter2.this, null, null, requestId));
                        MediaRouter2.this, null, requestId));
            }
        }
    }
@@ -494,8 +494,7 @@ public class MediaRouter2 {
     * <p>
     * Pass {@code null} to sessionInfo for the failure case.
     */
    void createControllerOnHandler(@Nullable RouteSessionInfo sessionInfo,
            @Nullable Bundle controlHints, int requestId) {
    void createControllerOnHandler(@Nullable RouteSessionInfo sessionInfo, int requestId) {
        SessionCreationRequest matchingRequest = null;
        for (SessionCreationRequest request : mSessionCreationRequests) {
            if (request.mRequestId == requestId) {
@@ -523,7 +522,7 @@ public class MediaRouter2 {
            // TODO: RouteSessionController should be created with full info (e.g. routes)
            //       from RouteSessionInfo.
            RouteSessionController controller = new RouteSessionController(sessionInfo);
            executor.execute(() -> callback.onSessionCreated(controller, controlHints));
            executor.execute(() -> callback.onSessionCreated(controller));
        }
    }

@@ -589,7 +588,7 @@ public class MediaRouter2 {
         *
         * @param controller the controller to control the created session
         */
        public void onSessionCreated(RouteSessionController controller, Bundle controlHints) {}
        public void onSessionCreated(RouteSessionController controller) {}

        /**
         * Called when the session creation request failed.
@@ -669,10 +668,9 @@ public class MediaRouter2 {
        }

        @Override
        public void notifySessionCreated(@Nullable RouteSessionInfo sessionInfo,
                @Nullable Bundle controlHints, int requestId) {
        public void notifySessionCreated(@Nullable RouteSessionInfo sessionInfo, int requestId) {
            mHandler.sendMessage(obtainMessage(MediaRouter2::createControllerOnHandler,
                    MediaRouter2.this, sessionInfo, controlHints, requestId));
                    MediaRouter2.this, sessionInfo, requestId));
        }
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@
package android.media;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;


import com.android.internal.annotations.GuardedBy;

@@ -39,6 +42,7 @@ public class RouteSessionController {
    private final int mSessionId;
    private final String mCategory;
    private final Object mLock = new Object();
    private final Bundle mControlHints;

    private List<String> mSelectedRoutes;

@@ -55,6 +59,7 @@ public class RouteSessionController {
        mSessionId = sessionInfo.getSessionId();
        mCategory = sessionInfo.getControlCategory();
        mSelectedRoutes = sessionInfo.getSelectedRoutes();
        mControlHints = sessionInfo.getControlHints();
        // TODO: Create getters for all other types of routes
    }

@@ -73,6 +78,14 @@ public class RouteSessionController {
        return mCategory;
    }

    /**
     * @return the control hints used to control route session if available.
     */
    @Nullable
    public Bundle getControlHints() {
        return mControlHints;
    }

    /**
     * @return the list of currently selected routes
     */
Loading