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

Commit 31f25dbb authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "Use MediaSession remote actions" into main

parents cc98c40b 22657b32
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -302,6 +302,13 @@ class PipMediaController(private val mContext: Context, private val mMainHandler
        setActiveMediaController(null)
    }

    /**
     * Returns {@code true} if the pinned Activity has an active associated MediaSession.
     */
    fun hasActiveMediaSession(): Boolean {
        return mMediaController != null
    }

    /**
     * Sets the active media controller for the top PiP activity.
     */
+10 −0
Original line number Diff line number Diff line
@@ -325,6 +325,16 @@ object PipUtils {
        return isPip2ExperimentEnabled as Boolean
    }

    private var isPipUmoExperienceEnabled: Boolean? = null

    @JvmStatic
    fun isPipUmoExperienceEnabled(): Boolean {
        if (isPipUmoExperienceEnabled == null) {
            isPipUmoExperienceEnabled = Flags.enablePipUmoExperience()
        }
        return isPipUmoExperienceEnabled as Boolean
    }

    /**
     * Returns true if the system theme is the dark theme.
     */
+3 −1
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ public abstract class Pip2Module {
            PipAppOpsListener pipAppOpsListener,
            PhonePipMenuController pipMenuController,
            PipUiEventLogger pipUiEventLogger,
            PipMediaController pipMediaController,
            PipSurfaceTransactionHelper pipSurfaceTransactionHelper,
            @ShellMainThread ShellExecutor mainExecutor) {
        if (!PipUtils.isPip2ExperimentEnabled()) {
@@ -145,7 +146,8 @@ public abstract class Pip2Module {
                    displayInsetsController, pipBoundsState, pipBoundsAlgorithm,
                    pipDisplayLayoutState, pipScheduler, taskStackListener, shellTaskOrganizer,
                    pipTransitionState, pipTouchHandler, pipAppOpsListener, pipMenuController,
                    pipUiEventLogger, pipSurfaceTransactionHelper, mainExecutor));
                    pipUiEventLogger, pipMediaController, pipSurfaceTransactionHelper,
                    mainExecutor));
        }
    }

+7 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.wm.shell.common.pip.PipMediaController;
import com.android.wm.shell.common.pip.PipMediaController.ActionListener;
import com.android.wm.shell.common.pip.PipMenuController;
import com.android.wm.shell.common.pip.PipUiEventLogger;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.protolog.ShellProtoLogGroup;

import java.io.PrintWriter;
@@ -486,6 +487,12 @@ public class PhonePipMenuController implements PipMenuController,
     * @return the best set of actions to show in the PiP menu.
     */
    private List<RemoteAction> resolveMenuActions() {
        // If UMO Experience is enabled, default to MediaSession actions if present.
        // Note that mMediaActions can be pulled asynchronously, we use the active media session
        // check here instead.
        if (PipUtils.isPipUmoExperienceEnabled() && mMediaController.hasActiveMediaSession()) {
            return mMediaActions;
        }
        if (isValidActions(mAppActions)) {
            return mAppActions;
        }
+8 −1
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import com.android.wm.shell.common.pip.PipAppOpsListener;
import com.android.wm.shell.common.pip.PipBoundsAlgorithm;
import com.android.wm.shell.common.pip.PipBoundsState;
import com.android.wm.shell.common.pip.PipDisplayLayoutState;
import com.android.wm.shell.common.pip.PipMediaController;
import com.android.wm.shell.common.pip.PipUiEventLogger;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.pip.Pip;
@@ -109,6 +110,7 @@ public class PipController implements ConfigurationChangeListener,
    private final ShellExecutor mMainExecutor;
    private final PipImpl mImpl;
    private final List<Consumer<Boolean>> mOnIsInPipStateChangedListeners = new ArrayList<>();
    private final PipMediaController mMediaController;

    // Wrapper for making Binder calls into PiP animation listener hosted in launcher's Recents.
    @Nullable private PipAnimationListener mPipRecentsAnimationListener;
@@ -156,6 +158,7 @@ public class PipController implements ConfigurationChangeListener,
            PipAppOpsListener pipAppOpsListener,
            PhonePipMenuController pipMenuController,
            PipUiEventLogger pipUiEventLogger,
            PipMediaController pipMediaController,
            PipSurfaceTransactionHelper pipSurfaceTransactionHelper,
            ShellExecutor mainExecutor) {
        mContext = context;
@@ -175,6 +178,7 @@ public class PipController implements ConfigurationChangeListener,
        mPipAppOpsListener = pipAppOpsListener;
        mPipMenuController = pipMenuController;
        mPipUiEventLogger = pipUiEventLogger;
        mMediaController = pipMediaController;
        mPipSurfaceTransactionHelper = pipSurfaceTransactionHelper;
        mMainExecutor = mainExecutor;
        mImpl = new PipImpl();
@@ -204,6 +208,7 @@ public class PipController implements ConfigurationChangeListener,
            PipAppOpsListener pipAppOpsListener,
            PhonePipMenuController pipMenuController,
            PipUiEventLogger pipUiEventLogger,
            PipMediaController pipMediaController,
            PipSurfaceTransactionHelper pipSurfaceTransactionHelper,
            ShellExecutor mainExecutor) {
        if (!context.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
@@ -215,7 +220,8 @@ public class PipController implements ConfigurationChangeListener,
                displayController, displayInsetsController, pipBoundsState, pipBoundsAlgorithm,
                pipDisplayLayoutState, pipScheduler, taskStackListener, shellTaskOrganizer,
                pipTransitionState, pipTouchHandler, pipAppOpsListener, pipMenuController,
                pipUiEventLogger, pipSurfaceTransactionHelper, mainExecutor);
                pipUiEventLogger, pipMediaController, pipSurfaceTransactionHelper,
                mainExecutor);
    }

    public PipImpl getPipImpl() {
@@ -515,6 +521,7 @@ public class PipController implements ConfigurationChangeListener,
                if (taskInfo != null && taskInfo.topActivity != null) {
                    mPipAppOpsListener.onActivityPinned(taskInfo.topActivity.getPackageName());
                    mPipUiEventLogger.setTaskInfo(taskInfo);
                    mMediaController.onActivityPinned();
                }
                if (mPipTransitionState.isInSwipePipToHomeTransition()) {
                    mPipUiEventLogger.log(