blob: bc850170d4b2b2dcc158e32e78f45578bbe1831c [file] [log] [blame]
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001/*
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
14 * limitations under the License
15 */
16
17package com.android.server.wm;
18
Jorim Jaggi829b9cd2017-01-23 16:20:53 +010019import android.app.ActivityManager.TaskDescription;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010020import android.app.ActivityManagerInternal;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080021import android.content.res.Configuration;
22import android.graphics.Rect;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080023import android.hardware.display.DisplayManagerGlobal;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080024import android.os.Binder;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080025import android.view.Display;
26import android.view.DisplayInfo;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080027import android.view.IApplicationToken;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080028import org.junit.Assert;
29import org.junit.Before;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010030import org.mockito.Mock;
31import org.mockito.Mockito;
32import org.mockito.MockitoAnnotations;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080033
Wale Ogunwale1666e312016-12-16 11:27:18 -080034import android.app.ActivityManager.TaskSnapshot;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080035import android.content.Context;
36import android.os.IBinder;
37import android.support.test.InstrumentationRegistry;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080038import android.view.IWindow;
39import android.view.WindowManager;
40
41import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID;
42import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080043import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080044import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080045import static android.content.res.Configuration.EMPTY;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080046import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080047import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
48import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
50import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
51import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
52import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
53import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
54import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
55import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
56import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
57import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080058import static com.android.server.wm.WindowContainer.POSITION_TOP;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080059import static org.mockito.Mockito.mock;
60
Jorim Jaggi9bafc712017-01-19 17:28:30 +010061import com.android.server.AttributeCache;
62import com.android.server.LocalServices;
63
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080064/**
65 * Common base class for window manager unit test classes.
66 */
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080067class WindowTestsBase {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080068 static WindowManagerService sWm = null;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010069 static TestWindowManagerPolicy sPolicy = null;
70 private final static IWindow sIWindow = new TestIWindow();
71 private final static Session sMockSession = mock(Session.class);
Andrii Kulian367ff7f2017-01-25 19:45:34 -080072 private static int sNextDisplayId = Display.DEFAULT_DISPLAY + 1;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080073 static int sNextStackId = FIRST_DYNAMIC_STACK_ID;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080074 private static int sNextTaskId = 0;
75
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080076 private static boolean sOneTimeSetupDone = false;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080077 static DisplayContent sDisplayContent;
Andrii Kulian367ff7f2017-01-25 19:45:34 -080078 static DisplayInfo sDisplayInfo = new DisplayInfo();
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080079 static WindowLayersController sLayersController;
80 static WindowState sWallpaperWindow;
81 static WindowState sImeWindow;
82 static WindowState sImeDialogWindow;
83 static WindowState sStatusBarWindow;
84 static WindowState sDockedDividerWindow;
85 static WindowState sNavBarWindow;
86 static WindowState sAppWindow;
87 static WindowState sChildAppWindowAbove;
88 static WindowState sChildAppWindowBelow;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010089 static @Mock ActivityManagerInternal sMockAm;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080090
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080091 @Before
92 public void setUp() throws Exception {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080093 if (sOneTimeSetupDone) {
Jorim Jaggi9bafc712017-01-19 17:28:30 +010094 Mockito.reset(sMockAm);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080095 return;
96 }
97 sOneTimeSetupDone = true;
Jorim Jaggi9bafc712017-01-19 17:28:30 +010098 MockitoAnnotations.initMocks(this);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080099 final Context context = InstrumentationRegistry.getTargetContext();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100100 LocalServices.addService(ActivityManagerInternal.class, sMockAm);
101 AttributeCache.init(context);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800102 sWm = TestWindowManagerPolicy.getWindowManagerService(context);
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100103 sPolicy = (TestWindowManagerPolicy) sWm.mPolicy;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800104 sLayersController = new WindowLayersController(sWm);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800105 sDisplayContent = sWm.mRoot.getDisplayContent(context.getDisplay().getDisplayId());
106 if (sDisplayContent != null) {
107 sDisplayContent.removeImmediately();
108 }
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800109 // Make sure that display ids don't overlap, so there won't be several displays with same
110 // ids among RootWindowContainer children.
111 for (DisplayContent dc : sWm.mRoot.mChildren) {
112 if (dc.getDisplayId() >= sNextDisplayId) {
113 sNextDisplayId = dc.getDisplayId() + 1;
114 }
115 }
116 context.getDisplay().getDisplayInfo(sDisplayInfo);
117 sDisplayContent = createNewDisplay();
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100118 sWm.mDisplayEnabled = true;
119 sWm.mDisplayReady = true;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800120
121 // Set-up some common windows.
122 sWallpaperWindow = createWindow(null, TYPE_WALLPAPER, sDisplayContent, "wallpaperWindow");
123 sImeWindow = createWindow(null, TYPE_INPUT_METHOD, sDisplayContent, "sImeWindow");
124 sImeDialogWindow =
125 createWindow(null, TYPE_INPUT_METHOD_DIALOG, sDisplayContent, "sImeDialogWindow");
126 sStatusBarWindow = createWindow(null, TYPE_STATUS_BAR, sDisplayContent, "sStatusBarWindow");
127 sNavBarWindow =
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800128 createWindow(null, TYPE_NAVIGATION_BAR, sDisplayContent, "sNavBarWindow");
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800129 sDockedDividerWindow =
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800130 createWindow(null, TYPE_DOCK_DIVIDER, sDisplayContent, "sDockedDividerWindow");
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800131 sAppWindow = createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "sAppWindow");
132 sChildAppWindowAbove = createWindow(sAppWindow,
133 TYPE_APPLICATION_ATTACHED_DIALOG, sAppWindow.mToken, "sChildAppWindowAbove");
134 sChildAppWindowBelow = createWindow(sAppWindow,
135 TYPE_APPLICATION_MEDIA_OVERLAY, sAppWindow.mToken, "sChildAppWindowBelow");
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800136 }
137
138 /** Asserts that the first entry is greater than the second entry. */
139 void assertGreaterThan(int first, int second) throws Exception {
140 Assert.assertTrue("Excepted " + first + " to be greater than " + second, first > second);
141 }
142
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100143 /**
144 * Waits until the main handler for WM has processed all messages.
145 */
146 void waitUntilHandlerIdle() {
147 sWm.mH.runWithScissors(() -> { }, 0);
148 }
149
150 private static WindowToken createWindowToken(DisplayContent dc, int type) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800151 if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800152 return new TestWindowToken(type, dc);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800153 }
154
Andrii Kuliand2765632016-12-12 22:26:34 -0800155 final TaskStack stack = createTaskStackOnDisplay(dc);
156 final Task task = createTaskInStack(stack, 0 /* userId */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800157 final TestAppWindowToken token = new TestAppWindowToken(dc);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800158 task.addChild(token, 0);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800159 return token;
160 }
161
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100162 static WindowState createWindow(WindowState parent, int type, String name) {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800163 return (parent == null)
164 ? createWindow(parent, type, sDisplayContent, name)
165 : createWindow(parent, type, parent.mToken, name);
166 }
167
Jorim Jaggi02886a82016-12-06 09:10:06 -0800168 WindowState createAppWindow(Task task, int type, String name) {
169 final AppWindowToken token = new TestAppWindowToken(sDisplayContent);
170 task.addChild(token, 0);
171 return createWindow(null, type, token, name);
172 }
173
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100174 static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800175 final WindowToken token = createWindowToken(dc, type);
176 return createWindow(parent, type, token, name);
177 }
178
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100179 static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800180 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
181 attrs.setTitle(name);
182
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100183 final WindowState w = new WindowState(sWm, sMockSession, sIWindow, token, parent, OP_NONE,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800184 0, attrs, 0, 0, false /* ownerCanAddInternalSystemWindow */);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800185 // TODO: Probably better to make this call in the WindowState ctor to avoid errors with
186 // adding it to the token...
187 token.addWindow(w);
188 return w;
189 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800190
Andrii Kuliand2765632016-12-12 22:26:34 -0800191 /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100192 static TaskStack createTaskStackOnDisplay(DisplayContent dc) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800193 return createStackControllerOnDisplay(dc).mContainer;
194 }
195
196 static StackWindowController createStackControllerOnDisplay(DisplayContent dc) {
197 final int stackId = ++sNextStackId;
198 return new StackWindowController(stackId, null, dc.getDisplayId(),
199 true /* onTop */, new Rect(), sWm);
Andrii Kuliand2765632016-12-12 22:26:34 -0800200 }
201
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800202 /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100203 static Task createTaskInStack(TaskStack stack, int userId) {
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800204 final Task newTask = new Task(sNextTaskId++, stack, userId, sWm, null, EMPTY, 0, false,
205 false, new TaskDescription(), null);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800206 stack.addTask(newTask, POSITION_TOP);
Andrii Kuliand2765632016-12-12 22:26:34 -0800207 return newTask;
208 }
209
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800210 /** Creates a {@link DisplayContent} and adds it to the system. */
211 DisplayContent createNewDisplay() {
212 final int displayId = sNextDisplayId++;
213 final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId,
214 sDisplayInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
215 return new DisplayContent(display, sWm, sLayersController, new WallpaperController(sWm));
216 }
217
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800218 /* Used so we can gain access to some protected members of the {@link WindowToken} class */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100219 static class TestWindowToken extends WindowToken {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800220
221 TestWindowToken(int type, DisplayContent dc) {
222 this(type, dc, false /* persistOnEmpty */);
223 }
224
225 TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800226 super(sWm, mock(IBinder.class), type, persistOnEmpty, dc,
227 false /* ownerCanManageAppTokens */);
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800228 }
229
230 int getWindowsCount() {
231 return mChildren.size();
232 }
233
234 boolean hasWindow(WindowState w) {
235 return mChildren.contains(w);
236 }
237 }
238
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800239 /** Used so we can gain access to some protected members of the {@link AppWindowToken} class. */
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100240 static class TestAppWindowToken extends AppWindowToken {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800241
242 TestAppWindowToken(DisplayContent dc) {
243 super(sWm, null, false, dc);
244 }
245
Winson Chung30480042017-01-26 10:55:34 -0800246 TestAppWindowToken(WindowManagerService service, IApplicationToken token,
247 boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos,
248 boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation,
249 int rotationAnimationHint, int configChanges, boolean launchTaskBehind,
250 boolean alwaysFocusable, AppWindowContainerController controller) {
251 super(service, token, voiceInteraction, dc, inputDispatchingTimeoutNanos, fullscreen,
252 showForAllUsers, targetSdk, orientation, rotationAnimationHint, configChanges,
253 launchTaskBehind, alwaysFocusable, controller);
254 }
255
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800256 int getWindowsCount() {
257 return mChildren.size();
258 }
259
260 boolean hasWindow(WindowState w) {
261 return mChildren.contains(w);
262 }
263
264 WindowState getFirstChild() {
265 return mChildren.getFirst();
266 }
267
268 WindowState getLastChild() {
269 return mChildren.getLast();
270 }
Winson Chung30480042017-01-26 10:55:34 -0800271
272 int positionInParent() {
273 return getParent().mChildren.indexOf(this);
274 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800275 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800276
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800277 /* Used so we can gain access to some protected members of the {@link Task} class */
278 class TestTask extends Task {
279
280 boolean mShouldDeferRemoval = false;
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800281 boolean mOnDisplayChangedCalled = false;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800282 private boolean mUseLocalIsAnimating = false;
283 private boolean mIsAnimating = false;
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800284
285 TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800286 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
287 boolean homeTask, TaskWindowContainerController controller) {
288 super(taskId, stack, userId, service, bounds, overrideConfig, resizeMode,
289 supportsPictureInPicture, homeTask, new TaskDescription(), controller);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800290 }
291
292 boolean shouldDeferRemoval() {
293 return mShouldDeferRemoval;
294 }
295
296 int positionInParent() {
297 return getParent().mChildren.indexOf(this);
298 }
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800299
300 @Override
301 void onDisplayChanged(DisplayContent dc) {
302 super.onDisplayChanged(dc);
303 mOnDisplayChangedCalled = true;
304 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800305
306 @Override
307 boolean isAnimating() {
308 return mUseLocalIsAnimating ? mIsAnimating : super.isAnimating();
309 }
310
311 void setLocalIsAnimating(boolean isAnimating) {
312 mUseLocalIsAnimating = true;
313 mIsAnimating = isAnimating;
314 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800315 }
316
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800317 /**
318 * Used so we can gain access to some protected members of {@link TaskWindowContainerController}
319 * class.
320 */
321 class TestTaskWindowContainerController extends TaskWindowContainerController {
322
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800323 TestTaskWindowContainerController() {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800324 this(createStackControllerOnDisplay(sDisplayContent));
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800325 }
326
Wale Ogunwale1666e312016-12-16 11:27:18 -0800327 TestTaskWindowContainerController(StackWindowController stackController) {
328 super(sNextTaskId++, new TaskWindowContainerListener() {
329 @Override
330 public void onSnapshotChanged(TaskSnapshot snapshot) {
331
332 }
333
334 @Override
335 public void requestResize(Rect bounds, int resizeMode) {
336
337 }
338 }, stackController, 0 /* userId */, null /* bounds */,
Winson Chungd3395382016-12-13 11:49:09 -0800339 EMPTY /* overrideConfig*/, RESIZE_MODE_UNRESIZEABLE,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800340 false /* supportsPictureInPicture */, false /* homeTask*/, true /* toTop*/,
341 true /* showForAllUsers */, new TaskDescription(), sWm);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800342 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800343
344 @Override
345 TestTask createTask(int taskId, TaskStack stack, int userId, Rect bounds,
Winson Chungd3395382016-12-13 11:49:09 -0800346 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800347 boolean homeTask, TaskDescription taskDescription) {
348 return new TestTask(taskId, stack, userId, mService, bounds, overrideConfig, resizeMode,
349 supportsPictureInPicture, homeTask, this);
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800350 }
351 }
352
353 class TestAppWindowContainerController extends AppWindowContainerController {
354
355 final IApplicationToken mToken;
356
357 TestAppWindowContainerController(TestTaskWindowContainerController taskController) {
358 this(taskController, new TestIApplicationToken());
359 }
360
361 TestAppWindowContainerController(TestTaskWindowContainerController taskController,
362 IApplicationToken token) {
363 super(taskController, token, null /* listener */, 0 /* index */,
364 SCREEN_ORIENTATION_UNSPECIFIED, true /* fullscreen */,
365 true /* showForAllUsers */, 0 /* configChanges */, false /* voiceInteraction */,
366 false /* launchTaskBehind */, false /* alwaysFocusable */,
367 0 /* targetSdkVersion */, 0 /* rotationAnimationHint */,
368 0 /* inputDispatchingTimeoutNanos */, sWm);
369 mToken = token;
370 }
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100371
Winson Chung30480042017-01-26 10:55:34 -0800372 @Override
373 AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token,
374 boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos,
375 boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation,
376 int rotationAnimationHint, int configChanges, boolean launchTaskBehind,
377 boolean alwaysFocusable, AppWindowContainerController controller) {
378 return new TestAppWindowToken(service, token, voiceInteraction, dc,
379 inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk,
380 orientation,
381 rotationAnimationHint, configChanges, launchTaskBehind, alwaysFocusable,
382 controller);
383 }
384
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100385 AppWindowToken getAppWindowToken() {
386 return (AppWindowToken) sDisplayContent.getWindowToken(mToken.asBinder());
387 }
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800388 }
389
390 class TestIApplicationToken implements IApplicationToken {
391
392 private final Binder mBinder = new Binder();
393 @Override
394 public IBinder asBinder() {
395 return mBinder;
396 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800397 }
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800398
399 /** Used to track resize reports. */
400 class TestWindowState extends WindowState {
401 boolean resizeReported;
402
403 TestWindowState(WindowManager.LayoutParams attrs, WindowToken token) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800404 super(sWm, sMockSession, sIWindow, token, null, OP_NONE, 0, attrs, 0, 0,
405 false /* ownerCanAddInternalSystemWindow */);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800406 }
407
408 @Override
409 void reportResized() {
410 super.reportResized();
411 resizeReported = true;
412 }
413
414 @Override
415 public boolean isGoneForLayoutLw() {
416 return false;
417 }
418
419 @Override
420 void updateResizingWindowIfNeeded() {
421 // Used in AppWindowTokenTests#testLandscapeSeascapeRotationRelayout to deceive
422 // the system that it can actually update the window.
423 boolean hadSurface = mHasSurface;
424 mHasSurface = true;
425
426 super.updateResizingWindowIfNeeded();
427
428 mHasSurface = hadSurface;
429 }
430 }
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800431}