From 23bf5462f05b33ce4390d8370520e43b74dbec09 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Fri, 13 May 2016 15:24:39 -0700 Subject: [PATCH] Handle multi-window for inset hint We need to incorporate task bounds when calculating the inset hint so we don't specify something wrong to the client which we correct immediately after. Bug: 28697105 Change-Id: I23cec7d6cc62a4d982e0796a867e803d4cce0803 --- .../android/view/WindowManagerPolicy.java | 11 ++++++-- .../server/policy/PhoneWindowManager.java | 28 +++++++++++++++++-- .../server/wm/WindowManagerService.java | 13 +++++++-- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java index 908a99ddd91e7..e6f5b8386d492 100644 --- a/core/java/android/view/WindowManagerPolicy.java +++ b/core/java/android/view/WindowManagerPolicy.java @@ -938,7 +938,11 @@ public interface WindowManagerPolicy { * be correct. * * @param attrs The LayoutParams of the window. - * @param rotation Rotation of the display. + * @param taskBounds The bounds of the task this window is on or {@code null} if no task is + * associated with the window. + * @param displayRotation Rotation of the display. + * @param displayWidth The width of the display. + * @param displayHeight The height of the display. * @param outContentInsets The areas covered by system windows, expressed as positive insets. * @param outStableInsets The areas covered by stable system windows irrespective of their * current visibility. Expressed as positive insets. @@ -946,8 +950,9 @@ public interface WindowManagerPolicy { * @return Whether to always consume the navigation bar. * See {@link #isNavBarForcedShownLw(WindowState)}. */ - public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int rotation, - Rect outContentInsets, Rect outStableInsets, Rect outOutsets); + public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, + int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, + Rect outStableInsets, Rect outOutsets); /** * Called when layout of the windows is finished. After this function has diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index b2cf89b17cfc6..b30817f53cdbb 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -553,6 +553,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { static final Rect mTmpStableFrame = new Rect(); static final Rect mTmpNavigationFrame = new Rect(); static final Rect mTmpOutsetFrame = new Rect(); + private static final Rect mTmpRect = new Rect(); WindowState mTopFullscreenOpaqueWindowState; WindowState mTopFullscreenOpaqueOrDimmingWindowState; @@ -3797,8 +3798,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { } @Override - public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation, - Rect outContentInsets, Rect outStableInsets, Rect outOutsets) { + public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, + int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, + Rect outStableInsets, Rect outOutsets) { final int fl = PolicyControl.getWindowFlags(null, attrs); final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); @@ -3852,6 +3854,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { outStableInsets.set(mStableLeft, mStableTop, availRight - mStableRight, availBottom - mStableBottom); + if (taskBounds != null) { + calculateRelevantTaskInsets(taskBounds, outContentInsets, + displayWidth, displayHeight); + calculateRelevantTaskInsets(taskBounds, outStableInsets, + displayWidth, displayHeight); + } return mForceShowSystemBars; } outContentInsets.setEmpty(); @@ -3859,6 +3867,22 @@ public class PhoneWindowManager implements WindowManagerPolicy { return mForceShowSystemBars; } + /** + * For any given task bounds, the insets relevant for these bounds given the insets relevant + * for the entire display. + */ + private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth, + int displayHeight) { + mTmpRect.set(0, 0, displayWidth, displayHeight); + mTmpRect.inset(inOutInsets); + mTmpRect.intersect(taskBounds); + int leftInset = mTmpRect.left - taskBounds.left; + int topInset = mTmpRect.top - taskBounds.top; + int rightInset = taskBounds.right - mTmpRect.right; + int bottomInset = taskBounds.bottom - mTmpRect.bottom; + inOutInsets.set(leftInset, topInset, rightInset, bottomInset); + } + private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 239cc8eaae8cd..13cb28547264e 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -2117,8 +2117,17 @@ public class WindowManagerService extends IWindowManager.Stub } if (displayContent.isDefaultDisplay) { - if (mPolicy.getInsetHintLw(win.mAttrs, mRotation, outContentInsets, outStableInsets, - outOutsets)) { + final DisplayInfo displayInfo = displayContent.getDisplayInfo(); + final Rect taskBounds; + if (atoken != null && atoken.mTask != null) { + taskBounds = mTmpRect; + atoken.mTask.getBounds(mTmpRect); + } else { + taskBounds = null; + } + if (mPolicy.getInsetHintLw(win.mAttrs, taskBounds, mRotation, + displayInfo.logicalWidth, displayInfo.logicalHeight, outContentInsets, + outStableInsets, outOutsets)) { res |= WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_NAV_BAR; } } else {