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

Commit 9d784f9e authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Add flag to show a slider UI for routing session volume changes

This change is a non-functional refactor that enables the routing
framework to flag that a UI slider should be associated with a given
session update. The purpose of this change is to show the SysUI volume
slider when a mirroring session's volume changes as a result of a
hardware volume key press.

This change only adds the plumbing. The actual functional change to
populate the flag to true comes in a later change.

The approach used in this change mimics the approach used by
AudioManager#FLAG_SHOW_UI and MediaSessionManager#RemoteSessionCallback.

Bug: b/396394220
Test: atest CtsMediaRouterTestCases
Flag: EXEMPT refactor
Change-Id: I594c110e55eab0b77a7a1e685c55023c5704a9da
parent 0e14209a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import android.media.AppId;
 */
oneway interface IMediaRouter2Manager {
    void notifySessionCreated(int requestId, in RoutingSessionInfo session);
    void notifySessionUpdated(in RoutingSessionInfo session);
    void notifySessionUpdated(in RoutingSessionInfo session, in boolean shouldShowVolumeUi);
    void notifySessionReleased(in RoutingSessionInfo session);
    void notifyDiscoveryPreferenceChanged(String packageName,
            in RouteDiscoveryPreference discoveryPreference);
+33 −11
Original line number Diff line number Diff line
@@ -1332,7 +1332,7 @@ public final class MediaRouter2 {
        mSystemController.setRoutingSessionInfo(ensureClientPackageNameForSystemSession(
                currentSystemSessionInfo, mContext.getPackageName()));
        if (!oldInfo.equals(currentSystemSessionInfo)) {
            notifyControllerUpdated(mSystemController);
            notifyControllerUpdated(mSystemController, /* shouldShowVolumeUi= */ false);
        }
    }

@@ -1396,7 +1396,7 @@ public final class MediaRouter2 {
                    MediaRoute2Info currentRoute = routesMap.get(selectedRoute);
                    MediaRoute2Info oldRoute = mPreviousUnfilteredRoutes.get(selectedRoute);
                    if (!currentRoute.equals(oldRoute)) {
                        notifyControllerUpdated(controller);
                        notifyControllerUpdated(controller, /* shouldShowVolumeUi= */ false);
                        break;
                    }
                }
@@ -1527,7 +1527,7 @@ public final class MediaRouter2 {
                                sessionInfo, mImpl.getClientPackageName());
            }
            controller.setRoutingSessionInfo(sessionInfo);
            notifyControllerUpdated(controller);
            notifyControllerUpdated(controller, /* shouldShowVolumeUi= */ false);
        }
    }

