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