Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 21 | import static android.content.ActivityInfoProto.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 24 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 33 | import static android.view.WindowManager.TRANSIT_UNSET; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 34 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 35 | import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; |
| 36 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 37 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
| 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; |
| 39 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 40 | import static org.junit.Assert.assertEquals; |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 41 | import static org.junit.Assert.assertFalse; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 42 | import static org.junit.Assert.assertNotNull; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 43 | import static org.junit.Assert.assertNull; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 44 | import static org.junit.Assert.assertTrue; |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 45 | import static org.mockito.ArgumentMatchers.anyInt; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 46 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 47 | import android.content.res.Configuration; |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 48 | import android.graphics.Point; |
| 49 | import android.graphics.Rect; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 50 | import android.platform.test.annotations.Presubmit; |
| 51 | import android.view.Surface; |
| 52 | import android.view.WindowManager; |
| 53 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 54 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 55 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 56 | import org.junit.Before; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 57 | import org.junit.Test; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 58 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 59 | /** |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 60 | * Tests for the {@link AppWindowToken} class. |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 61 | * |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 62 | * Build/Install/Run: |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 63 | * atest WmTests:AppWindowTokenTests |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 64 | */ |
| 65 | @SmallTest |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 66 | @Presubmit |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 67 | public class AppWindowTokenTests extends WindowTestsBase { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 68 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 69 | TaskStack mStack; |
| 70 | Task mTask; |
| 71 | WindowTestUtils.TestAppWindowToken mToken; |
| 72 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 73 | private final String mPackageName = getInstrumentation().getTargetContext().getPackageName(); |
| 74 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 75 | @Before |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 76 | public void setUp() throws Exception { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 77 | mStack = createTaskStackOnDisplay(mDisplayContent); |
| 78 | mTask = createTaskInStack(mStack, 0 /* userId */); |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 79 | mToken = WindowTestUtils.createTestAppWindowToken(mDisplayContent, |
| 80 | false /* skipOnParentChanged */); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 81 | |
| 82 | mTask.addChild(mToken, 0); |
| 83 | } |
| 84 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 85 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 86 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 87 | public void testAddWindow_Order() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 88 | assertEquals(0, mToken.getWindowsCount()); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 89 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 90 | final WindowState win1 = createWindow(null, TYPE_APPLICATION, mToken, "win1"); |
| 91 | final WindowState startingWin = createWindow(null, TYPE_APPLICATION_STARTING, mToken, |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 92 | "startingWin"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 93 | final WindowState baseWin = createWindow(null, TYPE_BASE_APPLICATION, mToken, "baseWin"); |
| 94 | final WindowState win4 = createWindow(null, TYPE_APPLICATION, mToken, "win4"); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 95 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 96 | // Should not contain the windows that were added above. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 97 | assertEquals(4, mToken.getWindowsCount()); |
| 98 | assertTrue(mToken.hasWindow(win1)); |
| 99 | assertTrue(mToken.hasWindow(startingWin)); |
| 100 | assertTrue(mToken.hasWindow(baseWin)); |
| 101 | assertTrue(mToken.hasWindow(win4)); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 102 | |
| 103 | // The starting window should be on-top of all other windows. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 104 | assertEquals(startingWin, mToken.getLastChild()); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 105 | |
| 106 | // The base application window should be below all other windows. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 107 | assertEquals(baseWin, mToken.getFirstChild()); |
| 108 | mToken.removeImmediately(); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 112 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 113 | public void testFindMainWindow() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 114 | assertNull(mToken.findMainWindow()); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 115 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 116 | final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mToken, "window1"); |
| 117 | final WindowState window11 = createWindow(window1, FIRST_SUB_WINDOW, mToken, "window11"); |
| 118 | final WindowState window12 = createWindow(window1, FIRST_SUB_WINDOW, mToken, "window12"); |
| 119 | assertEquals(window1, mToken.findMainWindow()); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 120 | window1.mAnimatingExit = true; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 121 | assertEquals(window1, mToken.findMainWindow()); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 122 | final WindowState window2 = createWindow(null, TYPE_APPLICATION_STARTING, mToken, |
| 123 | "window2"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 124 | assertEquals(window2, mToken.findMainWindow()); |
| 125 | mToken.removeImmediately(); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 126 | } |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 127 | |
| 128 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 129 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 130 | public void testGetTopFullscreenWindow() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 131 | assertNull(mToken.getTopFullscreenWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 132 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 133 | final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mToken, "window1"); |
| 134 | final WindowState window11 = createWindow(null, TYPE_APPLICATION, mToken, "window11"); |
| 135 | final WindowState window12 = createWindow(null, TYPE_APPLICATION, mToken, "window12"); |
| 136 | assertEquals(window12, mToken.getTopFullscreenWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 137 | window12.mAttrs.width = 500; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 138 | assertEquals(window11, mToken.getTopFullscreenWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 139 | window11.mAttrs.width = 500; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 140 | assertEquals(window1, mToken.getTopFullscreenWindow()); |
| 141 | mToken.removeImmediately(); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 145 | public void testLandscapeSeascapeRotationByApp() { |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 146 | // Some plumbing to get the service ready for rotation updates. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 147 | mWm.mDisplayReady = true; |
| 148 | mWm.mDisplayEnabled = true; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 149 | |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 150 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 151 | TYPE_BASE_APPLICATION); |
| 152 | attrs.setTitle("AppWindow"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 153 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mToken); |
| 154 | mToken.addWindow(appWindow); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 155 | |
| 156 | // Set initial orientation and update. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 157 | mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 158 | mDisplayContent.updateOrientationFromAppTokens( |
| 159 | mDisplayContent.getRequestedOverrideConfiguration(), |
| 160 | null /* freezeThisOneIfNeeded */, false /* forceUpdate */); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 161 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mDisplayContent.getLastOrientation()); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 162 | appWindow.mResizeReported = false; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 163 | |
| 164 | // Update the orientation to perform 180 degree rotation and check that resize was reported. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 165 | mToken.setOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 166 | mDisplayContent.updateOrientationFromAppTokens( |
| 167 | mDisplayContent.getRequestedOverrideConfiguration(), |
| 168 | null /* freezeThisOneIfNeeded */, false /* forceUpdate */); |
Yunfan Chen | 0530fe7 | 2019-02-12 15:05:49 +0900 | [diff] [blame] | 169 | // In this test, DC will not get config update. Set the waiting flag to false. |
| 170 | mDisplayContent.mWaitingForConfig = false; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 171 | mWm.mRoot.performSurfacePlacement(false /* recoveringMemory */); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 172 | assertEquals(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, mDisplayContent.getLastOrientation()); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 173 | assertTrue(appWindow.mResizeReported); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 174 | appWindow.removeImmediately(); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 178 | public void testLandscapeSeascapeRotationByPolicy() { |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 179 | // Some plumbing to get the service ready for rotation updates. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 180 | mWm.mDisplayReady = true; |
| 181 | mWm.mDisplayEnabled = true; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 182 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 183 | final DisplayRotation spiedRotation = spy(mDisplayContent.getDisplayRotation()); |
| 184 | mDisplayContent.setDisplayRotation(spiedRotation); |
| 185 | |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 186 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 187 | TYPE_BASE_APPLICATION); |
| 188 | attrs.setTitle("AppWindow"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 189 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mToken); |
| 190 | mToken.addWindow(appWindow); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 191 | |
| 192 | // Set initial orientation and update. |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 193 | performRotation(spiedRotation, Surface.ROTATION_90); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 194 | appWindow.mResizeReported = false; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 195 | |
| 196 | // Update the rotation to perform 180 degree rotation and check that resize was reported. |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 197 | performRotation(spiedRotation, Surface.ROTATION_270); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 198 | assertTrue(appWindow.mResizeReported); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 199 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 200 | appWindow.removeImmediately(); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 201 | } |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 202 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 203 | private void performRotation(DisplayRotation spiedRotation, int rotationToReport) { |
| 204 | doReturn(rotationToReport).when(spiedRotation).rotationForOrientation(anyInt(), anyInt()); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 205 | int oldRotation = mDisplayContent.getRotation(); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 206 | mWm.updateRotation(false, false); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 207 | // Must manually apply here since ATM doesn't know about the display during this test |
| 208 | // (meaning it can't perform the normal sendNewConfiguration flow). |
| 209 | mDisplayContent.applyRotationLocked(oldRotation, mDisplayContent.getRotation()); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 210 | // Prevent the next rotation from being deferred by animation. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 211 | mWm.mAnimator.setScreenRotationAnimationLocked(mDisplayContent.getDisplayId(), null); |
| 212 | mWm.mRoot.performSurfacePlacement(false /* recoveringMemory */); |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 213 | } |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 214 | |
| 215 | @Test |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 216 | public void testSizeCompatBounds() { |
| 217 | // The real surface transaction is unnecessary. |
| 218 | mToken.setSkipPrepareSurfaces(true); |
| 219 | |
| 220 | final Rect fixedBounds = mToken.getRequestedOverrideConfiguration().windowConfiguration |
| 221 | .getBounds(); |
| 222 | fixedBounds.set(0, 0, 1200, 1600); |
| 223 | final Configuration newParentConfig = mTask.getConfiguration(); |
| 224 | |
| 225 | // Change the size of the container to two times smaller with insets. |
| 226 | newParentConfig.windowConfiguration.setAppBounds(200, 0, 800, 800); |
| 227 | final Rect containerAppBounds = newParentConfig.windowConfiguration.getAppBounds(); |
| 228 | final Rect containerBounds = newParentConfig.windowConfiguration.getBounds(); |
| 229 | containerBounds.set(0, 0, 600, 800); |
| 230 | mToken.onConfigurationChanged(newParentConfig); |
| 231 | |
| 232 | assertTrue(mToken.inSizeCompatMode()); |
| 233 | assertEquals(containerAppBounds, mToken.getBounds()); |
| 234 | assertEquals((float) containerAppBounds.width() / fixedBounds.width(), |
| 235 | mToken.getSizeCompatScale(), 0.0001f /* delta */); |
| 236 | |
| 237 | // Change the width of the container to two times bigger. |
| 238 | containerAppBounds.set(0, 0, 2400, 1600); |
| 239 | containerBounds.set(containerAppBounds); |
| 240 | mToken.onConfigurationChanged(newParentConfig); |
| 241 | |
| 242 | assertTrue(mToken.inSizeCompatMode()); |
| 243 | // Don't scale up, so the bounds keep the same as the fixed width. |
| 244 | assertEquals(fixedBounds.width(), mToken.getBounds().width()); |
| 245 | // Assert the position is horizontal center. |
| 246 | assertEquals((containerAppBounds.width() - fixedBounds.width()) / 2, |
| 247 | mToken.getBounds().left); |
| 248 | assertEquals(1f, mToken.getSizeCompatScale(), 0.0001f /* delta */); |
| 249 | |
| 250 | // Change the width of the container to fit the fixed bounds. |
| 251 | containerBounds.set(0, 0, 1200, 2000); |
| 252 | mToken.onConfigurationChanged(newParentConfig); |
| 253 | // Assert don't use fixed bounds because the region is enough. |
| 254 | assertFalse(mToken.inSizeCompatMode()); |
| 255 | } |
| 256 | |
| 257 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 258 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 259 | public void testGetOrientation() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 260 | mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 261 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 262 | mToken.setFillsParent(false); |
Bryce Lee | e83f34cd | 2017-10-31 19:50:54 -0700 | [diff] [blame] | 263 | // Can specify orientation if app doesn't fill parent. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 264 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mToken.getOrientation()); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 265 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 266 | mToken.setFillsParent(true); |
Jorim Jaggi | 980c9de | 2017-11-17 01:41:37 +0100 | [diff] [blame] | 267 | mToken.setHidden(true); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 268 | mToken.sendingToBottom = true; |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 269 | // Can not specify orientation if app isn't visible even though it fills parent. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 270 | assertEquals(SCREEN_ORIENTATION_UNSET, mToken.getOrientation()); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 271 | // Can specify orientation if the current orientation candidate is orientation behind. |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 272 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, |
| 273 | mToken.getOrientation(SCREEN_ORIENTATION_BEHIND)); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 274 | } |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 275 | |
| 276 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 277 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 278 | public void testKeyguardFlagsDuringRelaunch() { |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 279 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 280 | TYPE_BASE_APPLICATION); |
| 281 | attrs.flags |= FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD; |
| 282 | attrs.setTitle("AppWindow"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 283 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mToken); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 284 | |
| 285 | // Add window with show when locked flag |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 286 | mToken.addWindow(appWindow); |
| 287 | assertTrue(mToken.containsShowWhenLockedWindow() && mToken.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 288 | |
| 289 | // Start relaunching |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 290 | mToken.startRelaunching(); |
| 291 | assertTrue(mToken.containsShowWhenLockedWindow() && mToken.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 292 | |
| 293 | // Remove window and make sure that we still report back flag |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 294 | mToken.removeChild(appWindow); |
| 295 | assertTrue(mToken.containsShowWhenLockedWindow() && mToken.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 296 | |
| 297 | // Finish relaunching and ensure flag is now not reported |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 298 | mToken.finishRelaunching(); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 299 | assertFalse( |
| 300 | mToken.containsShowWhenLockedWindow() || mToken.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 301 | } |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 302 | |
| 303 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 304 | public void testStuckExitingWindow() { |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 305 | final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, |
| 306 | "closingWindow"); |
| 307 | closingWindow.mAnimatingExit = true; |
| 308 | closingWindow.mRemoveOnExit = true; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 309 | closingWindow.mAppToken.commitVisibility(null, false /* visible */, TRANSIT_UNSET, |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 310 | true /* performLayout */, false /* isVoiceInteraction */); |
| 311 | |
| 312 | // We pretended that we were running an exit animation, but that should have been cleared up |
| 313 | // by changing visibility of AppWindowToken |
| 314 | closingWindow.removeIfPossible(); |
| 315 | assertTrue(closingWindow.mRemoved); |
| 316 | } |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 317 | |
| 318 | @Test |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 319 | public void testSetOrientation() { |
| 320 | // Assert orientation is unspecified to start. |
| 321 | assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mToken.getOrientation()); |
| 322 | |
| 323 | mToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 324 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mToken.getOrientation()); |
| 325 | |
| 326 | mDisplayContent.removeAppToken(mToken.token); |
| 327 | // Assert orientation is unset to after container is removed. |
| 328 | assertEquals(SCREEN_ORIENTATION_UNSET, mToken.getOrientation()); |
| 329 | |
| 330 | // Reset display frozen state |
| 331 | mWm.mDisplayFrozen = false; |
| 332 | } |
| 333 | |
| 334 | @Test |
| 335 | public void testCreateRemoveStartingWindow() { |
| 336 | mToken.addStartingWindow(mPackageName, |
| 337 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 338 | false, false); |
| 339 | waitUntilHandlersIdle(); |
| 340 | assertHasStartingWindow(mToken); |
| 341 | mToken.removeStartingWindow(); |
| 342 | waitUntilHandlersIdle(); |
| 343 | assertNoStartingWindow(mToken); |
| 344 | } |
| 345 | |
| 346 | @Test |
| 347 | public void testAddRemoveRace() { |
| 348 | // There was once a race condition between adding and removing starting windows |
| 349 | for (int i = 0; i < 1000; i++) { |
| 350 | final WindowTestUtils.TestAppWindowToken appToken = createIsolatedTestAppWindowToken(); |
| 351 | |
| 352 | appToken.addStartingWindow(mPackageName, |
| 353 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 354 | false, false); |
| 355 | appToken.removeStartingWindow(); |
| 356 | waitUntilHandlersIdle(); |
| 357 | assertNoStartingWindow(appToken); |
| 358 | |
| 359 | appToken.getParent().getParent().removeImmediately(); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | @Test |
| 364 | public void testTransferStartingWindow() { |
| 365 | final WindowTestUtils.TestAppWindowToken token1 = createIsolatedTestAppWindowToken(); |
| 366 | final WindowTestUtils.TestAppWindowToken token2 = createIsolatedTestAppWindowToken(); |
| 367 | token1.addStartingWindow(mPackageName, |
| 368 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 369 | false, false); |
| 370 | waitUntilHandlersIdle(); |
| 371 | token2.addStartingWindow(mPackageName, |
| 372 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, token1.appToken.asBinder(), |
| 373 | true, true, false, true, false, false); |
| 374 | waitUntilHandlersIdle(); |
| 375 | assertNoStartingWindow(token1); |
| 376 | assertHasStartingWindow(token2); |
| 377 | } |
| 378 | |
| 379 | @Test |
| 380 | public void testTransferStartingWindowWhileCreating() { |
| 381 | final WindowTestUtils.TestAppWindowToken token1 = createIsolatedTestAppWindowToken(); |
| 382 | final WindowTestUtils.TestAppWindowToken token2 = createIsolatedTestAppWindowToken(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 383 | ((TestWindowManagerPolicy) token1.mWmService.mPolicy).setRunnableWhenAddingSplashScreen( |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 384 | () -> { |
| 385 | // Surprise, ...! Transfer window in the middle of the creation flow. |
| 386 | token2.addStartingWindow(mPackageName, |
| 387 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, |
| 388 | token1.appToken.asBinder(), true, true, false, |
| 389 | true, false, false); |
| 390 | }); |
| 391 | token1.addStartingWindow(mPackageName, |
| 392 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 393 | false, false); |
| 394 | waitUntilHandlersIdle(); |
| 395 | assertNoStartingWindow(token1); |
| 396 | assertHasStartingWindow(token2); |
| 397 | } |
| 398 | |
| 399 | private WindowTestUtils.TestAppWindowToken createIsolatedTestAppWindowToken() { |
| 400 | final TaskStack taskStack = createTaskStackOnDisplay(mDisplayContent); |
| 401 | final Task task = createTaskInStack(taskStack, 0 /* userId */); |
| 402 | return createTestAppWindowTokenForGivenTask(task); |
| 403 | } |
| 404 | |
| 405 | private WindowTestUtils.TestAppWindowToken createTestAppWindowTokenForGivenTask(Task task) { |
| 406 | final WindowTestUtils.TestAppWindowToken appToken = |
| 407 | WindowTestUtils.createTestAppWindowToken(mDisplayContent); |
| 408 | task.addChild(appToken, 0); |
| 409 | waitUntilHandlersIdle(); |
| 410 | return appToken; |
| 411 | } |
| 412 | |
| 413 | @Test |
| 414 | public void testTryTransferStartingWindowFromHiddenAboveToken() { |
| 415 | // Add two tasks on top of each other. |
| 416 | final WindowTestUtils.TestAppWindowToken tokenTop = createIsolatedTestAppWindowToken(); |
| 417 | final WindowTestUtils.TestAppWindowToken tokenBottom = |
| 418 | createTestAppWindowTokenForGivenTask(tokenTop.getTask()); |
| 419 | |
| 420 | // Add a starting window. |
| 421 | tokenTop.addStartingWindow(mPackageName, |
| 422 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 423 | false, false); |
| 424 | waitUntilHandlersIdle(); |
| 425 | |
| 426 | // Make the top one invisible, and try transferring the starting window from the top to the |
| 427 | // bottom one. |
| 428 | tokenTop.setVisibility(false, false); |
| 429 | tokenBottom.transferStartingWindowFromHiddenAboveTokenIfNeeded(); |
Yunfan Chen | dcb1fcf | 2019-02-07 19:08:41 +0900 | [diff] [blame] | 430 | waitUntilHandlersIdle(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 431 | |
| 432 | // Assert that the bottom window now has the starting window. |
| 433 | assertNoStartingWindow(tokenTop); |
| 434 | assertHasStartingWindow(tokenBottom); |
| 435 | } |
| 436 | |
| 437 | @Test |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 438 | public void testTransitionAnimationPositionAndBounds() { |
| 439 | final Rect stackBounds = new Rect( |
| 440 | 0/* left */, 0 /* top */, 1000 /* right */, 1000 /* bottom */); |
| 441 | final Rect taskBounds = new Rect( |
| 442 | 100/* left */, 200 /* top */, 600 /* right */, 600 /* bottom */); |
| 443 | mStack.setBounds(stackBounds); |
| 444 | mTask.setBounds(taskBounds); |
| 445 | |
| 446 | mTask.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 447 | assertTransitionAnimationPositionAndBounds(taskBounds.left, taskBounds.top, stackBounds); |
| 448 | |
| 449 | mTask.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 450 | assertTransitionAnimationPositionAndBounds(stackBounds.left, stackBounds.top, stackBounds); |
| 451 | } |
| 452 | |
| 453 | private void assertTransitionAnimationPositionAndBounds(int expectedX, int expectedY, |
| 454 | Rect expectedBounds) { |
| 455 | final Point outPosition = new Point(); |
| 456 | final Rect outBounds = new Rect(); |
| 457 | mToken.getAnimationBounds(outPosition, outBounds); |
| 458 | assertEquals(expectedX, outPosition.x); |
| 459 | assertEquals(expectedY, outPosition.y); |
| 460 | assertEquals(expectedBounds, outBounds); |
| 461 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 462 | |
| 463 | private void assertHasStartingWindow(AppWindowToken atoken) { |
| 464 | assertNotNull(atoken.startingSurface); |
| 465 | assertNotNull(atoken.startingData); |
| 466 | assertNotNull(atoken.startingWindow); |
| 467 | } |
| 468 | |
| 469 | private void assertNoStartingWindow(AppWindowToken atoken) { |
| 470 | assertNull(atoken.startingSurface); |
| 471 | assertNull(atoken.startingWindow); |
| 472 | assertNull(atoken.startingData); |
| 473 | atoken.forAllWindows(windowState -> { |
| 474 | assertFalse(windowState.getBaseType() == TYPE_APPLICATION_STARTING); |
| 475 | }, true); |
| 476 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 477 | } |