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

Commit b9450d9e authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Update PiP action even if menu is not visible

Deprecate also the query on WM for pip bounds in PhonePipMenuController

Video: http://recall/-/aaaaaabFQoRHlzixHdtY/n6eylZkmVGfJwp0nl42un
Bug: 172587320
Test: Play in spotify when PiP is in playing state, see video
Test: atest WMShellFlickerTests:com.android.wm.shell.flicker.pip
Change-Id: Ieca6b3e136d5fff6818474ef012ea6b415515fb4
parent 8316505a
Loading
Loading
Loading
Loading
+10 −20
Original line number Diff line number Diff line
@@ -16,13 +16,9 @@

package com.android.wm.shell.pip.phone;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.view.WindowManager.SHELL_ROOT_LAYER_PIP;

import android.annotation.Nullable;
import android.app.ActivityTaskManager;
import android.app.ActivityTaskManager.RootTaskInfo;
import android.app.RemoteAction;
import android.content.Context;
import android.content.pm.ParceledListSlice;
@@ -43,6 +39,7 @@ import android.view.WindowManagerGlobal;

import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SystemWindows;
import com.android.wm.shell.pip.PipBoundsState;
import com.android.wm.shell.pip.PipMediaController;
import com.android.wm.shell.pip.PipMediaController.ActionListener;
import com.android.wm.shell.pip.PipMenuController;
@@ -99,6 +96,7 @@ public class PhonePipMenuController implements PipMenuController {
    private final RectF mTmpSourceRectF = new RectF();
    private final RectF mTmpDestinationRectF = new RectF();
    private final Context mContext;
    private final PipBoundsState mPipBoundsState;
    private final PipMediaController mMediaController;
    private final ShellExecutor mMainExecutor;
    private final Handler mMainHandler;
@@ -134,10 +132,11 @@ public class PhonePipMenuController implements PipMenuController {
        }
    };

    public PhonePipMenuController(Context context, PipMediaController mediaController,
            SystemWindows systemWindows, ShellExecutor mainExecutor,
            Handler mainHandler) {
    public PhonePipMenuController(Context context, PipBoundsState pipBoundsState,
            PipMediaController mediaController, SystemWindows systemWindows,
            ShellExecutor mainExecutor, Handler mainHandler) {
        mContext = context;
        mPipBoundsState = pipBoundsState;
        mMediaController = mediaController;
        mSystemWindows = systemWindows;
        mMainExecutor = mainExecutor;
@@ -466,20 +465,11 @@ public class PhonePipMenuController implements PipMenuController {
     * Updates the PiP menu with the best set of actions provided.
     */
    private void updateMenuActions() {
        if (isMenuVisible()) {
            // Fetch the pinned stack bounds
            Rect stackBounds = null;
            try {
                RootTaskInfo pinnedTaskInfo = ActivityTaskManager.getService().getRootTaskInfo(
                        WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED);
                if (pinnedTaskInfo != null) {
                    stackBounds = pinnedTaskInfo.bounds;
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Error showing PIP menu", e);
        if (mPipMenuView != null) {
            final ParceledListSlice<RemoteAction> menuActions = resolveMenuActions();
            if (menuActions != null) {
                mPipMenuView.setActions(mPipBoundsState.getBounds(), menuActions.getList());
            }

            mPipMenuView.setActions(stackBounds, resolveMenuActions().getList());
        }
    }

+3 −1
Original line number Diff line number Diff line
@@ -374,8 +374,10 @@ public class PipMenuView extends FrameLayout {
    void setActions(Rect stackBounds, List<RemoteAction> actions) {
        mActions.clear();
        mActions.addAll(actions);
        if (mMenuState == MENU_STATE_FULL) {
            updateActionViews(stackBounds);
        }
    }

    private void updateActionViews(Rect stackBounds) {
        ViewGroup expandContainer = findViewById(R.id.expand_container);
+4 −3
Original line number Diff line number Diff line
@@ -157,11 +157,12 @@ public class WMShellModule {
    @WMSingleton
    @Provides
    static PhonePipMenuController providesPipPhoneMenuController(Context context,
            PipMediaController pipMediaController, SystemWindows systemWindows,
            PipBoundsState pipBoundsState, PipMediaController pipMediaController,
            SystemWindows systemWindows,
            @ShellMainThread ShellExecutor mainExecutor,
            @ShellMainThread Handler mainHandler) {
        return new PhonePipMenuController(context, pipMediaController, systemWindows,
                mainExecutor, mainHandler);
        return new PhonePipMenuController(context, pipBoundsState, pipMediaController,
                systemWindows, mainExecutor, mainHandler);
    }

    @WMSingleton