From 7737398f68bb03d1a7bc07b9cc8da700977afcec Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Fri, 24 Nov 2017 13:24:28 +0100 Subject: [PATCH] WM: Stop tampering with sysuiVisibility for layout Instead of changing the sysuiVisibility to get the desired layout behavior calculate the implied sysuiVisibility flags at layout time. This allows us to check what the window originally requested, which will be needed later for cutout-aware layout. Bug: 65689439 Test: runtest -x services/tests/servicestests/src/com/android/server/policy/PhoneWindowManagerLayoutTest.java Change-Id: I195f7b8ad535731614ea8f5fb2af2f001fd13036 --- .../com/android/server/policy/PhoneWindowManager.java | 11 ++++++++--- .../server/policy/PhoneWindowManagerLayoutTest.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index ac0b5a9d4a932..7415ec3881b15 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -2666,17 +2666,21 @@ public class PhoneWindowManager implements WindowManagerPolicy { // The status bar is the only window allowed to exhibit keyguard behavior. attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; } + } + private int getImpliedSysUiFlagsForLayout(LayoutParams attrs) { + int impliedFlags = 0; if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { - attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; + impliedFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; } final boolean forceWindowDrawsStatusBarBackground = (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0; if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 || forceWindowDrawsStatusBarBackground && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) { - attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + impliedFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; } + return impliedFlags; } void readLidState() { @@ -4832,7 +4836,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { final int fl = PolicyControl.getWindowFlags(win, attrs); final int pfl = attrs.privateFlags; final int sim = attrs.softInputMode; - final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); + final int requestedSysUiFl = PolicyControl.getSystemUiVisibility(win, null); + final int sysUiFl = requestedSysUiFl | getImpliedSysUiFlagsForLayout(attrs); final Rect pf = mTmpParentFrame; final Rect df = mTmpDisplayFrame; diff --git a/services/tests/servicestests/src/com/android/server/policy/PhoneWindowManagerLayoutTest.java b/services/tests/servicestests/src/com/android/server/policy/PhoneWindowManagerLayoutTest.java index 432fa7e4ac6e9..0941d4fd4fc97 100644 --- a/services/tests/servicestests/src/com/android/server/policy/PhoneWindowManagerLayoutTest.java +++ b/services/tests/servicestests/src/com/android/server/policy/PhoneWindowManagerLayoutTest.java @@ -23,6 +23,8 @@ import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; +import static org.junit.Assert.assertEquals; + import android.graphics.PixelFormat; import android.platform.test.annotations.Presubmit; import android.support.test.filters.SmallTest; @@ -94,4 +96,13 @@ public class PhoneWindowManagerLayoutTest extends PhoneWindowManagerTestBase { assertInsetByTopBottom(mAppWindow.contentFrame, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT); assertInsetByTopBottom(mAppWindow.decorFrame, 0, NAV_BAR_HEIGHT); } + + @Test + public void addingWindow_doesNotTamperWithSysuiFlags() { + mAppWindow.attrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; + mPolicy.addWindow(mAppWindow); + + assertEquals(0, mAppWindow.attrs.systemUiVisibility); + assertEquals(0, mAppWindow.attrs.subtreeSystemUiVisibility); + } } \ No newline at end of file