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

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

Merge "MediaRouter: make route controllers return route info"

parents 106e6f42 16d80550
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -195,11 +195,15 @@ public final class MediaRoute2Info implements Parcelable {
    private String createUniqueId() {
        String uniqueId = null;
        if (mProviderId != null) {
            uniqueId = mProviderId + ":" + mId;
            uniqueId = toUniqueId(mProviderId, mId);
        }
        return uniqueId;
    }

    static String toUniqueId(String providerId, String routeId) {
        return providerId + ":" + routeId;
    }

    /**
     * Returns true if the route info has all of the required field.
     * A route info only obtained from {@link com.android.server.media.MediaRouterService}
+29 −17
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class MediaRouter2 {

    private final String mPackageName;
    @GuardedBy("sLock")
    private final Map<String, MediaRoute2Info> mRoutes = new HashMap<>();
    final Map<String, MediaRoute2Info> mRoutes = new HashMap<>();

    @GuardedBy("sLock")
    private List<String> mControlCategories = Collections.emptyList();
@@ -678,8 +678,6 @@ public class MediaRouter2 {
     * A class to control media route 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}.
     *
     * @hide
     */
    public final class RouteSessionController {
        private final Object mLock = new Object();
@@ -724,42 +722,42 @@ public class MediaRouter2 {
        }

        /**
         * @return the unmodifiable list of IDs of currently selected routes
         * @return the unmodifiable list of currently selected routes
         */
        @NonNull
        public List<String> getSelectedRoutes() {
        public List<MediaRoute2Info> getSelectedRoutes() {
            synchronized (mLock) {
                return Collections.unmodifiableList(mSessionInfo.getSelectedRoutes());
                return getRoutesWithIdsLocked(mSessionInfo.getSelectedRoutes());
            }
        }

        /**
         * @return the unmodifiable list of IDs of selectable routes for the session.
         * @return the unmodifiable list of selectable routes for the session.
         */
        @NonNull
        public List<String> getSelectableRoutes() {
        public List<MediaRoute2Info> getSelectableRoutes() {
            synchronized (mLock) {
                return Collections.unmodifiableList(mSessionInfo.getSelectableRoutes());
                return getRoutesWithIdsLocked(mSessionInfo.getSelectableRoutes());
            }
        }

        /**
         * @return the unmodifiable list of IDs of deselectable routes for the session.
         * @return the unmodifiable list of deselectable routes for the session.
         */
        @NonNull
        public List<String> getDeselectableRoutes() {
        public List<MediaRoute2Info> getDeselectableRoutes() {
            synchronized (mLock) {
                return Collections.unmodifiableList(mSessionInfo.getDeselectableRoutes());
                return getRoutesWithIdsLocked(mSessionInfo.getDeselectableRoutes());
            }
        }

        /**
         * @return the unmodifiable list of IDs of transferrable routes for the session.
         * @return the unmodifiable list of transferrable routes for the session.
         */
        @NonNull
        public List<String> getTransferrableRoutes() {
        public List<MediaRoute2Info> getTransferrableRoutes() {
            synchronized (mLock) {
                return Collections.unmodifiableList(mSessionInfo.getTransferrableRoutes());
                return getRoutesWithIdsLocked(mSessionInfo.getTransferrableRoutes());
            }
        }

@@ -784,7 +782,7 @@ public class MediaRouter2 {
         * @see #getSelectedRoutes()
         * @see SessionCallback#onSessionInfoChanged
         */
        public void selectRoute(MediaRoute2Info route) {
        public void selectRoute(@NonNull MediaRoute2Info route) {
            // TODO: Implement this when the actual connection logic is implemented.
        }

@@ -796,7 +794,7 @@ public class MediaRouter2 {
         * @see #getSelectedRoutes()
         * @see SessionCallback#onSessionInfoChanged
         */
        public void deselectRoute(MediaRoute2Info route) {
        public void deselectRoute(@NonNull MediaRoute2Info route) {
            // TODO: Implement this when the actual connection logic is implemented.
        }

@@ -817,6 +815,20 @@ public class MediaRouter2 {
            }
            // TODO: Use stopMedia variable when the actual connection logic is implemented.
        }

        private List<MediaRoute2Info> getRoutesWithIdsLocked(List<String> routeIds) {
            List<MediaRoute2Info> routes = new ArrayList<>();
            synchronized (mLock) {
                for (String routeId : routeIds) {
                    MediaRoute2Info route = mRoutes.get(
                            MediaRoute2Info.toUniqueId(mSessionInfo.mProviderId, routeId));
                    if (route != null) {
                        routes.add(route);
                    }
                }
            }
            return Collections.unmodifiableList(routes);
        }
    }

    final class RouteCallbackRecord {
+3 −3
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ public class MediaRouter2Test {
            @Override
            public void onSessionCreated(RouteSessionController controller) {
                assertNotNull(controller);
                assertTrue(controller.getSelectedRoutes().contains(ROUTE_ID1));
                assertTrue(createRouteMap(controller.getSelectedRoutes()).containsKey(ROUTE_ID1));
                assertTrue(TextUtils.equals(CATEGORY_SAMPLE, controller.getControlCategory()));
                successLatch.countDown();
            }
@@ -384,8 +384,8 @@ public class MediaRouter2Test {
            RouteSessionController controller2 = createdControllers.get(1);

            assertNotEquals(controller1.getSessionId(), controller2.getSessionId());
            assertTrue(controller1.getSelectedRoutes().contains(ROUTE_ID1));
            assertTrue(controller2.getSelectedRoutes().contains(ROUTE_ID2));
            assertTrue(createRouteMap(controller1.getSelectedRoutes()).containsKey(ROUTE_ID1));
            assertTrue(createRouteMap(controller2.getSelectedRoutes()).containsKey(ROUTE_ID2));
            assertTrue(TextUtils.equals(CATEGORY_SAMPLE, controller1.getControlCategory()));
            assertTrue(TextUtils.equals(CATEGORY_SAMPLE, controller2.getControlCategory()));
        } finally {