From e4ee8f8ab836ee115e9cbab360f35773e37fd5d5 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Mon, 31 Oct 2016 12:40:15 -0700 Subject: [PATCH] Add some more computeFrameLw tests. This time for producing insets in the fullscreen case. Test: bit FrameworksServicesTests:com.android.server.wm.WindowFrameTests Change-Id: I2566572af996f024d4b07c3bac945bc8ef7005b9 --- .../com/android/server/wm/WindowState.java | 4 ++ .../android/server/wm/WindowFrameTests.java | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 59caa1433193d..51fc9f0806e72 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -1030,6 +1030,10 @@ class WindowState extends WindowContainer implements WindowManagerP return mVisibleFrame; } + Rect getStableFrameLw() { + return mStableFrame; + } + @Override public boolean getGivenInsetsPendingLw() { return mGivenInsetsPending; diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java index 15cd55f37fb38..19b418662cb33 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowFrameTests.java @@ -35,6 +35,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.FLAG_SCALED; import static android.view.WindowManager.LayoutParams.FILL_PARENT; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Tests for the {@link WindowState#computeFrameLw} method and other window frame machinery. @@ -101,6 +102,63 @@ public class WindowFrameTests { assertEquals(bottom, rect.bottom); } + @Test + public void testLayoutInFullscreenTaskInsets() throws Exception { + Task task = new TaskWithBounds(null); // fullscreen task doesn't use bounds for computeFrame + WindowState w = createWindow(task, FILL_PARENT, FILL_PARENT); + w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; + + final int bottomContentInset = 100; + final int topContentInset = 50; + final int bottomVisibleInset = 30; + final int topVisibleInset = 70; + final int leftStableInset = 20; + final int rightStableInset = 90; + + // With no insets or system decor all the frames incoming from PhoneWindowManager + // are identical. + final Rect pf = new Rect(0, 0, 1000, 1000); + final Rect df = pf; + final Rect of = df; + final Rect cf = new Rect(pf); + // Produce some insets + cf.top += 50; + cf.bottom -= 100; + final Rect vf = new Rect(pf); + vf.top += topVisibleInset; + vf.bottom -= bottomVisibleInset; + final Rect sf = new Rect(pf); + sf.left += leftStableInset; + sf.right -= rightStableInset; + + final Rect dcf = pf; + // When mFrame extends past cf, the content insets are + // the difference between mFrame and ContentFrame. Visible + // and stable frames work the same way. + w.computeFrameLw(pf, df, of, cf, vf, dcf, sf, null); + assertRect(w.mFrame,0, 0, 1000, 1000); + assertRect(w.mContentInsets, 0, topContentInset, 0, bottomContentInset); + assertRect(w.mVisibleInsets, 0, topVisibleInset, 0, bottomVisibleInset); + assertRect(w.mStableInsets, leftStableInset, 0, rightStableInset, 0); + // The frames remain as passed in shrunk to the window frame + assertTrue(cf.equals(w.getContentFrameLw())); + assertTrue(vf.equals(w.getVisibleFrameLw())); + assertTrue(sf.equals(w.getStableFrameLw())); + // On the other hand mFrame doesn't extend past cf we won't get any insets + w.mAttrs.x = 100; + w.mAttrs.y = 100; + w.mAttrs.width = 100; w.mAttrs.height = 100; //have to clear MATCH_PARENT + w.mRequestedWidth = 100; + w.mRequestedHeight = 100; + w.computeFrameLw(pf, df, of, cf, vf, dcf, sf, null); + assertRect(w.mFrame, 100, 100, 200, 200); + assertRect(w.mContentInsets, 0, 0, 0, 0); + // In this case the frames are shrunk to the window frame. + assertTrue(w.mFrame.equals(w.getContentFrameLw())); + assertTrue(w.mFrame.equals(w.getVisibleFrameLw())); + assertTrue(w.mFrame.equals(w.getStableFrameLw())); + } + @Test public void testLayoutInFullscreenTaskNoInsets() throws Exception { Task task = new TaskWithBounds(null); // fullscreen task doesn't use bounds for computeFrame