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