From 61ecc1bb39c475e790a6d23afa16204e294432a9 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 17 Feb 2017 10:46:17 -0800 Subject: [PATCH] Fixes issues where the PiP menu activity is out of sync. - When the menu activity is hidden or destroyed by the system, we should reset the state so that we can restore the input consumer and show again property next time the PiP is interacted with. - Also ensuring that non-focused pinned stack windows are not added to the input window list Bug: 35462085 Bug: 34281221 Test: Relaunch a PiP activity that is single top. Test: Launch a new task/activity from a PiP activity after the menu is visible. Change-Id: I43829cce50669de704caf5a720c2adf7daf92398 --- .../systemui/pip/phone/PipMenuActivity.java | 18 ++++++++++ .../com/android/server/wm/InputMonitor.java | 34 +++++++++++-------- 2 files changed, 38 insertions(+), 14 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 90669772bcd1b..8a60cd127b106 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java @@ -137,6 +137,24 @@ public class PipMenuActivity extends Activity { showMenu(); } + @Override + protected void onUserLeaveHint() { + super.onUserLeaveHint(); + + // If another task is starting on top of the menu, then finish it so that it can be + // recreated on the top next time it starts + finish(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + // Fallback, if we are destroyed for any other reason (like when the task is being reset), + // also reset the callback. + notifyActivityCallback(null); + } + @Override public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { if (!isInPictureInPictureMode) { diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java index 37b8deb0a24fe..dc4806a980fae 100644 --- a/services/core/java/com/android/server/wm/InputMonitor.java +++ b/services/core/java/com/android/server/wm/InputMonitor.java @@ -631,14 +631,26 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks { return; } - if (mAddPipInputConsumerHandle - && w.getStackId() == PINNED_STACK_ID - && inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer) { - // Update the bounds of the Pip input consumer to match the Pinned stack - w.getStack().getBounds(pipTouchableBounds); - pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds); - addInputWindowHandle(pipInputConsumer.mWindowHandle); - mAddPipInputConsumerHandle = false; + final int flags = w.mAttrs.flags; + final int privateFlags = w.mAttrs.privateFlags; + final int type = w.mAttrs.type; + final boolean hasFocus = w == mInputFocus; + final boolean isVisible = w.isVisibleLw(); + + if (w.getStackId() == PINNED_STACK_ID) { + if (mAddPipInputConsumerHandle + && (inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer)) { + // Update the bounds of the Pip input consumer to match the Pinned stack + w.getStack().getBounds(pipTouchableBounds); + pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds); + addInputWindowHandle(pipInputConsumer.mWindowHandle); + mAddPipInputConsumerHandle = false; + } + // TODO: Fix w.canReceiveTouchInput() to handle this case + if (!hasFocus) { + // Skip this pinned stack window if it does not have focus + return; + } } if (mAddInputConsumerHandle @@ -655,12 +667,6 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks { } } - final int flags = w.mAttrs.flags; - final int privateFlags = w.mAttrs.privateFlags; - final int type = w.mAttrs.type; - - final boolean hasFocus = w == mInputFocus; - final boolean isVisible = w.isVisibleLw(); if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) { mDisableWallpaperTouchEvents = true; }