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