TestWindowManagerPolicy.java revision db8e106fa35ca75f4a8bf9795edc7676fbf8e003
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.IShortcutService;
20import com.android.server.input.InputManagerService;
21
22import android.content.Context;
23import 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;
29import android.util.Log;
30import android.view.Display;
31import android.view.IWindowManager;
32import android.view.KeyEvent;
33import android.view.View;
34import android.view.WindowManager;
35import android.view.WindowManagerPolicy;
36import android.view.animation.Animation;
37
38import java.io.PrintWriter;
39
40import 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_MAGNIFICATION_OVERLAY;
59import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
60import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
61import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
62import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
63import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
64import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
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
83import static org.mockito.Mockito.mock;
84
85class TestWindowManagerPolicy implements WindowManagerPolicy {
86    private static final String TAG = "TestWindowManagerPolicy";
87
88    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.
94            sWm = WindowManagerService.main(context, mock(InputManagerService.class), true, false,
95                    false, new TestWindowManagerPolicy());
96        }
97        return sWm;
98    }
99
100    @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) {
150        // 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_PRESENTATION:
156            case TYPE_PRIVATE_PRESENTATION:
157                return 2;
158            case TYPE_WALLPAPER:
159                // wallpaper is at the bottom, though the window manager may move it.
160                return 2;
161            case TYPE_DOCK_DIVIDER:
162                return 2;
163            case TYPE_QS_DIALOG:
164                return 2;
165            case TYPE_PHONE:
166                return 3;
167            case TYPE_SEARCH_BAR:
168            case TYPE_VOICE_INTERACTION_STARTING:
169                return 4;
170            case TYPE_VOICE_INTERACTION:
171                // voice interaction layer is almost immediately above apps.
172                return 5;
173            case TYPE_INPUT_CONSUMER:
174                return 6;
175            case TYPE_SYSTEM_DIALOG:
176                return 7;
177            case TYPE_TOAST:
178                // toasts and the plugged-in battery thing
179                return 8;
180            case TYPE_PRIORITY_PHONE:
181                // SIM errors and unlock.  Not sure if this really should be in a high layer.
182                return 9;
183            case TYPE_DREAM:
184                // used for Dreams (screensavers with TYPE_DREAM windows)
185                return 10;
186            case TYPE_SYSTEM_ALERT:
187                // like the ANR / app crashed dialogs
188                return 11;
189            case TYPE_INPUT_METHOD:
190                // on-screen keyboards and other such input method user interfaces go here.
191                return 12;
192            case TYPE_INPUT_METHOD_DIALOG:
193                // on-screen keyboards and other such input method user interfaces go here.
194                return 13;
195            case TYPE_STATUS_BAR_SUB_PANEL:
196                return 15;
197            case TYPE_STATUS_BAR:
198                return 16;
199            case TYPE_STATUS_BAR_PANEL:
200                return 17;
201            case TYPE_KEYGUARD_DIALOG:
202                return 18;
203            case TYPE_VOLUME_OVERLAY:
204                // the on-screen volume indicator and controller shown when the user
205                // changes the device volume
206                return 19;
207            case TYPE_SYSTEM_OVERLAY:
208                // the on-screen volume indicator and controller shown when the user
209                // changes the device volume
210                return 20;
211            case TYPE_NAVIGATION_BAR:
212                // the navigation bar, if available, shows atop most things
213                return 21;
214            case TYPE_NAVIGATION_BAR_PANEL:
215                // some panels (e.g. search) need to show on top of the navigation bar
216                return 22;
217            case TYPE_SCREENSHOT:
218                // screenshot selection layer shouldn't go above system error, but it should cover
219                // navigation bars at the very least.
220                return 23;
221            case TYPE_SYSTEM_ERROR:
222                // system-level error dialogs
223                return 24;
224            case TYPE_MAGNIFICATION_OVERLAY:
225                // used to highlight the magnified portion of a display
226                return 25;
227            case TYPE_DISPLAY_OVERLAY:
228                // used to simulate secondary display devices
229                return 26;
230            case TYPE_DRAG:
231                // the drag layer: input for drag-and-drop is associated with this window,
232                // which sits above all other focusable windows
233                return 27;
234            case TYPE_ACCESSIBILITY_OVERLAY:
235                // overlay put by accessibility services to intercept user interaction
236                return 28;
237            case TYPE_SECURE_SYSTEM_OVERLAY:
238                return 29;
239            case TYPE_BOOT_PROGRESS:
240                return 30;
241            case TYPE_POINTER:
242                // the (mouse) pointer layer
243                return 31;
244        }
245        Log.e(TAG, "Unknown window type: " + type);
246        return 2;
247    }
248
249    @Override
250    public int subWindowTypeToLayerLw(int type) {
251        // TODO: figure-out a good way to keep this in-sync with PhoneWindowManager...
252        switch (type) {
253            case TYPE_APPLICATION_PANEL:
254            case TYPE_APPLICATION_ATTACHED_DIALOG:
255                return 1;
256            case TYPE_APPLICATION_MEDIA:
257                return -2;
258            case TYPE_APPLICATION_MEDIA_OVERLAY:
259                return -1;
260            case TYPE_APPLICATION_SUB_PANEL:
261                return 2;
262            case TYPE_APPLICATION_ABOVE_SUB_PANEL:
263                return 3;
264        }
265        Log.e(TAG, "Unknown sub-window type: " + type);
266        return 0;
267    }
268
269    @Override
270    public int getMaxWallpaperLayer() {
271        return 0;
272    }
273
274    @Override
275    public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
276            int displayId) {
277        return 0;
278    }
279
280    @Override
281    public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
282            int displayId) {
283        return 0;
284    }
285
286    @Override
287    public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
288            int displayId) {
289        return 0;
290    }
291
292    @Override
293    public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
294            int displayId) {
295        return 0;
296    }
297
298    @Override
299    public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
300        return false;
301    }
302
303    @Override
304    public boolean canBeHiddenByKeyguardLw(WindowState win) {
305        return false;
306    }
307
308    @Override
309    public View addStartingWindow(IBinder appToken, String packageName, int theme,
310            CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
311            int logo, int windowFlags, Configuration overrideConfig) {
312        return null;
313    }
314
315    @Override
316    public void removeStartingWindow(IBinder appToken, View window) {
317
318    }
319
320    @Override
321    public int prepareAddWindowLw(WindowState win,
322            WindowManager.LayoutParams attrs) {
323        return 0;
324    }
325
326    @Override
327    public void removeWindowLw(WindowState win) {
328
329    }
330
331    @Override
332    public int selectAnimationLw(WindowState win, int transit) {
333        return 0;
334    }
335
336    @Override
337    public void selectRotationAnimationLw(int[] anim) {
338
339    }
340
341    @Override
342    public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
343            boolean forceDefault) {
344        return false;
345    }
346
347    @Override
348    public Animation createHiddenByKeyguardExit(boolean onWallpaper,
349            boolean goingToNotificationShade) {
350        return null;
351    }
352
353    @Override
354    public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) {
355        return null;
356    }
357
358    @Override
359    public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
360        return 0;
361    }
362
363    @Override
364    public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
365        return 0;
366    }
367
368    @Override
369    public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event,
370            int policyFlags) {
371        return 0;
372    }
373
374    @Override
375    public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event,
376            int policyFlags) {
377        return null;
378    }
379
380    @Override
381    public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
382            int displayRotation, int uiMode) {
383
384    }
385
386    @Override
387    public int getSystemDecorLayerLw() {
388        return 0;
389    }
390
391    @Override
392    public void getContentRectLw(Rect r) {
393
394    }
395
396    @Override
397    public void layoutWindowLw(WindowState win,
398            WindowState attached) {
399
400    }
401
402    @Override
403    public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
404            int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
405            Rect outStableInsets, Rect outOutsets) {
406        return false;
407    }
408
409    @Override
410    public void finishLayoutLw() {
411
412    }
413
414    @Override
415    public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
416
417    }
418
419    @Override
420    public void applyPostLayoutPolicyLw(WindowState win,
421            WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget) {
422    }
423
424    @Override
425    public int finishPostLayoutPolicyLw() {
426        return 0;
427    }
428
429    @Override
430    public boolean allowAppAnimationsLw() {
431        return false;
432    }
433
434    @Override
435    public int focusChangedLw(WindowState lastFocus,
436            WindowState newFocus) {
437        return 0;
438    }
439
440    @Override
441    public void startedWakingUp() {
442
443    }
444
445    @Override
446    public void finishedWakingUp() {
447
448    }
449
450    @Override
451    public void startedGoingToSleep(int why) {
452
453    }
454
455    @Override
456    public void finishedGoingToSleep(int why) {
457
458    }
459
460    @Override
461    public void screenTurningOn(ScreenOnListener screenOnListener) {
462
463    }
464
465    @Override
466    public void screenTurnedOn() {
467
468    }
469
470    @Override
471    public void screenTurnedOff() {
472
473    }
474
475    @Override
476    public boolean isScreenOn() {
477        return false;
478    }
479
480    @Override
481    public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
482
483    }
484
485    @Override
486    public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
487
488    }
489
490    @Override
491    public void enableKeyguard(boolean enabled) {
492
493    }
494
495    @Override
496    public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
497
498    }
499
500    @Override
501    public boolean isKeyguardLocked() {
502        return false;
503    }
504
505    @Override
506    public boolean isKeyguardSecure(int userId) {
507        return false;
508    }
509
510    @Override
511    public boolean isKeyguardOccluded() {
512        return false;
513    }
514
515    @Override
516    public boolean isKeyguardTrustedLw() {
517        return false;
518    }
519
520    @Override
521    public boolean isKeyguardShowingAndNotOccluded() {
522        return false;
523    }
524
525    @Override
526    public boolean inKeyguardRestrictedKeyInputMode() {
527        return false;
528    }
529
530    @Override
531    public void dismissKeyguardLw() {
532
533    }
534
535    @Override
536    public boolean isKeyguardDrawnLw() {
537        return false;
538    }
539
540    @Override
541    public boolean isShowingDreamLw() {
542        return false;
543    }
544
545    @Override
546    public void onKeyguardOccludedChangedLw(boolean occluded) {
547    }
548
549    @Override
550    public int rotationForOrientationLw(int orientation,
551            int lastRotation) {
552        return 0;
553    }
554
555    @Override
556    public boolean rotationHasCompatibleMetricsLw(int orientation,
557            int rotation) {
558        return false;
559    }
560
561    @Override
562    public void setRotationLw(int rotation) {
563
564    }
565
566    @Override
567    public void setSafeMode(boolean safeMode) {
568
569    }
570
571    @Override
572    public void systemReady() {
573
574    }
575
576    @Override
577    public void systemBooted() {
578
579    }
580
581    @Override
582    public void showBootMessage(CharSequence msg, boolean always) {
583
584    }
585
586    @Override
587    public void hideBootMessages() {
588
589    }
590
591    @Override
592    public void userActivity() {
593
594    }
595
596    @Override
597    public void enableScreenAfterBoot() {
598
599    }
600
601    @Override
602    public void setCurrentOrientationLw(int newOrientation) {
603
604    }
605
606    @Override
607    public boolean performHapticFeedbackLw(WindowState win, int effectId,
608            boolean always) {
609        return false;
610    }
611
612    @Override
613    public void keepScreenOnStartedLw() {
614
615    }
616
617    @Override
618    public void keepScreenOnStoppedLw() {
619
620    }
621
622    @Override
623    public int getUserRotationMode() {
624        return 0;
625    }
626
627    @Override
628    public void setUserRotationMode(int mode,
629            int rotation) {
630
631    }
632
633    @Override
634    public int adjustSystemUiVisibilityLw(int visibility) {
635        return 0;
636    }
637
638    @Override
639    public boolean hasNavigationBar() {
640        return false;
641    }
642
643    @Override
644    public void lockNow(Bundle options) {
645
646    }
647
648    @Override
649    public void setLastInputMethodWindowLw(WindowState ime,
650            WindowState target) {
651
652    }
653
654    @Override
655    public void showRecentApps(boolean fromHome) {
656
657    }
658
659    @Override
660    public void showGlobalActions() {
661
662    }
663
664    @Override
665    public int getInputMethodWindowVisibleHeightLw() {
666        return 0;
667    }
668
669    @Override
670    public void setCurrentUserLw(int newUserId) {
671
672    }
673
674    @Override
675    public void setSwitchingUser(boolean switching) {
676
677    }
678
679    @Override
680    public void dump(String prefix, PrintWriter writer, String[] args) {
681
682    }
683
684    @Override
685    public boolean canMagnifyWindow(int windowType) {
686        return false;
687    }
688
689    @Override
690    public boolean isTopLevelWindow(int windowType) {
691        return false;
692    }
693
694    @Override
695    public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
696
697    }
698
699    @Override
700    public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
701            Rect outInsets) {
702
703    }
704
705    @Override
706    public boolean isNavBarForcedShownLw(WindowState win) {
707        return false;
708    }
709
710    @Override
711    public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
712            Rect outInsets) {
713
714    }
715
716    @Override
717    public boolean isDockSideAllowed(int dockSide) {
718        return false;
719    }
720
721    @Override
722    public void onConfigurationChanged() {
723
724    }
725
726    @Override
727    public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) {
728        return false;
729    }
730
731    @Override
732    public void setTvPipVisibilityLw(boolean visible) {
733
734    }
735
736    @Override
737    public void setRecentsVisibilityLw(boolean visible) {
738
739   }
740}
741