From c109aa6e563dd13dc5f6415247d745c2be1f8e83 Mon Sep 17 00:00:00 2001 From: "jorgegil@google.com" Date: Wed, 19 May 2021 14:27:59 -0700 Subject: [PATCH] Only resize the menu on hide if it was resized on show Fixes an issue where a max-size PIP is resized to the user-resized size after either: A) single-tap to show the menu and then it times out to hide it, or B) single-tap to show the menu and then single tap outside of the PIP window This was caused by the resize=true flag being passed into PipMenuView.hideMenu() from the hide menu timeout runnable or from PipResizeGestureHandler.onDragCornerResize() Bug: 186616706 Test: enter PIP, then: 1) double-tap to MAX, then tap once to show menu and wait for it to time out - verify it stays in MAX size 2) double-tap to MAX, then tap once to show menu and once outside of PIP - verify it stays in MAX size 3) pinch-resize to minimum size, tap once, wait for it to expand a bit, wait for the menu timeout - verify it resizes down to the minimum size. Change-Id: I394d49b77f2c6aa42fc4681ef5238c478a474b85 --- .../wm/shell/pip/phone/PhonePipMenuController.java | 7 ++++--- .../src/com/android/wm/shell/pip/phone/PipMenuView.java | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java index 140f32f9eb7f8..02451c30d4ef2 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java @@ -18,8 +18,6 @@ package com.android.wm.shell.pip.phone; import static android.view.WindowManager.SHELL_ROOT_LAYER_PIP; -import static com.android.wm.shell.pip.phone.PipMenuView.ANIM_TYPE_HIDE; - import android.annotation.Nullable; import android.app.RemoteAction; import android.content.Context; @@ -399,7 +397,10 @@ public class PhonePipMenuController implements PipMenuController { * Hides the menu view. */ public void hideMenu() { - hideMenu(ANIM_TYPE_HIDE, true /* resize */); + final boolean isMenuVisible = isMenuVisible(); + if (isMenuVisible) { + mPipMenuView.hideMenu(); + } } /** diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java index e21083569c41b..67b1e6dd4cc76 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java @@ -130,6 +130,11 @@ public class PipMenuView extends FrameLayout { private ShellExecutor mMainExecutor; private Handler mMainHandler; + /** + * Whether the most recent showing of the menu caused a PIP resize, such as when PIP is too + * small and it is resized on menu show to fit the actions. + */ + private boolean mDidLastShowMenuResize; private final Runnable mHideMenuRunnable = this::hideMenu; protected View mViewRoot; @@ -245,6 +250,7 @@ public class PipMenuView extends FrameLayout { void showMenu(int menuState, Rect stackBounds, boolean allowMenuTimeout, boolean resizeMenuOnShow, boolean withDelay, boolean showResizeHandle) { mAllowMenuTimeout = allowMenuTimeout; + mDidLastShowMenuResize = resizeMenuOnShow; if (mMenuState != menuState) { // Disallow touches if the menu needs to resize while showing, and we are transitioning // to/from a full menu state. @@ -340,7 +346,7 @@ public class PipMenuView extends FrameLayout { } void hideMenu(Runnable animationEndCallback) { - hideMenu(animationEndCallback, true /* notifyMenuVisibility */, true /* resize */, + hideMenu(animationEndCallback, true /* notifyMenuVisibility */, mDidLastShowMenuResize, ANIM_TYPE_HIDE); }