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

Commit 69b07161 authored by Jeff Brown's avatar Jeff Brown
Browse files

Add media router service and integrate with remote displays.

This change adds a new media router service whose purpose is to track
global state information associated with media routes.  This service
publishes routes to the media router instance in application processes
and handles requested state changes such as selecting or unselecting
global routes.  The service also binds to remote display provider
services which can offer new remote display routes to the system.

Includes a test application for manually verifying certain aspects
of the operation of the media router service.

The remote display provider interface is essentially a stripped down
media route provider interface as defined in the support library
media router implementation.  For now, it is designed to be used only
by first parties to publish remote display routes to the system so
it is not exposed as public API in the SDK.  In the future, the remote
display provider interface will most likely be deprecated and replaced
with a more featureful media route provider interface for third
party integration, similar to what is in the support library today.

Further patch sets integrate these new capabilities into the System UI
and Settings for connecting remote displays.

Bug: 11257292
Change-Id: I31109f23f17b474d17534d0f5f4503e388b081c2
parent f3c99e88
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -251,6 +251,8 @@ LOCAL_SRC_FILES += \
	media/java/android/media/IAudioService.aidl \
	media/java/android/media/IAudioFocusDispatcher.aidl \
	media/java/android/media/IAudioRoutesObserver.aidl \
	media/java/android/media/IMediaRouterClient.aidl \
	media/java/android/media/IMediaRouterService.aidl \
	media/java/android/media/IMediaScannerListener.aidl \
	media/java/android/media/IMediaScannerService.aidl \
	media/java/android/media/IRemoteControlClient.aidl \
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class MediaRouteActionProvider extends ActionProvider {
        }
        mRouteTypes = types;
        if (types != 0) {
            mRouter.addCallback(types, mCallback);
            mRouter.addCallback(types, mCallback, MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
        }
        if (mView != null) {
            mView.setRouteTypes(mRouteTypes);
+15 −12
Original line number Diff line number Diff line
@@ -123,14 +123,14 @@ public class MediaRouteButton extends View {

        if (mToggleMode) {
            if (mRemoteActive) {
                mRouter.selectRouteInt(mRouteTypes, mRouter.getDefaultRoute());
                mRouter.selectRouteInt(mRouteTypes, mRouter.getDefaultRoute(), true);
            } else {
                final int N = mRouter.getRouteCount();
                for (int i = 0; i < N; i++) {
                    final RouteInfo route = mRouter.getRouteAt(i);
                    if ((route.getSupportedTypes() & mRouteTypes) != 0 &&
                            route != mRouter.getDefaultRoute()) {
                        mRouter.selectRouteInt(mRouteTypes, route);
                        mRouter.selectRouteInt(mRouteTypes, route, true);
                    }
                }
            }
@@ -201,7 +201,8 @@ public class MediaRouteButton extends View {

        if (mAttachedToWindow) {
            updateRouteInfo();
            mRouter.addCallback(types, mRouterCallback);
            mRouter.addCallback(types, mRouterCallback,
                    MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
        }
    }

@@ -217,8 +218,7 @@ public class MediaRouteButton extends View {
    void updateRemoteIndicator() {
        final RouteInfo selected = mRouter.getSelectedRoute(mRouteTypes);
        final boolean isRemote = selected != mRouter.getDefaultRoute();
        final boolean isConnecting = selected != null &&
                selected.getStatusCode() == RouteInfo.STATUS_CONNECTING;
        final boolean isConnecting = selected != null && selected.isConnecting();

        boolean needsRefresh = false;
        if (mRemoteActive != isRemote) {
@@ -238,7 +238,7 @@ public class MediaRouteButton extends View {
    void updateRouteCount() {
        final int N = mRouter.getRouteCount();
        int count = 0;
        boolean hasVideoRoutes = false;
        boolean scanRequired = false;
        for (int i = 0; i < N; i++) {
            final RouteInfo route = mRouter.getRouteAt(i);
            final int routeTypes = route.getSupportedTypes();
@@ -248,8 +248,9 @@ public class MediaRouteButton extends View {
                } else {
                    count++;
                }
                if ((routeTypes & MediaRouter.ROUTE_TYPE_LIVE_VIDEO) != 0) {
                    hasVideoRoutes = true;
                if (((routeTypes & MediaRouter.ROUTE_TYPE_LIVE_VIDEO
                        | MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY)) != 0) {
                    scanRequired = true;
                }
            }
        }
@@ -257,9 +258,10 @@ public class MediaRouteButton extends View {
        setEnabled(count != 0);

        // Only allow toggling if we have more than just user routes.
        // Don't toggle if we support video routes, we may have to let the dialog scan.
        mToggleMode = count == 2 && (mRouteTypes & MediaRouter.ROUTE_TYPE_LIVE_AUDIO) != 0 &&
                !hasVideoRoutes;
        // Don't toggle if we support video or remote display routes, we may have to
        // let the dialog scan.
        mToggleMode = count == 2 && (mRouteTypes & MediaRouter.ROUTE_TYPE_LIVE_AUDIO) != 0
                && !scanRequired;
    }

    @Override
@@ -313,7 +315,8 @@ public class MediaRouteButton extends View {
        super.onAttachedToWindow();
        mAttachedToWindow = true;
        if (mRouteTypes != 0) {
            mRouter.addCallback(mRouteTypes, mRouterCallback);
            mRouter.addCallback(mRouteTypes, mRouterCallback,
                    MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
            updateRouteInfo();
        }
    }
+9 −0
Original line number Diff line number Diff line
@@ -643,6 +643,15 @@ public final class Display {
                || uid == 0;
    }

    /**
     * Returns true if the display is a public presentation display.
     * @hide
     */
    public boolean isPublicPresentation() {
        return (mFlags & (Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION)) ==
                Display.FLAG_PRESENTATION;
    }

    private void updateDisplayInfoLocked() {
        // Note: The display manager caches display info objects on our behalf.
        DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId);
+3 −3
Original line number Diff line number Diff line
@@ -501,7 +501,7 @@ public class MediaRouteChooserDialogFragment extends DialogFragment {

                final RouteInfo route = (RouteInfo) item;
                if (type == VIEW_ROUTE) {
                    mRouter.selectRouteInt(mRouteTypes, route);
                    mRouter.selectRouteInt(mRouteTypes, route, true);
                    dismiss();
                } else if (type == VIEW_GROUPING_ROUTE) {
                    final Checkable c = (Checkable) view;
@@ -514,7 +514,7 @@ public class MediaRouteChooserDialogFragment extends DialogFragment {
                        if (mRouter.getSelectedRoute(mRouteTypes) == oldGroup) {
                            // Old group was selected but is now empty. Select the group
                            // we're manipulating since that's where the last route went.
                            mRouter.selectRouteInt(mRouteTypes, mEditingGroup);
                            mRouter.selectRouteInt(mRouteTypes, mEditingGroup, true);
                        }
                        oldGroup.removeRoute(route);
                        mEditingGroup.addRoute(route);
@@ -555,7 +555,7 @@ public class MediaRouteChooserDialogFragment extends DialogFragment {
                mEditingGroup = group;
                mCategoryEditingGroups = group.getCategory();
                getDialog().setCanceledOnTouchOutside(false);
                mRouter.selectRouteInt(mRouteTypes, mEditingGroup);
                mRouter.selectRouteInt(mRouteTypes, mEditingGroup, true);
                update();
                scrollToEditingGroup();
            }
Loading