TestWindowManagerPolicy.java revision 5b6714c2fa3cdd87642766e3fb0a1478d2422ec2
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        return 0;
277    }
278
279    @Override
280    public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
281        return 0;
282    }
283
284    @Override
285    public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
286        return 0;
287    }
288
289    @Override
290    public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
291        return 0;
292    }
293
294    @Override
295    public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
296        return false;
297    }
298
299    @Override
300    public boolean canBeHiddenByKeyguardLw(WindowState win) {
301        return false;
302    }
303
304    @Override
305    public View addStartingWindow(IBinder appToken, String packageName, int theme,
306            CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
307            int logo, int windowFlags, Configuration overrideConfig) {
308        return null;
309    }
310
311    @Override
312    public void removeStartingWindow(IBinder appToken, View window) {
313
314    }
315
316    @Override
317    public int prepareAddWindowLw(WindowState win,
318            WindowManager.LayoutParams attrs) {
319        return 0;
320    }
321
322    @Override
323    public void removeWindowLw(WindowState win) {
324
325    }
326
327    @Override
328    public int selectAnimationLw(WindowState win, int transit) {
329        return 0;
330    }
331
332    @Override
333    public void selectRotationAnimationLw(int[] anim) {
334
335    }
336
337    @Override
338    public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
339            boolean forceDefault) {
340        return false;
341    }
342
343    @Override
344    public Animation createHiddenByKeyguardExit(boolean onWallpaper,
345            boolean goingToNotificationShade) {
346        return null;
347    }
348
349    @Override
350    public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) {
351        return null;
352    }
353
354    @Override
355    public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
356        return 0;
357    }
358
359    @Override
360    public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
361        return 0;
362    }
363
364    @Override
365    public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event,
366            int policyFlags) {
367        return 0;
368    }
369
370    @Override
371    public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event,
372            int policyFlags) {
373        return null;
374    }
375
376    @Override
377    public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
378            int displayRotation, int uiMode) {
379
380    }
381
382    @Override
383    public int getSystemDecorLayerLw() {
384        return 0;
385    }
386
387    @Override
388    public void getContentRectLw(Rect r) {
389
390    }
391
392    @Override
393    public void layoutWindowLw(WindowState win,
394            WindowState attached) {
395
396    }
397
398    @Override
399    public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
400            int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
401            Rect outStableInsets, Rect outOutsets) {
402        return false;
403    }
404
405    @Override
406    public void finishLayoutLw() {
407
408    }
409
410    @Override
411    public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
412
413    }
414
415    @Override
416    public void applyPostLayoutPolicyLw(WindowState win,
417            WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget) {
418    }
419
420    @Override
421    public int finishPostLayoutPolicyLw() {
422        return 0;
423    }
424
425    @Override
426    public boolean allowAppAnimationsLw() {
427        return false;
428    }
429
430    @Override
431    public int focusChangedLw(WindowState lastFocus,
432            WindowState newFocus) {
433        return 0;
434    }
435
436    @Override
437    public void startedWakingUp() {
438
439    }
440
441    @Override
442    public void finishedWakingUp() {
443
444    }
445
446    @Override
447    public void startedGoingToSleep(int why) {
448
449    }
450
451    @Override
452    public void finishedGoingToSleep(int why) {
453
454    }
455
456    @Override
457    public void screenTurningOn(ScreenOnListener screenOnListener) {
458
459    }
460
461    @Override
462    public void screenTurnedOn() {
463
464    }
465
466    @Override
467    public void screenTurnedOff() {
468
469    }
470
471    @Override
472    public boolean isScreenOn() {
473        return false;
474    }
475
476    @Override
477    public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
478
479    }
480
481    @Override
482    public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
483
484    }
485
486    @Override
487    public void enableKeyguard(boolean enabled) {
488
489    }
490
491    @Override
492    public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
493
494    }
495
496    @Override
497    public boolean isKeyguardLocked() {
498        return false;
499    }
500
501    @Override
502    public boolean isKeyguardSecure(int userId) {
503        return false;
504    }
505
506    @Override
507    public boolean isKeyguardOccluded() {
508        return false;
509    }
510
511    @Override
512    public boolean isKeyguardTrustedLw() {
513        return false;
514    }
515
516    @Override
517    public boolean isKeyguardShowingAndNotOccluded() {
518        return false;
519    }
520
521    @Override
522    public boolean inKeyguardRestrictedKeyInputMode() {
523        return false;
524    }
525
526    @Override
527    public void dismissKeyguardLw() {
528
529    }
530
531    @Override
532    public boolean isKeyguardDrawnLw() {
533        return false;
534    }
535
536    @Override
537    public boolean isShowingDreamLw() {
538        return false;
539    }
540
541    @Override
542    public void onKeyguardOccludedChangedLw(boolean occluded) {
543    }
544
545    @Override
546    public int rotationForOrientationLw(int orientation,
547            int lastRotation) {
548        return 0;
549    }
550
551    @Override
552    public boolean rotationHasCompatibleMetricsLw(int orientation,
553            int rotation) {
554        return false;
555    }
556
557    @Override
558    public void setRotationLw(int rotation) {
559
560    }
561
562    @Override
563    public void setSafeMode(boolean safeMode) {
564
565    }
566
567    @Override
568    public void systemReady() {
569
570    }
571
572    @Override
573    public void systemBooted() {
574
575    }
576
577    @Override
578    public void showBootMessage(CharSequence msg, boolean always) {
579
580    }
581
582    @Override
583    public void hideBootMessages() {
584
585    }
586
587    @Override
588    public void userActivity() {
589
590    }
591
592    @Override
593    public void enableScreenAfterBoot() {
594
595    }
596
597    @Override
598    public void setCurrentOrientationLw(int newOrientation) {
599
600    }
601
602    @Override
603    public boolean performHapticFeedbackLw(WindowState win, int effectId,
604            boolean always) {
605        return false;
606    }
607
608    @Override
609    public void keepScreenOnStartedLw() {
610
611    }
612
613    @Override
614    public void keepScreenOnStoppedLw() {
615
616    }
617
618    @Override
619    public int getUserRotationMode() {
620        return 0;
621    }
622
623    @Override
624    public void setUserRotationMode(int mode,
625            int rotation) {
626
627    }
628
629    @Override
630    public int adjustSystemUiVisibilityLw(int visibility) {
631        return 0;
632    }
633
634    @Override
635    public boolean hasNavigationBar() {
636        return false;
637    }
638
639    @Override
640    public void lockNow(Bundle options) {
641
642    }
643
644    @Override
645    public void setLastInputMethodWindowLw(WindowState ime,
646            WindowState target) {
647
648    }
649
650    @Override
651    public void showRecentApps(boolean fromHome) {
652
653    }
654
655    @Override
656    public void showGlobalActions() {
657
658    }
659
660    @Override
661    public int getInputMethodWindowVisibleHeightLw() {
662        return 0;
663    }
664
665    @Override
666    public void setCurrentUserLw(int newUserId) {
667
668    }
669
670    @Override
671    public void setSwitchingUser(boolean switching) {
672
673    }
674
675    @Override
676    public void dump(String prefix, PrintWriter writer, String[] args) {
677
678    }
679
680    @Override
681    public boolean canMagnifyWindow(int windowType) {
682        return false;
683    }
684
685    @Override
686    public boolean isTopLevelWindow(int windowType) {
687        return false;
688    }
689
690    @Override
691    public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
692
693    }
694
695    @Override
696    public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
697            Rect outInsets) {
698
699    }
700
701    @Override
702    public boolean isNavBarForcedShownLw(WindowState win) {
703        return false;
704    }
705
706    @Override
707    public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
708            Rect outInsets) {
709
710    }
711
712    @Override
713    public boolean isDockSideAllowed(int dockSide) {
714        return false;
715    }
716
717    @Override
718    public void onConfigurationChanged() {
719
720    }
721
722    @Override
723    public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) {
724        return false;
725    }
726
727    @Override
728    public void setTvPipVisibilityLw(boolean visible) {
729
730    }
731
732    @Override
733    public void setRecentsVisibilityLw(boolean visible) {
734
735   }
736}
737