@@ -1775,9 +1775,10 @@ public final class MediaRouter2 {
        }
    }

    private void notifyControllerUpdated(RoutingController controller) {
    private void notifyControllerUpdated(RoutingController controller, boolean shouldShowVolumeUi) {
        for (ControllerCallbackRecord record : mControllerCallbackRecords) {
            record.mExecutor.execute(() -> record.mCallback.onControllerUpdated(controller));
            record.mExecutor.execute(
                    () -> record.mCallback.onControllerUpdated(controller, shouldShowVolumeUi));
        }
    }

@@ -1960,6 +1961,23 @@ public final class MediaRouter2 {
         * @see #getSystemController()
         */
        public void onControllerUpdated(@NonNull RoutingController controller) {}

        /**
         * Equivalent to {@link #onControllerUpdated(RoutingController)} except it adds {@code
         * shouldShowVolumeUi}, which indicates that a UI affordance should be presented as a result
         * of this controller update. Likely, because the update is the result of a HW volume key
         * press.
         *
         * <p>By default, this method invokes {@link #onControllerUpdated(RoutingController)}, which
         * means it's sufficient to override any of the methods in this class to receive controller
         * update events.
         *
         * @hide
         */
        public void onControllerUpdated(
                @NonNull RoutingController controller, boolean shouldShowVolumeUi) {
            this.onControllerUpdated(controller);
        }
    }

    /**
@@ -3704,7 +3722,8 @@ public final class MediaRouter2 {
            notifyTransferFailure(route);
        }

        private void onSessionUpdated(@NonNull RoutingSessionInfo session) {
        private void onSessionUpdated(
                @NonNull RoutingSessionInfo session, boolean shouldShowVolumeUi) {
            if (!isSessionRelatedToTargetPackageName(session)) {
                return;
            }
@@ -3717,7 +3736,7 @@ public final class MediaRouter2 {
            } else {
                controller = new RoutingController(session);
            }
            notifyControllerUpdated(controller);
            notifyControllerUpdated(controller, shouldShowVolumeUi);
        }

        /**
@@ -3773,7 +3792,8 @@ public final class MediaRouter2 {
            }
        }

        private void onSessionUpdatedOnHandler(@NonNull RoutingSessionInfo updatedSession) {
        private void onSessionUpdatedOnHandler(
                @NonNull RoutingSessionInfo updatedSession, boolean shouldShowVolumeUi) {
            for (MediaRouter2Manager.TransferRequest request : mTransferRequests) {
                String sessionId = request.mOldSessionInfo.getId();
                if (!TextUtils.equals(sessionId, updatedSession.getId())) {
@@ -3785,7 +3805,7 @@ public final class MediaRouter2 {
                    break;
                }
            }
            this.onSessionUpdated(updatedSession);
            this.onSessionUpdated(updatedSession, shouldShowVolumeUi);
        }

        private void onSessionReleasedOnHandler(@NonNull RoutingSessionInfo session) {
@@ -3922,12 +3942,14 @@ public final class MediaRouter2 {
            }

            @Override
            public void notifySessionUpdated(RoutingSessionInfo routingSessionInfo) {
            public void notifySessionUpdated(
                    RoutingSessionInfo routingSessionInfo, boolean shouldShowVolumeUi) {
                mHandler.sendMessage(
                        obtainMessage(
                                ProxyMediaRouter2Impl::onSessionUpdatedOnHandler,
                                ProxyMediaRouter2Impl.this,
                                routingSessionInfo));
                                routingSessionInfo,
                                shouldShowVolumeUi));
            }

            @Override
+8 −3
Original line number Diff line number Diff line
@@ -1116,9 +1116,14 @@ public final class MediaRouter2Manager {
        }

        @Override
        public void notifySessionUpdated(RoutingSessionInfo session) {
            mHandler.sendMessage(obtainMessage(MediaRouter2Manager::handleSessionsUpdatedOnHandler,
                    MediaRouter2Manager.this, session));
        public void notifySessionUpdated(
                RoutingSessionInfo session, boolean ignoredShouldShowVolumeUi) {
            // This class doesn't support shouldShowVolumeUi. MediaRouter2 does.
            mHandler.sendMessage(
                    obtainMessage(
                            MediaRouter2Manager::handleSessionsUpdatedOnHandler,
                            MediaRouter2Manager.this,
                            session));
        }

        @Override
+6 −1
Original line number Diff line number Diff line
@@ -198,11 +198,16 @@ abstract class MediaRoute2Provider {
         *     affected by global session changes. This set may only be non-empty when the {@code
         *     sessionInfo} is for the global session, and therefore has no {@link
         *     RoutingSessionInfo#getClientPackageName()}.
         * @param shouldShowVolumeSystemUi Whether a volume UI affordance should be presented as a
         *     result of this session update. For example, this session update may be the result of
         *     a volume change in response to a volume hardware key press, in which case a volume
         *     slider should be presented.
         */
        void onSessionUpdated(
                @NonNull MediaRoute2Provider provider,
                @NonNull RoutingSessionInfo sessionInfo,
                Set<String> packageNamesWithRoutingSessionOverrides);
                Set<String> packageNamesWithRoutingSessionOverrides,
                boolean shouldShowVolumeSystemUi);

        void onSessionReleased(@NonNull MediaRoute2Provider provider,
                @NonNull RoutingSessionInfo sessionInfo);
+2 −1
Original line number Diff line number Diff line
@@ -697,7 +697,8 @@ final class MediaRoute2ProviderServiceProxy extends MediaRoute2Provider {
                        mCallback::onSessionUpdated,
                        this,
                        session,
                        /* packageNamesWithRoutingSessionOverrides= */ Set.of()));
                        /* packageNamesWithRoutingSessionOverrides= */ Set.of(),
                        /* shouldShowVolumeUi= */ false));
    }

    private void dispatchSessionReleased(RoutingSessionInfo session) {
Loading