Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [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 | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 19 | import static android.app.AppOpsManager.OP_NONE; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 22 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 23 | import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 24 | import static android.view.View.VISIBLE; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
| 30 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 35 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 36 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 37 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 38 | import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; |
| 39 | |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 40 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; |
| 41 | |
| 42 | import static org.mockito.Mockito.mock; |
| 43 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 44 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 45 | import android.content.Context; |
| 46 | import android.content.res.Configuration; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 47 | import android.hardware.display.DisplayManagerGlobal; |
| 48 | import android.testing.DexmakerShareClassLoaderRule; |
| 49 | import android.util.Log; |
| 50 | import android.view.Display; |
| 51 | import android.view.DisplayInfo; |
| 52 | import android.view.IWindow; |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 53 | import android.view.Surface; |
| 54 | import android.view.SurfaceControl.Transaction; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 55 | import android.view.WindowManager; |
| 56 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 57 | import com.android.server.AttributeCache; |
Garfield Tan | 26835f0 | 2019-02-07 14:38:38 -0800 | [diff] [blame] | 58 | import com.android.server.wm.utils.MockTracker; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 59 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 60 | import org.junit.After; |
Tadashi G. Takaoka | 5a108b8 | 2018-12-13 17:09:12 +0900 | [diff] [blame] | 61 | import org.junit.AfterClass; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 62 | import org.junit.Before; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 63 | import org.junit.BeforeClass; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 64 | import org.junit.Rule; |
| 65 | |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 66 | import java.io.IOException; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 67 | import java.util.HashSet; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 68 | import java.util.LinkedList; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 69 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 70 | /** |
| 71 | * Common base class for window manager unit test classes. |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 72 | * |
| 73 | * Make sure any requests to WM hold the WM lock if needed b/73966377 |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 74 | */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 75 | class WindowTestsBase { |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 76 | private static final String TAG = WindowTestsBase.class.getSimpleName(); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 77 | |
| 78 | WindowManagerService mWm; |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 79 | private final IWindow mIWindow = new TestIWindow(); |
| 80 | private Session mMockSession; |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 81 | // The default display is removed in {@link #setUp} and then we iterate over all displays to |
| 82 | // make sure we don't collide with any existing display. If we run into no other display, the |
Bryce Lee | 6272c7f | 2017-03-17 17:22:35 -0700 | [diff] [blame] | 83 | // added display should be treated as default. This cannot be the default display |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 84 | private static int sNextDisplayId = DEFAULT_DISPLAY + 1; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 85 | static int sNextStackId = 1000; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 86 | |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 87 | /** Non-default display. */ |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 88 | DisplayContent mDisplayContent; |
| 89 | DisplayInfo mDisplayInfo = new DisplayInfo(); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 90 | WindowState mWallpaperWindow; |
| 91 | WindowState mImeWindow; |
| 92 | WindowState mImeDialogWindow; |
| 93 | WindowState mStatusBarWindow; |
| 94 | WindowState mDockedDividerWindow; |
| 95 | WindowState mNavBarWindow; |
| 96 | WindowState mAppWindow; |
| 97 | WindowState mChildAppWindowAbove; |
| 98 | WindowState mChildAppWindowBelow; |
| 99 | HashSet<WindowState> mCommonWindows; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 100 | |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 101 | private MockTracker mMockTracker; |
| 102 | |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 103 | /** |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 104 | * Spied {@link Transaction} class than can be used to verify calls. |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 105 | */ |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 106 | Transaction mTransaction; |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 107 | |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 108 | @Rule |
| 109 | public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule = |
| 110 | new DexmakerShareClassLoaderRule(); |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 111 | @Rule |
| 112 | public final SystemServicesTestRule mSystemServicesTestRule = new SystemServicesTestRule(); |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 113 | |
Tadashi G. Takaoka | 5a108b8 | 2018-12-13 17:09:12 +0900 | [diff] [blame] | 114 | static WindowState.PowerManagerWrapper sPowerManagerWrapper; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 115 | |
| 116 | @BeforeClass |
| 117 | public static void setUpOnceBase() { |
| 118 | AttributeCache.init(getInstrumentation().getTargetContext()); |
Tadashi G. Takaoka | 5a108b8 | 2018-12-13 17:09:12 +0900 | [diff] [blame] | 119 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 120 | sPowerManagerWrapper = mock(WindowState.PowerManagerWrapper.class); |
| 121 | } |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 122 | |
Tadashi G. Takaoka | 5a108b8 | 2018-12-13 17:09:12 +0900 | [diff] [blame] | 123 | @AfterClass |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 124 | public static void tearDownOnceBase() throws IOException { |
| 125 | sPowerManagerWrapper = null; |
Tadashi G. Takaoka | 5a108b8 | 2018-12-13 17:09:12 +0900 | [diff] [blame] | 126 | } |
| 127 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 128 | @Before |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 129 | public void setUpBase() { |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 130 | mMockTracker = new MockTracker(); |
| 131 | |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 132 | // If @Before throws an exception, the error isn't logged. This will make sure any failures |
| 133 | // in the set up are clear. This can be removed when b/37850063 is fixed. |
| 134 | try { |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 135 | mMockSession = mock(Session.class); |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 136 | mTransaction = spy(StubTransaction.class); |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 137 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 138 | final Context context = getInstrumentation().getTargetContext(); |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 139 | |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 140 | mWm = mSystemServicesTestRule.getWindowManagerService(); |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 141 | |
| 142 | // Setup factory classes to prevent calls to native code. |
| 143 | |
| 144 | // Return a spied Transaction class than can be used to verify calls. |
| 145 | mWm.mTransactionFactory = () -> mTransaction; |
| 146 | // Return a SurfaceControl.Builder class that creates mocked SurfaceControl instances. |
| 147 | mWm.mSurfaceBuilderFactory = (unused) -> new MockSurfaceControlBuilder(); |
| 148 | // Return mocked Surface instances. |
| 149 | mWm.mSurfaceFactory = () -> mock(Surface.class); |
| 150 | |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 151 | beforeCreateDisplay(); |
| 152 | |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 153 | context.getDisplay().getDisplayInfo(mDisplayInfo); |
| 154 | mDisplayContent = createNewDisplay(); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 155 | mWm.mDisplayEnabled = true; |
| 156 | mWm.mDisplayReady = true; |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 157 | |
| 158 | // Set-up some common windows. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 159 | mCommonWindows = new HashSet<>(); |
| 160 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 161 | mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow"); |
| 162 | mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow"); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 163 | mDisplayContent.mInputMethodWindow = mImeWindow; |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 164 | mImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG, |
| 165 | "mImeDialogWindow"); |
| 166 | mStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "mStatusBarWindow"); |
| 167 | mNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "mNavBarWindow"); |
| 168 | mDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER, |
| 169 | "mDockedDividerWindow"); |
| 170 | mAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "mAppWindow"); |
| 171 | mChildAppWindowAbove = createCommonWindow(mAppWindow, |
| 172 | TYPE_APPLICATION_ATTACHED_DIALOG, |
| 173 | "mChildAppWindowAbove"); |
| 174 | mChildAppWindowBelow = createCommonWindow(mAppWindow, |
| 175 | TYPE_APPLICATION_MEDIA_OVERLAY, |
| 176 | "mChildAppWindowBelow"); |
| 177 | } |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 178 | // Adding a display will cause freezing the display. Make sure to wait until it's |
| 179 | // unfrozen to not run into race conditions with the tests. |
| 180 | waitUntilHandlersIdle(); |
| 181 | } catch (Exception e) { |
| 182 | Log.e(TAG, "Failed to set up test", e); |
| 183 | throw e; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 184 | } |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 187 | void beforeCreateDisplay() { |
| 188 | // Called before display is created. |
| 189 | } |
| 190 | |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 191 | @After |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 192 | public void tearDownBase() { |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 193 | // If @After throws an exception, the error isn't logged. This will make sure any failures |
| 194 | // in the tear down are clear. This can be removed when b/37850063 is fixed. |
| 195 | try { |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 196 | // Test may schedule to perform surface placement or other messages. Wait until a |
| 197 | // stable state to clean up for consistency. |
| 198 | waitUntilHandlersIdle(); |
| 199 | |
| 200 | final LinkedList<WindowState> nonCommonWindows = new LinkedList<>(); |
Wale Ogunwale | 027f475 | 2017-05-12 10:37:16 -0700 | [diff] [blame] | 201 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 202 | synchronized (mWm.mGlobalLock) { |
| 203 | mWm.mRoot.forAllWindows(w -> { |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 204 | if (!mCommonWindows.contains(w)) { |
| 205 | nonCommonWindows.addLast(w); |
| 206 | } |
| 207 | }, true /* traverseTopToBottom */); |
| 208 | |
| 209 | while (!nonCommonWindows.isEmpty()) { |
| 210 | nonCommonWindows.pollLast().removeImmediately(); |
Wale Ogunwale | 027f475 | 2017-05-12 10:37:16 -0700 | [diff] [blame] | 211 | } |
Wale Ogunwale | 027f475 | 2017-05-12 10:37:16 -0700 | [diff] [blame] | 212 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 213 | for (int i = mWm.mRoot.mChildren.size() - 1; i >= 0; --i) { |
| 214 | final DisplayContent displayContent = mWm.mRoot.mChildren.get(i); |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 215 | if (!displayContent.isDefaultDisplay) { |
| 216 | displayContent.removeImmediately(); |
| 217 | } |
| 218 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 219 | // Remove app transition & window freeze timeout callbacks to prevent unnecessary |
| 220 | // actions after test. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 221 | mWm.getDefaultDisplayContentLocked().mAppTransition |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 222 | .removeAppTransitionTimeoutCallbacks(); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 223 | mWm.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 224 | mDisplayContent.mInputMethodTarget = null; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 225 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 226 | |
Tadashi G. Takaoka | a5f7c2c | 2019-01-09 12:17:14 +0900 | [diff] [blame] | 227 | // Cleaned up everything in Handler. |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 228 | mSystemServicesTestRule.cleanupWindowManagerHandlers(); |
chaviw | 578b6fe | 2018-03-06 16:24:17 -0800 | [diff] [blame] | 229 | } catch (Exception e) { |
| 230 | Log.e(TAG, "Failed to tear down test", e); |
| 231 | throw e; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 232 | } |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 233 | |
| 234 | mMockTracker.close(); |
| 235 | mMockTracker = null; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 238 | private WindowState createCommonWindow(WindowState parent, int type, String name) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 239 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 240 | final WindowState win = createWindow(parent, type, name); |
| 241 | mCommonWindows.add(win); |
| 242 | // Prevent common windows from been IMe targets |
| 243 | win.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 244 | return win; |
| 245 | } |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 248 | /** |
| 249 | * Waits until the main handler for WM has processed all messages. |
| 250 | */ |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 251 | void waitUntilHandlersIdle() { |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 252 | mSystemServicesTestRule.waitUntilWindowManagerHandlersIdle(); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 255 | private WindowToken createWindowToken( |
| 256 | DisplayContent dc, int windowingMode, int activityType, int type) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 257 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 258 | if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) { |
| 259 | return WindowTestUtils.createTestWindowToken(type, dc); |
| 260 | } |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 261 | |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 262 | return createAppWindowToken(dc, windowingMode, activityType); |
| 263 | } |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | AppWindowToken createAppWindowToken(DisplayContent dc, int windowingMode, int activityType) { |
Vishnu Nair | a297726 | 2018-07-26 13:31:26 -0700 | [diff] [blame] | 267 | return createTestAppWindowToken(dc, windowingMode, activityType); |
| 268 | } |
| 269 | |
| 270 | WindowTestUtils.TestAppWindowToken createTestAppWindowToken(DisplayContent dc, int |
| 271 | windowingMode, int activityType) { |
Vishnu Nair | f77d53d | 2019-02-20 14:38:50 -0800 | [diff] [blame] | 272 | return createTestAppWindowToken(dc, windowingMode, activityType, |
Vishnu Nair | aab3d3d | 2019-03-08 10:34:44 -0800 | [diff] [blame] | 273 | false /*skipOnParentChanged */); |
Vishnu Nair | f77d53d | 2019-02-20 14:38:50 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | WindowTestUtils.TestAppWindowToken createTestAppWindowToken(DisplayContent dc, int |
| 277 | windowingMode, int activityType, boolean skipOnParentChanged) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 278 | final TaskStack stack = createTaskStackOnDisplay(windowingMode, activityType, dc); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 279 | final Task task = createTaskInStack(stack, 0 /* userId */); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 280 | final WindowTestUtils.TestAppWindowToken appWindowToken = |
Vishnu Nair | f77d53d | 2019-02-20 14:38:50 -0800 | [diff] [blame] | 281 | WindowTestUtils.createTestAppWindowToken(dc, skipOnParentChanged); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 282 | task.addChild(appWindowToken, 0); |
| 283 | return appWindowToken; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 286 | WindowState createWindow(WindowState parent, int type, String name) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 287 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 288 | return (parent == null) |
| 289 | ? createWindow(parent, type, mDisplayContent, name) |
| 290 | : createWindow(parent, type, parent.mToken, name); |
| 291 | } |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 294 | WindowState createWindow(WindowState parent, int type, String name, int ownerId) { |
| 295 | synchronized (mWm.mGlobalLock) { |
| 296 | return (parent == null) |
| 297 | ? createWindow(parent, type, mDisplayContent, name, ownerId) |
| 298 | : createWindow(parent, type, parent.mToken, name, ownerId); |
| 299 | } |
| 300 | } |
| 301 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 302 | WindowState createWindowOnStack(WindowState parent, int windowingMode, int activityType, |
| 303 | int type, DisplayContent dc, String name) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 304 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 305 | final WindowToken token = createWindowToken(dc, windowingMode, activityType, type); |
| 306 | return createWindow(parent, type, token, name); |
| 307 | } |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 310 | WindowState createAppWindow(Task task, int type, String name) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 311 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 312 | final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(mDisplayContent); |
| 313 | task.addChild(token, 0); |
| 314 | return createWindow(null, type, token, name); |
| 315 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 318 | WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 319 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 320 | final WindowToken token = createWindowToken( |
| 321 | dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type); |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 322 | return createWindow(parent, type, token, name, 0 /* ownerId */); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name, |
| 327 | int ownerId) { |
| 328 | synchronized (mWm.mGlobalLock) { |
| 329 | final WindowToken token = createWindowToken( |
| 330 | dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type); |
| 331 | return createWindow(parent, type, token, name, ownerId); |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 332 | } |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 335 | WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name, |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 336 | boolean ownerCanAddInternalSystemWindow) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 337 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 338 | final WindowToken token = createWindowToken( |
| 339 | dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type); |
| 340 | return createWindow(parent, type, token, name, 0 /* ownerId */, |
| 341 | ownerCanAddInternalSystemWindow); |
| 342 | } |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 345 | WindowState createWindow(WindowState parent, int type, WindowToken token, String name) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 346 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 347 | return createWindow(parent, type, token, name, 0 /* ownerId */, |
| 348 | false /* ownerCanAddInternalSystemWindow */); |
| 349 | } |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 352 | WindowState createWindow(WindowState parent, int type, WindowToken token, String name, |
Michal Karpinski | a606a29 | 2019-01-12 17:29:52 +0000 | [diff] [blame] | 353 | int ownerId) { |
| 354 | synchronized (mWm.mGlobalLock) { |
| 355 | return createWindow(parent, type, token, name, ownerId, |
| 356 | false /* ownerCanAddInternalSystemWindow */); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | WindowState createWindow(WindowState parent, int type, WindowToken token, String name, |
Daichi Hirono | da0748d | 2017-12-13 12:48:59 +0900 | [diff] [blame] | 361 | int ownerId, boolean ownerCanAddInternalSystemWindow) { |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 362 | return createWindow(parent, type, token, name, ownerId, ownerCanAddInternalSystemWindow, |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 363 | mWm, mMockSession, mIWindow); |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static WindowState createWindow(WindowState parent, int type, WindowToken token, |
| 367 | String name, int ownerId, boolean ownerCanAddInternalSystemWindow, |
| 368 | WindowManagerService service, Session session, IWindow iWindow) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 369 | synchronized (service.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 370 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type); |
| 371 | attrs.setTitle(name); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 372 | |
Adrian Roos | 3150dbf | 2018-03-28 18:06:52 +0200 | [diff] [blame] | 373 | final WindowState w = new WindowState(service, session, iWindow, token, parent, |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 374 | OP_NONE, |
| 375 | 0, attrs, VISIBLE, ownerId, ownerCanAddInternalSystemWindow, |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 376 | sPowerManagerWrapper); |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 377 | // TODO: Probably better to make this call in the WindowState ctor to avoid errors with |
| 378 | // adding it to the token... |
| 379 | token.addWindow(w); |
| 380 | return w; |
| 381 | } |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 382 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 383 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 384 | /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */ |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 385 | TaskStack createTaskStackOnDisplay(DisplayContent dc) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 386 | synchronized (mWm.mGlobalLock) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 387 | return createTaskStackOnDisplay(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, dc); |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 388 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 391 | TaskStack createTaskStackOnDisplay(int windowingMode, int activityType, DisplayContent dc) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 392 | synchronized (mWm.mGlobalLock) { |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 393 | final Configuration overrideConfig = new Configuration(); |
| 394 | overrideConfig.windowConfiguration.setWindowingMode(windowingMode); |
| 395 | overrideConfig.windowConfiguration.setActivityType(activityType); |
| 396 | final int stackId = ++sNextStackId; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 397 | final TaskStack stack = new TaskStack(mWm, stackId, mock(ActivityStack.class)); |
| 398 | dc.setStackOnDisplay(stackId, true, stack); |
| 399 | stack.onRequestedOverrideConfigurationChanged(overrideConfig); |
| 400 | return stack; |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 401 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 404 | /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */ |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 405 | Task createTaskInStack(TaskStack stack, int userId) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 406 | return WindowTestUtils.createTaskInStack(mWm, stack, userId); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 409 | /** Creates a {@link DisplayContent} and adds it to the system. */ |
| 410 | DisplayContent createNewDisplay() { |
Chilun | 8753ad3 | 2018-10-09 15:56:45 +0800 | [diff] [blame] | 411 | return createNewDisplay(mDisplayInfo); |
| 412 | } |
| 413 | |
| 414 | /** Creates a {@link DisplayContent} and adds it to the system. */ |
| 415 | DisplayContent createNewDisplay(DisplayInfo displayInfo) { |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 416 | final int displayId = sNextDisplayId++; |
| 417 | final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId, |
Chilun | 8753ad3 | 2018-10-09 15:56:45 +0800 | [diff] [blame] | 418 | displayInfo, DEFAULT_DISPLAY_ADJUSTMENTS); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 419 | synchronized (mWm.mGlobalLock) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 420 | return new DisplayContent(display, mWm, mock(ActivityDisplay.class)); |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 421 | } |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 422 | } |
| 423 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 424 | /** |
| 425 | * Creates a {@link DisplayContent} with given display state and adds it to the system. |
| 426 | * |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 427 | * @param displayState For initializing the state of the display. See |
| 428 | * {@link Display#getState()}. |
| 429 | */ |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 430 | DisplayContent createNewDisplay(int displayState) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 431 | // Leverage main display info & initialize it with display state for given displayId. |
| 432 | DisplayInfo displayInfo = new DisplayInfo(); |
| 433 | displayInfo.copyFrom(mDisplayInfo); |
| 434 | displayInfo.state = displayState; |
| 435 | final int displayId = sNextDisplayId++; |
| 436 | final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId, |
| 437 | displayInfo, DEFAULT_DISPLAY_ADJUSTMENTS); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 438 | synchronized (mWm.mGlobalLock) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 439 | // Display creation is driven by DisplayWindowController via ActivityStackSupervisor. |
| 440 | // We skip those steps here. |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 441 | final ActivityDisplay mockAd = mock(ActivityDisplay.class); |
| 442 | return mWm.mRoot.createDisplayContent(display, mockAd); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 446 | /** Creates a {@link com.android.server.wm.WindowTestUtils.TestWindowState} */ |
| 447 | WindowTestUtils.TestWindowState createWindowState(WindowManager.LayoutParams attrs, |
| 448 | WindowToken token) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 449 | synchronized (mWm.mGlobalLock) { |
| 450 | return new WindowTestUtils.TestWindowState(mWm, mMockSession, mIWindow, attrs, token); |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 451 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 452 | } |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 453 | } |