blob: 9f57f4993ed59c6f150efb835a5e9d3bac1da1f1 [file] [log] [blame]
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001/*
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 Jaggi9bafc712017-01-19 17:28:30 +010019import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Andrii Kulian3a1619d2017-07-07 14:38:09 -070020import static android.view.WindowManagerPolicy.NAV_BAR_BOTTOM;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070021
22import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
23
24import static org.mockito.ArgumentMatchers.anyString;
jackqdyulei455e90a2017-02-09 15:29:16 -080025import static org.mockito.Matchers.anyInt;
26import static org.mockito.Mockito.doReturn;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070027import static org.mockito.Mockito.mock;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080028import static org.mockito.Mockito.any;
29import static org.mockito.Mockito.doAnswer;
jackqdyulei455e90a2017-02-09 15:29:16 -080030
31import android.os.PowerSaveState;
Steven Timotiusaf03df62017-07-18 16:56:43 -070032import android.util.proto.ProtoOutputStream;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080033import org.mockito.invocation.InvocationOnMock;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070034
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080035import android.annotation.Nullable;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080036import android.app.ActivityManagerInternal;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080037import android.content.Context;
38import android.content.res.CompatibilityInfo;
39import android.content.res.Configuration;
40import android.graphics.Rect;
Andrii Kulian4ede3e02017-01-12 11:52:31 -080041import android.hardware.display.DisplayManagerInternal;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080042import android.os.Bundle;
43import android.os.IBinder;
44import android.os.RemoteException;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080045import android.view.Display;
46import android.view.IWindowManager;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070047import android.view.InputChannel;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080048import android.view.KeyEvent;
49import android.view.WindowManager;
50import android.view.WindowManagerPolicy;
51import android.view.animation.Animation;
Andrii Kulian4ede3e02017-01-12 11:52:31 -080052import android.os.PowerManagerInternal;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080053
54import com.android.internal.policy.IKeyguardDismissCallback;
55import com.android.internal.policy.IShortcutService;
56import com.android.server.input.InputManagerService;
Andrii Kulian4ede3e02017-01-12 11:52:31 -080057import com.android.server.LocalServices;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080058
59import java.io.PrintWriter;
60
Wale Ogunwalecfca2582016-10-19 09:53:25 -070061class TestWindowManagerPolicy implements WindowManagerPolicy {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070062 private static final String TAG = "TestWindowManagerPolicy";
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070063
Wale Ogunwale51362492016-09-08 17:49:17 -070064 private static WindowManagerService sWm = null;
65
Andrii Kulian4ede3e02017-01-12 11:52:31 -080066 int rotationToReport = 0;
67
Jorim Jaggi9bafc712017-01-19 17:28:30 +010068 private Runnable mRunnableWhenAddingSplashScreen;
69
Wale Ogunwale51362492016-09-08 17:49:17 -070070 static synchronized WindowManagerService getWindowManagerService(Context context) {
71 if (sWm == null) {
72 // We only want to do this once for the test process as we don't want WM to try to
73 // register a bunch of local services again.
Andrii Kulian4ede3e02017-01-12 11:52:31 -080074 if (LocalServices.getService(DisplayManagerInternal.class) == null) {
75 LocalServices.addService(DisplayManagerInternal.class,
76 mock(DisplayManagerInternal.class));
77 }
78 if (LocalServices.getService(PowerManagerInternal.class) == null) {
79 LocalServices.addService(PowerManagerInternal.class,
80 mock(PowerManagerInternal.class));
jackqdyulei455e90a2017-02-09 15:29:16 -080081 final PowerManagerInternal pm =
82 LocalServices.getService(PowerManagerInternal.class);
83 PowerSaveState state = new PowerSaveState.Builder().build();
84 doReturn(state).when(pm).getLowPowerState(anyInt());
Andrii Kulian4ede3e02017-01-12 11:52:31 -080085 }
Wale Ogunwale17f175c2017-02-07 16:54:10 -080086 if (LocalServices.getService(ActivityManagerInternal.class) == null) {
87 LocalServices.addService(ActivityManagerInternal.class,
88 mock(ActivityManagerInternal.class));
89 final ActivityManagerInternal am =
90 LocalServices.getService(ActivityManagerInternal.class);
91 doAnswer((InvocationOnMock invocationOnMock) -> {
Paul Duffin192bb0b2017-03-09 18:49:41 +000092 final Runnable runnable = invocationOnMock.<Runnable>getArgument(0);
Wale Ogunwale17f175c2017-02-07 16:54:10 -080093 if (runnable != null) {
94 runnable.run();
95 }
96 return null;
97 }).when(am).notifyKeyguardFlagsChanged(any());
98 }
Bryce Lee04ab3462017-04-10 15:06:33 -070099
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700100 InputManagerService ims = mock(InputManagerService.class);
101 // InputChannel is final and can't be mocked.
102 InputChannel[] input = InputChannel.openInputChannelPair(TAG_WM);
103 if (input != null && input.length > 1) {
104 doReturn(input[1]).when(ims).monitorInput(anyString());
105 }
106
107 sWm = WindowManagerService.main(context, ims, true, false,
Wale Ogunwalecfca2582016-10-19 09:53:25 -0700108 false, new TestWindowManagerPolicy());
Wale Ogunwale51362492016-09-08 17:49:17 -0700109 }
110 return sWm;
111 }
112
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700113 @Override
114 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)
115 throws RemoteException {
116
117 }
118
119 @Override
120 public void init(Context context, IWindowManager windowManager,
121 WindowManagerFuncs windowManagerFuncs) {
122
123 }
124
125 @Override
126 public boolean isDefaultOrientationForced() {
127 return false;
128 }
129
130 @Override
131 public void setInitialDisplaySize(Display display, int width, int height, int density) {
132
133 }
134
135 @Override
136 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
137
138 }
139
140 @Override
141 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
142 return 0;
143 }
144
145 @Override
146 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
147 return false;
148 }
149
150 @Override
151 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
152
153 }
154
155 @Override
156 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
157 int navigationPresence) {
158
159 }
160
161 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700162 public int getMaxWallpaperLayer() {
163 return 0;
164 }
165
166 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800167 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
168 int displayId) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700169 return 0;
170 }
171
172 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800173 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
174 int displayId) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700175 return 0;
176 }
177
178 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800179 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
180 int displayId) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700181 return 0;
182 }
183
184 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800185 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
186 int displayId) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700187 return 0;
188 }
189
190 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700191 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
192 return false;
193 }
194
195 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200196 public boolean canBeHiddenByKeyguardLw(WindowState win) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700197 return false;
198 }
199
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100200 /**
201 * Sets a runnable to run when adding a splash screen which gets executed after the window has
202 * been added but before returning the surface.
203 */
204 void setRunnableWhenAddingSplashScreen(Runnable r) {
205 mRunnableWhenAddingSplashScreen = r;
206 }
207
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700208 @Override
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800209 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme,
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700210 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800211 int logo, int windowFlags, Configuration overrideConfig, int displayId) {
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100212 final com.android.server.wm.WindowState window;
213 final AppWindowToken atoken;
214 synchronized (sWm.mWindowMap) {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700215 atoken = sWm.mRoot.getAppWindowToken(appToken);
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100216 window = WindowTestsBase.createWindow(null, TYPE_APPLICATION_STARTING, atoken,
217 "Starting window");
218 atoken.startingWindow = window;
219 }
220 if (mRunnableWhenAddingSplashScreen != null) {
221 mRunnableWhenAddingSplashScreen.run();
222 mRunnableWhenAddingSplashScreen = null;
223 }
224 return () -> {
225 synchronized (sWm.mWindowMap) {
226 atoken.removeChild(window);
227 atoken.startingWindow = null;
228 }
229 };
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700230 }
231
232 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700233 public int prepareAddWindowLw(WindowState win,
234 WindowManager.LayoutParams attrs) {
235 return 0;
236 }
237
238 @Override
239 public void removeWindowLw(WindowState win) {
240
241 }
242
243 @Override
244 public int selectAnimationLw(WindowState win, int transit) {
245 return 0;
246 }
247
248 @Override
249 public void selectRotationAnimationLw(int[] anim) {
250
251 }
252
253 @Override
254 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
255 boolean forceDefault) {
256 return false;
257 }
258
259 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200260 public Animation createHiddenByKeyguardExit(boolean onWallpaper,
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700261 boolean goingToNotificationShade) {
262 return null;
263 }
264
265 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200266 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700267 return null;
268 }
269
270 @Override
271 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
272 return 0;
273 }
274
275 @Override
276 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
277 return 0;
278 }
279
280 @Override
281 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event,
282 int policyFlags) {
283 return 0;
284 }
285
286 @Override
287 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event,
288 int policyFlags) {
289 return null;
290 }
291
292 @Override
293 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
294 int displayRotation, int uiMode) {
295
296 }
297
298 @Override
299 public int getSystemDecorLayerLw() {
300 return 0;
301 }
302
303 @Override
304 public void getContentRectLw(Rect r) {
305
306 }
307
308 @Override
309 public void layoutWindowLw(WindowState win,
310 WindowState attached) {
311
312 }
313
314 @Override
315 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
316 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
317 Rect outStableInsets, Rect outOutsets) {
318 return false;
319 }
320
321 @Override
322 public void finishLayoutLw() {
323
324 }
325
326 @Override
327 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
328
329 }
330
331 @Override
332 public void applyPostLayoutPolicyLw(WindowState win,
Jorim Jaggife762342016-10-13 14:33:27 +0200333 WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700334 }
335
336 @Override
337 public int finishPostLayoutPolicyLw() {
338 return 0;
339 }
340
341 @Override
342 public boolean allowAppAnimationsLw() {
343 return false;
344 }
345
346 @Override
347 public int focusChangedLw(WindowState lastFocus,
348 WindowState newFocus) {
349 return 0;
350 }
351
352 @Override
353 public void startedWakingUp() {
354
355 }
356
357 @Override
358 public void finishedWakingUp() {
359
360 }
361
362 @Override
363 public void startedGoingToSleep(int why) {
364
365 }
366
367 @Override
368 public void finishedGoingToSleep(int why) {
369
370 }
371
372 @Override
373 public void screenTurningOn(ScreenOnListener screenOnListener) {
374
375 }
376
377 @Override
378 public void screenTurnedOn() {
379
380 }
381
382 @Override
Jorim Jaggi51304d72017-05-17 17:25:32 +0200383 public void screenTurningOff(ScreenOffListener screenOffListener) {
384
385 }
386
387 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700388 public void screenTurnedOff() {
389
390 }
391
392 @Override
393 public boolean isScreenOn() {
Jorim Jaggi9bafc712017-01-19 17:28:30 +0100394 return true;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700395 }
396
397 @Override
Adrian Roos7c894802017-07-19 12:25:34 +0200398 public boolean okToAnimate() {
Adrian Roose94c15c2017-05-09 13:17:54 -0700399 return true;
400 }
401
402 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700403 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
404
405 }
406
407 @Override
408 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
409
410 }
411
412 @Override
413 public void enableKeyguard(boolean enabled) {
414
415 }
416
417 @Override
418 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
419
420 }
421
422 @Override
423 public boolean isKeyguardLocked() {
424 return false;
425 }
426
427 @Override
428 public boolean isKeyguardSecure(int userId) {
429 return false;
430 }
431
432 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200433 public boolean isKeyguardOccluded() {
434 return false;
435 }
436
437 @Override
438 public boolean isKeyguardTrustedLw() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700439 return false;
440 }
441
442 @Override
443 public boolean isKeyguardShowingAndNotOccluded() {
444 return false;
445 }
446
447 @Override
448 public boolean inKeyguardRestrictedKeyInputMode() {
449 return false;
450 }
451
452 @Override
Jorim Jaggi241ae102016-11-02 21:57:33 -0700453 public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700454 }
455
456 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200457 public boolean isKeyguardDrawnLw() {
458 return false;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700459 }
460
461 @Override
Jorim Jaggi77e10432016-10-26 17:43:56 -0700462 public boolean isShowingDreamLw() {
463 return false;
464 }
465
466 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200467 public void onKeyguardOccludedChangedLw(boolean occluded) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700468 }
469
470 @Override
471 public int rotationForOrientationLw(int orientation,
472 int lastRotation) {
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800473 return rotationToReport;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700474 }
475
476 @Override
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700477 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
478 return true;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700479 }
480
481 @Override
482 public void setRotationLw(int rotation) {
483
484 }
485
486 @Override
487 public void setSafeMode(boolean safeMode) {
488
489 }
490
491 @Override
492 public void systemReady() {
493
494 }
495
496 @Override
497 public void systemBooted() {
498
499 }
500
501 @Override
502 public void showBootMessage(CharSequence msg, boolean always) {
503
504 }
505
506 @Override
507 public void hideBootMessages() {
508
509 }
510
511 @Override
512 public void userActivity() {
513
514 }
515
516 @Override
517 public void enableScreenAfterBoot() {
518
519 }
520
521 @Override
522 public void setCurrentOrientationLw(int newOrientation) {
523
524 }
525
526 @Override
527 public boolean performHapticFeedbackLw(WindowState win, int effectId,
528 boolean always) {
529 return false;
530 }
531
532 @Override
533 public void keepScreenOnStartedLw() {
534
535 }
536
537 @Override
538 public void keepScreenOnStoppedLw() {
539
540 }
541
542 @Override
543 public int getUserRotationMode() {
544 return 0;
545 }
546
547 @Override
548 public void setUserRotationMode(int mode,
549 int rotation) {
550
551 }
552
553 @Override
554 public int adjustSystemUiVisibilityLw(int visibility) {
555 return 0;
556 }
557
558 @Override
559 public boolean hasNavigationBar() {
560 return false;
561 }
562
563 @Override
564 public void lockNow(Bundle options) {
565
566 }
567
568 @Override
569 public void setLastInputMethodWindowLw(WindowState ime,
570 WindowState target) {
571
572 }
573
574 @Override
575 public void showRecentApps(boolean fromHome) {
576
577 }
578
579 @Override
580 public void showGlobalActions() {
581
582 }
583
584 @Override
585 public int getInputMethodWindowVisibleHeightLw() {
586 return 0;
587 }
588
589 @Override
590 public void setCurrentUserLw(int newUserId) {
591
592 }
593
594 @Override
Evan Rosky18396452016-07-27 15:19:37 -0700595 public void setSwitchingUser(boolean switching) {
596
597 }
598
599 @Override
Steven Timotiusaf03df62017-07-18 16:56:43 -0700600 public void writeToProto(ProtoOutputStream proto, long fieldId) {
601
602 }
603
604 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700605 public void dump(String prefix, PrintWriter writer, String[] args) {
606
607 }
608
609 @Override
610 public boolean canMagnifyWindow(int windowType) {
611 return false;
612 }
613
614 @Override
615 public boolean isTopLevelWindow(int windowType) {
616 return false;
617 }
618
619 @Override
620 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
621
622 }
623
624 @Override
625 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
626 Rect outInsets) {
627
628 }
629
630 @Override
631 public boolean isNavBarForcedShownLw(WindowState win) {
632 return false;
633 }
634
635 @Override
Andrii Kulian3a1619d2017-07-07 14:38:09 -0700636 public int getNavBarPosition() {
637 return NAV_BAR_BOTTOM;
638 }
639
640 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700641 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
642 Rect outInsets) {
643
644 }
645
646 @Override
647 public boolean isDockSideAllowed(int dockSide) {
648 return false;
649 }
650
651 @Override
652 public void onConfigurationChanged() {
653
654 }
655
656 @Override
657 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) {
658 return false;
659 }
Brian Carlstrom7203d622016-09-21 01:00:36 -0700660
661 @Override
Winson Chungac52f282017-03-30 14:44:52 -0700662 public void setPipVisibilityLw(boolean visible) {
Brian Carlstrom7203d622016-09-21 01:00:36 -0700663
664 }
665
666 @Override
667 public void setRecentsVisibilityLw(boolean visible) {
668
Keun-young Park4136d2d2017-05-08 14:51:59 -0700669 }
670
671 @Override
672 public void onSystemUiStarted() {
673 }
674
675 @Override
676 public boolean canDismissBootAnimation() {
677 return true;
678 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700679}