blob: 5148e5567c93e41424a43bd19b20222ee3a78929 [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
19import com.android.internal.policy.IShortcutService;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070020import com.android.server.input.InputManagerService;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070021
22import android.content.Context;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070023import android.content.res.CompatibilityInfo;
24import android.content.res.Configuration;
25import android.graphics.Rect;
26import android.os.Bundle;
27import android.os.IBinder;
28import android.os.RemoteException;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070029import android.util.Log;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070030import android.view.Display;
31import android.view.IWindowManager;
32import android.view.KeyEvent;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070033import android.view.View;
34import android.view.WindowManager;
35import android.view.WindowManagerPolicy;
36import android.view.animation.Animation;
37
38import java.io.PrintWriter;
39
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070040import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
41import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
42import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
43import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL;
44import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
45import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
46import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
47import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
48import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
49import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
50import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
51import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
52import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
53import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
54import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
55import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
56import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
57import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
58import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM;
59import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
60import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
61import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
62import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
63import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
64import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
65import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
66import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
67import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
68import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
69import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
70import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
71import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
72import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
73import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
74import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
75import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
76import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
77import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
78import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
79import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING;
80import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
81import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
82
Wale Ogunwalecfca2582016-10-19 09:53:25 -070083import static org.mockito.Mockito.mock;
84
85class TestWindowManagerPolicy implements WindowManagerPolicy {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070086 private static final String TAG = "TestWindowManagerPolicy";
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070087
Wale Ogunwale51362492016-09-08 17:49:17 -070088 private static WindowManagerService sWm = null;
89
90 static synchronized WindowManagerService getWindowManagerService(Context context) {
91 if (sWm == null) {
92 // We only want to do this once for the test process as we don't want WM to try to
93 // register a bunch of local services again.
Wale Ogunwalecfca2582016-10-19 09:53:25 -070094 sWm = WindowManagerService.main(context, mock(InputManagerService.class), true, false,
95 false, new TestWindowManagerPolicy());
Wale Ogunwale51362492016-09-08 17:49:17 -070096 }
97 return sWm;
98 }
99
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700100 @Override
101 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)
102 throws RemoteException {
103
104 }
105
106 @Override
107 public void init(Context context, IWindowManager windowManager,
108 WindowManagerFuncs windowManagerFuncs) {
109
110 }
111
112 @Override
113 public boolean isDefaultOrientationForced() {
114 return false;
115 }
116
117 @Override
118 public void setInitialDisplaySize(Display display, int width, int height, int density) {
119
120 }
121
122 @Override
123 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
124
125 }
126
127 @Override
128 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
129 return 0;
130 }
131
132 @Override
133 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
134 return false;
135 }
136
137 @Override
138 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
139
140 }
141
142 @Override
143 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
144 int navigationPresence) {
145
146 }
147
148 @Override
149 public int windowTypeToLayerLw(int type) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700150 // TODO: figure-out a good way to keep this in-sync with PhoneWindowManager...sigh!
151 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
152 return 2;
153 }
154 switch (type) {
155 case TYPE_PRIVATE_PRESENTATION:
156 return 2;
157 case TYPE_WALLPAPER:
158 // wallpaper is at the bottom, though the window manager may move it.
159 return 2;
160 case TYPE_DOCK_DIVIDER:
161 return 2;
162 case TYPE_QS_DIALOG:
163 return 2;
164 case TYPE_PHONE:
165 return 3;
166 case TYPE_SEARCH_BAR:
167 case TYPE_VOICE_INTERACTION_STARTING:
168 return 4;
169 case TYPE_VOICE_INTERACTION:
170 // voice interaction layer is almost immediately above apps.
171 return 5;
172 case TYPE_INPUT_CONSUMER:
173 return 6;
174 case TYPE_SYSTEM_DIALOG:
175 return 7;
176 case TYPE_TOAST:
177 // toasts and the plugged-in battery thing
178 return 8;
179 case TYPE_PRIORITY_PHONE:
180 // SIM errors and unlock. Not sure if this really should be in a high layer.
181 return 9;
182 case TYPE_DREAM:
183 // used for Dreams (screensavers with TYPE_DREAM windows)
184 return 10;
185 case TYPE_SYSTEM_ALERT:
186 // like the ANR / app crashed dialogs
187 return 11;
188 case TYPE_INPUT_METHOD:
189 // on-screen keyboards and other such input method user interfaces go here.
190 return 12;
191 case TYPE_INPUT_METHOD_DIALOG:
192 // on-screen keyboards and other such input method user interfaces go here.
193 return 13;
194 case TYPE_KEYGUARD_SCRIM:
195 // the safety window that shows behind keyguard while keyguard is starting
196 return 14;
197 case TYPE_STATUS_BAR_SUB_PANEL:
198 return 15;
199 case TYPE_STATUS_BAR:
200 return 16;
201 case TYPE_STATUS_BAR_PANEL:
202 return 17;
203 case TYPE_KEYGUARD_DIALOG:
204 return 18;
205 case TYPE_VOLUME_OVERLAY:
206 // the on-screen volume indicator and controller shown when the user
207 // changes the device volume
208 return 19;
209 case TYPE_SYSTEM_OVERLAY:
210 // the on-screen volume indicator and controller shown when the user
211 // changes the device volume
212 return 20;
213 case TYPE_NAVIGATION_BAR:
214 // the navigation bar, if available, shows atop most things
215 return 21;
216 case TYPE_NAVIGATION_BAR_PANEL:
217 // some panels (e.g. search) need to show on top of the navigation bar
218 return 22;
219 case TYPE_SCREENSHOT:
220 // screenshot selection layer shouldn't go above system error, but it should cover
221 // navigation bars at the very least.
222 return 23;
223 case TYPE_SYSTEM_ERROR:
224 // system-level error dialogs
225 return 24;
226 case TYPE_MAGNIFICATION_OVERLAY:
227 // used to highlight the magnified portion of a display
228 return 25;
229 case TYPE_DISPLAY_OVERLAY:
230 // used to simulate secondary display devices
231 return 26;
232 case TYPE_DRAG:
233 // the drag layer: input for drag-and-drop is associated with this window,
234 // which sits above all other focusable windows
235 return 27;
236 case TYPE_ACCESSIBILITY_OVERLAY:
237 // overlay put by accessibility services to intercept user interaction
238 return 28;
239 case TYPE_SECURE_SYSTEM_OVERLAY:
240 return 29;
241 case TYPE_BOOT_PROGRESS:
242 return 30;
243 case TYPE_POINTER:
244 // the (mouse) pointer layer
245 return 31;
246 }
247 Log.e(TAG, "Unknown window type: " + type);
248 return 2;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700249 }
250
251 @Override
252 public int subWindowTypeToLayerLw(int type) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700253 // TODO: figure-out a good way to keep this in-sync with PhoneWindowManager...
254 switch (type) {
255 case TYPE_APPLICATION_PANEL:
256 case TYPE_APPLICATION_ATTACHED_DIALOG:
257 return 1;
258 case TYPE_APPLICATION_MEDIA:
259 return -2;
260 case TYPE_APPLICATION_MEDIA_OVERLAY:
261 return -1;
262 case TYPE_APPLICATION_SUB_PANEL:
263 return 2;
264 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
265 return 3;
266 }
267 Log.e(TAG, "Unknown sub-window type: " + type);
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700268 return 0;
269 }
270
271 @Override
272 public int getMaxWallpaperLayer() {
273 return 0;
274 }
275
276 @Override
277 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
278 return 0;
279 }
280
281 @Override
282 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
283 return 0;
284 }
285
286 @Override
287 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
288 return 0;
289 }
290
291 @Override
292 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
293 return 0;
294 }
295
296 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700297 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
298 return false;
299 }
300
301 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200302 public boolean canBeHiddenByKeyguardLw(WindowState win) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700303 return false;
304 }
305
306 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700307 public View addStartingWindow(IBinder appToken, String packageName, int theme,
308 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
309 int logo, int windowFlags, Configuration overrideConfig) {
310 return null;
311 }
312
313 @Override
314 public void removeStartingWindow(IBinder appToken, View window) {
315
316 }
317
318 @Override
319 public int prepareAddWindowLw(WindowState win,
320 WindowManager.LayoutParams attrs) {
321 return 0;
322 }
323
324 @Override
325 public void removeWindowLw(WindowState win) {
326
327 }
328
329 @Override
330 public int selectAnimationLw(WindowState win, int transit) {
331 return 0;
332 }
333
334 @Override
335 public void selectRotationAnimationLw(int[] anim) {
336
337 }
338
339 @Override
340 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
341 boolean forceDefault) {
342 return false;
343 }
344
345 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200346 public Animation createHiddenByKeyguardExit(boolean onWallpaper,
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700347 boolean goingToNotificationShade) {
348 return null;
349 }
350
351 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200352 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700353 return null;
354 }
355
356 @Override
357 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
358 return 0;
359 }
360
361 @Override
362 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
363 return 0;
364 }
365
366 @Override
367 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event,
368 int policyFlags) {
369 return 0;
370 }
371
372 @Override
373 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event,
374 int policyFlags) {
375 return null;
376 }
377
378 @Override
379 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
380 int displayRotation, int uiMode) {
381
382 }
383
384 @Override
385 public int getSystemDecorLayerLw() {
386 return 0;
387 }
388
389 @Override
390 public void getContentRectLw(Rect r) {
391
392 }
393
394 @Override
395 public void layoutWindowLw(WindowState win,
396 WindowState attached) {
397
398 }
399
400 @Override
401 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
402 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
403 Rect outStableInsets, Rect outOutsets) {
404 return false;
405 }
406
407 @Override
408 public void finishLayoutLw() {
409
410 }
411
412 @Override
413 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
414
415 }
416
417 @Override
418 public void applyPostLayoutPolicyLw(WindowState win,
Jorim Jaggife762342016-10-13 14:33:27 +0200419 WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700420 }
421
422 @Override
423 public int finishPostLayoutPolicyLw() {
424 return 0;
425 }
426
427 @Override
428 public boolean allowAppAnimationsLw() {
429 return false;
430 }
431
432 @Override
433 public int focusChangedLw(WindowState lastFocus,
434 WindowState newFocus) {
435 return 0;
436 }
437
438 @Override
439 public void startedWakingUp() {
440
441 }
442
443 @Override
444 public void finishedWakingUp() {
445
446 }
447
448 @Override
449 public void startedGoingToSleep(int why) {
450
451 }
452
453 @Override
454 public void finishedGoingToSleep(int why) {
455
456 }
457
458 @Override
459 public void screenTurningOn(ScreenOnListener screenOnListener) {
460
461 }
462
463 @Override
464 public void screenTurnedOn() {
465
466 }
467
468 @Override
469 public void screenTurnedOff() {
470
471 }
472
473 @Override
474 public boolean isScreenOn() {
475 return false;
476 }
477
478 @Override
479 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
480
481 }
482
483 @Override
484 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
485
486 }
487
488 @Override
489 public void enableKeyguard(boolean enabled) {
490
491 }
492
493 @Override
494 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
495
496 }
497
498 @Override
499 public boolean isKeyguardLocked() {
500 return false;
501 }
502
503 @Override
504 public boolean isKeyguardSecure(int userId) {
505 return false;
506 }
507
508 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200509 public boolean isKeyguardOccluded() {
510 return false;
511 }
512
513 @Override
514 public boolean isKeyguardTrustedLw() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700515 return false;
516 }
517
518 @Override
519 public boolean isKeyguardShowingAndNotOccluded() {
520 return false;
521 }
522
523 @Override
524 public boolean inKeyguardRestrictedKeyInputMode() {
525 return false;
526 }
527
528 @Override
529 public void dismissKeyguardLw() {
530
531 }
532
533 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200534 public boolean isKeyguardDrawnLw() {
535 return false;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700536 }
537
538 @Override
Jorim Jaggife762342016-10-13 14:33:27 +0200539 public void onKeyguardOccludedChangedLw(boolean occluded) {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700540 }
541
542 @Override
543 public int rotationForOrientationLw(int orientation,
544 int lastRotation) {
545 return 0;
546 }
547
548 @Override
549 public boolean rotationHasCompatibleMetricsLw(int orientation,
550 int rotation) {
551 return false;
552 }
553
554 @Override
555 public void setRotationLw(int rotation) {
556
557 }
558
559 @Override
560 public void setSafeMode(boolean safeMode) {
561
562 }
563
564 @Override
565 public void systemReady() {
566
567 }
568
569 @Override
570 public void systemBooted() {
571
572 }
573
574 @Override
575 public void showBootMessage(CharSequence msg, boolean always) {
576
577 }
578
579 @Override
580 public void hideBootMessages() {
581
582 }
583
584 @Override
585 public void userActivity() {
586
587 }
588
589 @Override
590 public void enableScreenAfterBoot() {
591
592 }
593
594 @Override
595 public void setCurrentOrientationLw(int newOrientation) {
596
597 }
598
599 @Override
600 public boolean performHapticFeedbackLw(WindowState win, int effectId,
601 boolean always) {
602 return false;
603 }
604
605 @Override
606 public void keepScreenOnStartedLw() {
607
608 }
609
610 @Override
611 public void keepScreenOnStoppedLw() {
612
613 }
614
615 @Override
616 public int getUserRotationMode() {
617 return 0;
618 }
619
620 @Override
621 public void setUserRotationMode(int mode,
622 int rotation) {
623
624 }
625
626 @Override
627 public int adjustSystemUiVisibilityLw(int visibility) {
628 return 0;
629 }
630
631 @Override
632 public boolean hasNavigationBar() {
633 return false;
634 }
635
636 @Override
637 public void lockNow(Bundle options) {
638
639 }
640
641 @Override
642 public void setLastInputMethodWindowLw(WindowState ime,
643 WindowState target) {
644
645 }
646
647 @Override
648 public void showRecentApps(boolean fromHome) {
649
650 }
651
652 @Override
653 public void showGlobalActions() {
654
655 }
656
657 @Override
658 public int getInputMethodWindowVisibleHeightLw() {
659 return 0;
660 }
661
662 @Override
663 public void setCurrentUserLw(int newUserId) {
664
665 }
666
667 @Override
Evan Rosky18396452016-07-27 15:19:37 -0700668 public void setSwitchingUser(boolean switching) {
669
670 }
671
672 @Override
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700673 public void dump(String prefix, PrintWriter writer, String[] args) {
674
675 }
676
677 @Override
678 public boolean canMagnifyWindow(int windowType) {
679 return false;
680 }
681
682 @Override
683 public boolean isTopLevelWindow(int windowType) {
684 return false;
685 }
686
687 @Override
688 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
689
690 }
691
692 @Override
693 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
694 Rect outInsets) {
695
696 }
697
698 @Override
699 public boolean isNavBarForcedShownLw(WindowState win) {
700 return false;
701 }
702
703 @Override
704 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
705 Rect outInsets) {
706
707 }
708
709 @Override
710 public boolean isDockSideAllowed(int dockSide) {
711 return false;
712 }
713
714 @Override
715 public void onConfigurationChanged() {
716
717 }
718
719 @Override
720 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) {
721 return false;
722 }
Brian Carlstrom7203d622016-09-21 01:00:36 -0700723
724 @Override
725 public void setTvPipVisibilityLw(boolean visible) {
726
727 }
728
729 @Override
730 public void setRecentsVisibilityLw(boolean visible) {
731
732 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700733}