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

Commit f829e6f1 authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Rename RouteSessionInfo and RouteSessionController

This CL renames following classes:
 - RouteSessionInfo to RoutingSessionInfo
 - RouteSessionController to RoutingController

Bug: 147527788
Test: atest mediaroutertest
Change-Id: I6d6c997d9119b668bd8879f2f5a8ca266ddbeccc
parent 459dee33
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package android.media;

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

/**
@@ -26,7 +26,7 @@ import android.os.Bundle;
 */
oneway interface IMediaRoute2ProviderClient {
    void updateState(in MediaRoute2ProviderInfo providerInfo,
            in List<RouteSessionInfo> sessionInfos);
    void notifySessionCreated(in @nullable RouteSessionInfo sessionInfo, long requestId);
    void notifySessionInfoChanged(in RouteSessionInfo sessionInfo);
            in List<RoutingSessionInfo> sessionInfos);
    void notifySessionCreated(in @nullable RoutingSessionInfo sessionInfo, long requestId);
    void notifySessionInfoChanged(in RoutingSessionInfo sessionInfo);
}
+4 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package android.media;

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

/**
@@ -28,7 +28,7 @@ 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, int requestId);
    void notifySessionInfoChanged(in RouteSessionInfo sessionInfo);
    void notifySessionReleased(in RouteSessionInfo sessionInfo);
    void notifySessionCreated(in @nullable RoutingSessionInfo sessionInfo, int requestId);
    void notifySessionInfoChanged(in RoutingSessionInfo sessionInfo);
    void notifySessionReleased(in RoutingSessionInfo sessionInfo);
}
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.media.IMediaRouterClient;
import android.media.MediaRoute2Info;
import android.media.MediaRouterClientState;
import android.media.RouteDiscoveryPreference;
import android.media.RouteSessionInfo;
import android.media.RoutingSessionInfo;

/**
 * {@hide}
@@ -70,5 +70,5 @@ interface IMediaRouterService {
    void requestUpdateVolume2Manager(IMediaRouter2Manager manager,
            in MediaRoute2Info route, int direction);

    List<RouteSessionInfo> getActiveSessions(IMediaRouter2Manager manager);
    List<RoutingSessionInfo> getActiveSessions(IMediaRouter2Manager manager);
}
+20 −19
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public abstract class MediaRoute2ProviderService extends Service {
    private MediaRoute2ProviderInfo mProviderInfo;

    @GuardedBy("mSessionLock")
    private ArrayMap<String, RouteSessionInfo> mSessionInfo = new ArrayMap<>();
    private ArrayMap<String, RoutingSessionInfo> mSessionInfo = new ArrayMap<>();

    public MediaRoute2ProviderService() {
        mHandler = new Handler(Looper.getMainLooper());
@@ -122,7 +122,7 @@ public abstract class MediaRoute2ProviderService extends Service {
     * @hide
     */
    @Nullable
    public final RouteSessionInfo getSessionInfo(@NonNull String sessionId) {
    public final RoutingSessionInfo getSessionInfo(@NonNull String sessionId) {
        if (TextUtils.isEmpty(sessionId)) {
            throw new IllegalArgumentException("sessionId must not be empty");
        }
@@ -132,11 +132,11 @@ public abstract class MediaRoute2ProviderService extends Service {
    }

    /**
     * Gets the list of {@link RouteSessionInfo session info} that the provider service maintains.
     * Gets the list of {@link RoutingSessionInfo session info} that the provider service maintains.
     * @hide
     */
    @NonNull
    public final List<RouteSessionInfo> getAllSessionInfo() {
    public final List<RoutingSessionInfo> getAllSessionInfo() {
        synchronized (mSessionLock) {
            return new ArrayList<>(mSessionInfo.values());
        }
@@ -149,10 +149,10 @@ public abstract class MediaRoute2ProviderService extends Service {
     * session info changes.
     *
     * @param sessionInfo new session information
     * @see #notifySessionCreated(RouteSessionInfo, long)
     * @see #notifySessionCreated(RoutingSessionInfo, long)
     * @hide
     */
    public final void updateSessionInfo(@NonNull RouteSessionInfo sessionInfo) {
    public final void updateSessionInfo(@NonNull RoutingSessionInfo sessionInfo) {
        Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
        String sessionId = sessionInfo.getId();

@@ -173,7 +173,7 @@ public abstract class MediaRoute2ProviderService extends Service {
     * TODO: This method is temporary, only created for tests. Remove when the alternative is ready.
     * @hide
     */
    public final void notifySessionInfoChanged(@NonNull RouteSessionInfo sessionInfo) {
    public final void notifySessionInfoChanged(@NonNull RoutingSessionInfo sessionInfo) {
        Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");

        String sessionId = sessionInfo.getId();
@@ -201,7 +201,7 @@ public abstract class MediaRoute2ProviderService extends Service {
     * controlled, pass a {@link Bundle} that contains how to control it.
     *
     * @param sessionInfo information of the new session.
     *                    The {@link RouteSessionInfo#getId() id} of the session must be
     *                    The {@link RoutingSessionInfo#getId() id} of the session must be
     *                    unique. Pass {@code null} to reject the request or inform clients that
     *                    session creation is failed.
     * @param requestId id of the previous request to create this session
@@ -209,7 +209,8 @@ public abstract class MediaRoute2ProviderService extends Service {
     */
    // TODO: fail reason?
    // TODO: Maybe better to create notifySessionCreationFailed?
    public final void notifySessionCreated(@Nullable RouteSessionInfo sessionInfo, long requestId) {
    public final void notifySessionCreated(@Nullable RoutingSessionInfo sessionInfo,
            long requestId) {
        if (sessionInfo != null) {
            String sessionId = sessionInfo.getId();
            synchronized (mSessionLock) {
@@ -237,7 +238,7 @@ public abstract class MediaRoute2ProviderService extends Service {
     * {@link #onDestroySession} is called if the session is released.
     *
     * @param sessionId id of the session to be released
     * @see #onDestroySession(String, RouteSessionInfo)
     * @see #onDestroySession(String, RoutingSessionInfo)
     * @hide
     */
    public final void releaseSession(@NonNull String sessionId) {
@@ -245,7 +246,7 @@ public abstract class MediaRoute2ProviderService extends Service {
            throw new IllegalArgumentException("sessionId must not be empty");
        }
        //TODO: notify media router service of release.
        RouteSessionInfo sessionInfo;
        RoutingSessionInfo sessionInfo;
        synchronized (mSessionLock) {
            sessionInfo = mSessionInfo.remove(sessionId);
        }
@@ -259,10 +260,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, long)}
     * session info. Call {@link #notifySessionCreated(RoutingSessionInfo, long)}
     * 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, long)}
     * as session info in {@link #notifySessionCreated(RoutingSessionInfo, long)}
     * with the given {@code requestId}.
     *
     * @param packageName the package name of the application that selected the route
@@ -285,18 +286,18 @@ public abstract class MediaRoute2ProviderService extends Service {
     * @hide
     */
    public abstract void onDestroySession(@NonNull String sessionId,
            @NonNull RouteSessionInfo lastSessionInfo);
            @NonNull RoutingSessionInfo lastSessionInfo);

    //TODO: make a way to reject the request
    /**
     * Called when a client requests selecting a route for the session.
     * After the route is selected, call {@link #updateSessionInfo(RouteSessionInfo)} to update
     * After the route is selected, call {@link #updateSessionInfo(RoutingSessionInfo)} 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 #updateSessionInfo(RouteSessionInfo)
     * @see #updateSessionInfo(RoutingSessionInfo)
     * @hide
     */
    public abstract void onSelectRoute(@NonNull String sessionId, @NonNull String routeId);
@@ -304,7 +305,7 @@ public abstract class MediaRoute2ProviderService extends Service {
    //TODO: make a way to reject the request
    /**
     * Called when a client requests deselecting a route from the session.
     * After the route is deselected, call {@link #updateSessionInfo(RouteSessionInfo)} to update
     * After the route is deselected, call {@link #updateSessionInfo(RoutingSessionInfo)} to update
     * session info and call {@link #updateProviderInfo(MediaRoute2ProviderInfo)} to notify
     * clients of updated session info.
     *
@@ -317,7 +318,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 #updateSessionInfo(RouteSessionInfo)} to update
     * After the transfer is finished, call {@link #updateSessionInfo(RoutingSessionInfo)} to update
     * session info and call {@link #updateProviderInfo(MediaRoute2ProviderInfo)} to notify
     * clients of updated session info.
     *
@@ -377,7 +378,7 @@ public abstract class MediaRoute2ProviderService extends Service {
            return;
        }

        List<RouteSessionInfo> sessionInfos;
        List<RoutingSessionInfo> sessionInfos;
        synchronized (mSessionLock) {
            sessionInfos = new ArrayList<>(mSessionInfo.values());
        }
+39 −39
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public class MediaRouter2 {
    Client2 mClient;

    @GuardedBy("sLock")
    private Map<String, RouteSessionController> mSessionControllers = new ArrayMap<>();
    private Map<String, RoutingController> mRoutingControllers = new ArrayMap<>();

    private AtomicInteger mSessionCreationRequestCnt = new AtomicInteger(1);

@@ -241,7 +241,7 @@ public class MediaRouter2 {
    }

    /**
     * Registers a callback to get updates on creations and changes of route sessions.
     * Registers a callback to get updates on creations and changes of routing sessions.
     * If you register the same callback twice or more, it will be ignored.
     *
     * @param executor the executor to execute the callback on
@@ -455,7 +455,7 @@ public class MediaRouter2 {
     * <p>
     * Pass {@code null} to sessionInfo for the failure case.
     */
    void createControllerOnHandler(@Nullable RouteSessionInfo sessionInfo, int requestId) {
    void createControllerOnHandler(@Nullable RoutingSessionInfo sessionInfo, int requestId) {
        SessionCreationRequest matchingRequest = null;
        for (SessionCreationRequest request : mSessionCreationRequests) {
            if (request.mRequestId == requestId) {
@@ -502,23 +502,23 @@ public class MediaRouter2 {
        }

        if (sessionInfo != null) {
            RouteSessionController controller = new RouteSessionController(sessionInfo);
            RoutingController controller = new RoutingController(sessionInfo);
            synchronized (sRouterLock) {
                mSessionControllers.put(controller.getSessionId(), controller);
                mRoutingControllers.put(controller.getSessionId(), controller);
            }
            notifySessionCreated(controller);
        }
    }

    void changeSessionInfoOnHandler(RouteSessionInfo sessionInfo) {
    void changeSessionInfoOnHandler(RoutingSessionInfo sessionInfo) {
        if (sessionInfo == null) {
            Log.w(TAG, "changeSessionInfoOnHandler: Ignoring null sessionInfo.");
            return;
        }

        RouteSessionController matchingController;
        RoutingController matchingController;
        synchronized (sRouterLock) {
            matchingController = mSessionControllers.get(sessionInfo.getId());
            matchingController = mRoutingControllers.get(sessionInfo.getId());
        }

        if (matchingController == null) {
@@ -527,27 +527,27 @@ public class MediaRouter2 {
            return;
        }

        RouteSessionInfo oldInfo = matchingController.getRouteSessionInfo();
        RoutingSessionInfo oldInfo = matchingController.getRoutingSessionInfo();
        if (!TextUtils.equals(oldInfo.getProviderId(), sessionInfo.getProviderId())) {
            Log.w(TAG, "changeSessionInfoOnHandler: Provider IDs are not matched. old="
                    + oldInfo.getProviderId() + ", new=" + sessionInfo.getProviderId());
            return;
        }

        matchingController.setRouteSessionInfo(sessionInfo);
        matchingController.setRoutingSessionInfo(sessionInfo);
        notifySessionInfoChanged(matchingController, oldInfo, sessionInfo);
    }

    void releaseControllerOnHandler(RouteSessionInfo sessionInfo) {
    void releaseControllerOnHandler(RoutingSessionInfo sessionInfo) {
        if (sessionInfo == null) {
            Log.w(TAG, "releaseControllerOnHandler: Ignoring null sessionInfo.");
            return;
        }

        final String uniqueSessionId = sessionInfo.getId();
        RouteSessionController matchingController;
        RoutingController matchingController;
        synchronized (sRouterLock) {
            matchingController = mSessionControllers.get(uniqueSessionId);
            matchingController = mRoutingControllers.get(uniqueSessionId);
        }

        if (matchingController == null) {
@@ -558,7 +558,7 @@ public class MediaRouter2 {
            return;
        }

        RouteSessionInfo oldInfo = matchingController.getRouteSessionInfo();
        RoutingSessionInfo oldInfo = matchingController.getRoutingSessionInfo();
        if (!TextUtils.equals(oldInfo.getProviderId(), sessionInfo.getProviderId())) {
            Log.w(TAG, "releaseControllerOnHandler: Provider IDs are not matched. old="
                    + oldInfo.getProviderId() + ", new=" + sessionInfo.getProviderId());
@@ -566,7 +566,7 @@ public class MediaRouter2 {
        }

        synchronized (sRouterLock) {
            mSessionControllers.remove(uniqueSessionId, matchingController);
            mRoutingControllers.remove(uniqueSessionId, matchingController);
        }
        matchingController.release();
        notifyControllerReleased(matchingController);
@@ -610,7 +610,7 @@ public class MediaRouter2 {
        }
    }

    private void notifySessionCreated(RouteSessionController controller) {
    private void notifySessionCreated(RoutingController controller) {
        for (SessionCallbackRecord record: mSessionCallbackRecords) {
            record.mExecutor.execute(
                    () -> record.mSessionCallback.onSessionCreated(controller));
@@ -624,8 +624,8 @@ public class MediaRouter2 {
        }
    }

    private void notifySessionInfoChanged(RouteSessionController controller,
            RouteSessionInfo oldInfo, RouteSessionInfo newInfo) {
    private void notifySessionInfoChanged(RoutingController controller,
            RoutingSessionInfo oldInfo, RoutingSessionInfo newInfo) {
        for (SessionCallbackRecord record: mSessionCallbackRecords) {
            record.mExecutor.execute(
                    () -> record.mSessionCallback.onSessionInfoChanged(
@@ -633,7 +633,7 @@ public class MediaRouter2 {
        }
    }

    private void notifyControllerReleased(RouteSessionController controller) {
    private void notifyControllerReleased(RoutingController controller) {
        for (SessionCallbackRecord record: mSessionCallbackRecords) {
            record.mExecutor.execute(
                    () -> record.mSessionCallback.onSessionReleased(controller));
@@ -678,11 +678,11 @@ public class MediaRouter2 {
     */
    public static class SessionCallback {
        /**
         * Called when the route session is created by the route provider.
         * Called when the routing session is created by the route provider.
         *
         * @param controller the controller to control the created session
         */
        public void onSessionCreated(@NonNull RouteSessionController controller) {}
        public void onSessionCreated(@NonNull RoutingController controller) {}

        /**
         * Called when the session creation request failed.
@@ -702,45 +702,45 @@ public class MediaRouter2 {
         * TODO: (Discussion) Do we really need newInfo? The controller has the newInfo.
         *       However. there can be timing issue if there is no newInfo.
         */
        public void onSessionInfoChanged(@NonNull RouteSessionController controller,
                @NonNull RouteSessionInfo oldInfo,
                @NonNull RouteSessionInfo newInfo) {}
        public void onSessionInfoChanged(@NonNull RoutingController controller,
                @NonNull RoutingSessionInfo oldInfo,
                @NonNull RoutingSessionInfo newInfo) {}

        /**
         * Called when the session is released by {@link MediaRoute2ProviderService}.
         * Before this method is called, the controller would be released by the system,
         * which means the {@link RouteSessionController#isReleased()} will always return true
         * which means the {@link RoutingController#isReleased()} will always return true
         * for the {@code controller} here.
         * <p>
         * Note: Calling {@link RouteSessionController#release()} will <em>NOT</em> trigger
         * Note: Calling {@link RoutingController#release()} will <em>NOT</em> trigger
         * this method to be called.
         *
         * TODO: Add tests for checking whether this method is called.
         * TODO: When service process dies, this should be called.
         *
         * @see RouteSessionController#isReleased()
         * @see RoutingController#isReleased()
         */
        public void onSessionReleased(@NonNull RouteSessionController controller) {}
        public void onSessionReleased(@NonNull RoutingController controller) {}
    }

    /**
     * A class to control media route session in media route provider.
     * A class to control media routing session in media route provider.
     * For example, selecting/deselcting/transferring routes to session can be done through this
     * class. Instances are created by {@link MediaRouter2}.
     *
     * TODO: Need to add toString()
     * @hide
     */
    public final class RouteSessionController {
    public final class RoutingController {
        private final Object mControllerLock = new Object();

        @GuardedBy("mLock")
        private RouteSessionInfo mSessionInfo;
        private RoutingSessionInfo mSessionInfo;

        @GuardedBy("mLock")
        private volatile boolean mIsReleased;

        RouteSessionController(@NonNull RouteSessionInfo sessionInfo) {
        RoutingController(@NonNull RoutingSessionInfo sessionInfo) {
            mSessionInfo = sessionInfo;
        }

@@ -764,7 +764,7 @@ public class MediaRouter2 {
        }

        /**
         * @return the control hints used to control route session if available.
         * @return the control hints used to control routing session if available.
         */
        @Nullable
        public Bundle getControlHints() {
@@ -986,7 +986,7 @@ public class MediaRouter2 {

            Client2 client;
            synchronized (sRouterLock) {
                mSessionControllers.remove(getSessionId(), this);
                mRoutingControllers.remove(getSessionId(), this);
                client = mClient;
            }
            if (client != null) {
@@ -1003,13 +1003,13 @@ public class MediaRouter2 {
         * @hide
         */
        @NonNull
        public RouteSessionInfo getRouteSessionInfo() {
        public RoutingSessionInfo getRoutingSessionInfo() {
            synchronized (mControllerLock) {
                return mSessionInfo;
            }
        }

        void setRouteSessionInfo(@NonNull RouteSessionInfo info) {
        void setRoutingSessionInfo(@NonNull RoutingSessionInfo info) {
            synchronized (mControllerLock) {
                mSessionInfo = info;
            }
@@ -1125,19 +1125,19 @@ public class MediaRouter2 {
        }

        @Override
        public void notifySessionCreated(@Nullable RouteSessionInfo sessionInfo, int requestId) {
        public void notifySessionCreated(@Nullable RoutingSessionInfo sessionInfo, int requestId) {
            mHandler.sendMessage(obtainMessage(MediaRouter2::createControllerOnHandler,
                    MediaRouter2.this, sessionInfo, requestId));
        }

        @Override
        public void notifySessionInfoChanged(@Nullable RouteSessionInfo sessionInfo) {
        public void notifySessionInfoChanged(@Nullable RoutingSessionInfo sessionInfo) {
            mHandler.sendMessage(obtainMessage(MediaRouter2::changeSessionInfoOnHandler,
                    MediaRouter2.this, sessionInfo));
        }

        @Override
        public void notifySessionReleased(RouteSessionInfo sessionInfo) {
        public void notifySessionReleased(RoutingSessionInfo sessionInfo) {
            mHandler.sendMessage(obtainMessage(MediaRouter2::releaseControllerOnHandler,
                    MediaRouter2.this, sessionInfo));
        }
Loading