From bb78744c57eb7083165447d0396959a95d7e6e8d Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 1 Sep 2017 11:33:47 -0700 Subject: [PATCH] Fix issue with PiP menu activity disallowing touches - On devices where the expanded bounds are the same as the collapsed bounds, there is no task stack animation and no subsequent animation end callback, which means that touch state is not reset. Skip disallowing touches in this state. - Also fix race causing the PiP menu to ignore touches due to the pinned animation end callback happening before the menu is first shown. Bug: 65168767 Test: Tap menu on Ryu, rotate, and try and drag the PiP before the menu times out Change-Id: I0b264678aa3300fd4d4e9da5ef3d48a590232ae1 --- .../systemui/pip/phone/PipMenuActivity.java | 17 ++++++++++------ .../pip/phone/PipMenuActivityController.java | 14 +++++++++---- .../systemui/pip/phone/PipTouchHandler.java | 20 +++++++++++++------ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java index 13ba7c160526c..901b0b0a4e85b 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java @@ -19,6 +19,7 @@ package com.android.systemui.pip.phone; import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_ACTIONS; import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_ALLOW_TIMEOUT; import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_CONTROLLER_MESSENGER; +import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_WILL_RESIZE_MENU; import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_DISMISS_FRACTION; import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_MOVEMENT_BOUNDS; import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_MENU_STATE; @@ -132,7 +133,8 @@ public class PipMenuActivity extends Activity { showMenu(data.getInt(EXTRA_MENU_STATE), data.getParcelable(EXTRA_STACK_BOUNDS), data.getParcelable(EXTRA_MOVEMENT_BOUNDS), - data.getBoolean(EXTRA_ALLOW_TIMEOUT)); + data.getBoolean(EXTRA_ALLOW_TIMEOUT), + data.getBoolean(EXTRA_WILL_RESIZE_MENU)); break; } case MESSAGE_POKE_MENU: @@ -307,12 +309,14 @@ public class PipMenuActivity extends Activity { } private void showMenu(int menuState, Rect stackBounds, Rect movementBounds, - boolean allowMenuTimeout) { + boolean allowMenuTimeout, boolean resizeMenuOnShow) { mAllowMenuTimeout = allowMenuTimeout; if (mMenuState != menuState) { - boolean deferTouchesUntilAnimationEnds = (mMenuState == MENU_STATE_FULL) || - (menuState == MENU_STATE_FULL); - mAllowTouches = !deferTouchesUntilAnimationEnds; + // Disallow touches if the menu needs to resize while showing, and we are transitioning + // to/from a full menu state. + boolean disallowTouchesUntilAnimationEnd = resizeMenuOnShow && + (mMenuState == MENU_STATE_FULL || menuState == MENU_STATE_FULL); + mAllowTouches = !disallowTouchesUntilAnimationEnd; cancelDelayedFinish(); updateActionViews(stackBounds); if (mMenuContainerAnimator != null) { @@ -409,7 +413,8 @@ public class PipMenuActivity extends Activity { Rect stackBounds = intent.getParcelableExtra(EXTRA_STACK_BOUNDS); Rect movementBounds = intent.getParcelableExtra(EXTRA_MOVEMENT_BOUNDS); boolean allowMenuTimeout = intent.getBooleanExtra(EXTRA_ALLOW_TIMEOUT, true); - showMenu(menuState, stackBounds, movementBounds, allowMenuTimeout); + boolean willResizeMenu = intent.getBooleanExtra(EXTRA_WILL_RESIZE_MENU, false); + showMenu(menuState, stackBounds, movementBounds, allowMenuTimeout, willResizeMenu); } } diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java index c558056530b66..e898a51de33ca 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java @@ -63,6 +63,7 @@ public class PipMenuActivityController { public static final String EXTRA_STACK_BOUNDS = "stack_bounds"; public static final String EXTRA_MOVEMENT_BOUNDS = "movement_bounds"; public static final String EXTRA_ALLOW_TIMEOUT = "allow_timeout"; + public static final String EXTRA_WILL_RESIZE_MENU = "resize_menu_on_show"; public static final String EXTRA_DISMISS_FRACTION = "dismiss_fraction"; public static final String EXTRA_MENU_STATE = "menu_state"; @@ -268,7 +269,8 @@ public class PipMenuActivityController { // If we haven't requested the start activity, or if it previously took too long to // start, then start it startMenuActivity(MENU_STATE_NONE, null /* stackBounds */, - null /* movementBounds */, false /* allowMenuTimeout */); + null /* movementBounds */, false /* allowMenuTimeout */, + false /* resizeMenuOnShow */); } } @@ -276,18 +278,20 @@ public class PipMenuActivityController { * Shows the menu activity. */ public void showMenu(int menuState, Rect stackBounds, Rect movementBounds, - boolean allowMenuTimeout) { + boolean allowMenuTimeout, boolean willResizeMenu) { if (DEBUG) { Log.d(TAG, "showMenu() state=" + menuState + " hasActivity=" + (mToActivityMessenger != null) + " callers=\n" + Debug.getCallers(5, " ")); } + if (mToActivityMessenger != null) { Bundle data = new Bundle(); data.putInt(EXTRA_MENU_STATE, menuState); data.putParcelable(EXTRA_STACK_BOUNDS, stackBounds); data.putParcelable(EXTRA_MOVEMENT_BOUNDS, movementBounds); data.putBoolean(EXTRA_ALLOW_TIMEOUT, allowMenuTimeout); + data.putBoolean(EXTRA_WILL_RESIZE_MENU, willResizeMenu); Message m = Message.obtain(); m.what = PipMenuActivity.MESSAGE_SHOW_MENU; m.obj = data; @@ -299,7 +303,8 @@ public class PipMenuActivityController { } else if (!mStartActivityRequested || isStartActivityRequestedElapsed()) { // If we haven't requested the start activity, or if it previously took too long to // start, then start it - startMenuActivity(menuState, stackBounds, movementBounds, allowMenuTimeout); + startMenuActivity(menuState, stackBounds, movementBounds, allowMenuTimeout, + willResizeMenu); } } @@ -372,7 +377,7 @@ public class PipMenuActivityController { * Starts the menu activity on the top task of the pinned stack. */ private void startMenuActivity(int menuState, Rect stackBounds, Rect movementBounds, - boolean allowMenuTimeout) { + boolean allowMenuTimeout, boolean willResizeMenu) { try { StackInfo pinnedStackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID); if (pinnedStackInfo != null && pinnedStackInfo.taskIds != null && @@ -388,6 +393,7 @@ public class PipMenuActivityController { } intent.putExtra(EXTRA_MENU_STATE, menuState); intent.putExtra(EXTRA_ALLOW_TIMEOUT, allowMenuTimeout); + intent.putExtra(EXTRA_WILL_RESIZE_MENU, willResizeMenu); ActivityOptions options = ActivityOptions.makeCustomAnimation(mContext, 0, 0); options.setLaunchTaskId( pinnedStackInfo.taskIds[pinnedStackInfo.taskIds.length - 1]); diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java index 8ddd8882788bc..31814818303b5 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java @@ -170,7 +170,7 @@ public class PipTouchHandler { @Override public void onPipShowMenu() { mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), - mMovementBounds, true /* allowMenuTimeout */); + mMovementBounds, true /* allowMenuTimeout */, willResizeMenu()); } } @@ -214,7 +214,7 @@ public class PipTouchHandler { // Only show the menu if the user isn't currently interacting with the PiP if (!mTouchState.isUserInteracting()) { mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), - mMovementBounds, false /* allowMenuTimeout */); + mMovementBounds, false /* allowMenuTimeout */, willResizeMenu()); } } @@ -236,7 +236,7 @@ public class PipTouchHandler { if (mShowPipMenuOnAnimationEnd) { mMenuController.showMenu(MENU_STATE_CLOSE, mMotionHelper.getBounds(), - mMovementBounds, true /* allowMenuTimeout */); + mMovementBounds, true /* allowMenuTimeout */, false /* willResizeMenu */); mShowPipMenuOnAnimationEnd = false; } } @@ -337,7 +337,7 @@ public class PipTouchHandler { private void onAccessibilityShowMenu() { mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), - mMovementBounds, false /* allowMenuTimeout */); + mMovementBounds, false /* allowMenuTimeout */, willResizeMenu()); } private boolean handleTouchEvent(MotionEvent ev) { @@ -704,7 +704,7 @@ public class PipTouchHandler { // If the menu is still visible, and we aren't minimized, then just poke the // menu so that it will timeout after the user stops touching it mMenuController.showMenu(mMenuState, mMotionHelper.getBounds(), - mMovementBounds, true /* allowMenuTimeout */); + mMovementBounds, true /* allowMenuTimeout */, willResizeMenu()); } else { // If the menu is not visible, then we can still be showing the activity for the // dismiss overlay, so just finish it after the animation completes @@ -731,7 +731,7 @@ public class PipTouchHandler { setMinimizedStateInternal(false); } else if (mMenuState != MENU_STATE_FULL) { mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), - mMovementBounds, true /* allowMenuTimeout */); + mMovementBounds, true /* allowMenuTimeout */, willResizeMenu()); } else { mMenuController.hideMenu(); mMotionHelper.expandPip(); @@ -773,6 +773,14 @@ public class PipTouchHandler { cleanUpDismissTarget(); } + /** + * @return whether the menu will resize as a part of showing the full menu. + */ + private boolean willResizeMenu() { + return mExpandedBounds.width() != mNormalBounds.width() || + mExpandedBounds.height() != mNormalBounds.height(); + } + public void dump(PrintWriter pw, String prefix) { final String innerPrefix = prefix + " "; pw.println(prefix + TAG);