1 /*
2  * Copyright (C) 2017 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 
17 package com.android.server.policy;
18 
19 import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20 import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
21 import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY;
22 import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
23 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL;
24 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
25 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
26 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
27 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
28 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
29 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
30 import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
31 import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
32 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
33 import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
34 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
35 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
36 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
37 import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
38 import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
39 import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
40 import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
41 import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE;
42 import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
43 import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
44 import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
45 import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
46 import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
47 import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
48 import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
49 import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
50 import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
51 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
52 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL;
53 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
54 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
55 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
56 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
57 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
58 import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
59 import static android.view.WindowManager.LayoutParams.TYPE_TRUSTED_APPLICATION_OVERLAY;
60 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
61 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING;
62 import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
63 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
64 import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
65 
66 import static java.lang.annotation.RetentionPolicy.SOURCE;
67 
68 import android.annotation.IntDef;
69 import android.annotation.NonNull;
70 import android.annotation.Nullable;
71 import android.app.WindowConfiguration;
72 import android.content.Context;
73 import android.content.res.CompatibilityInfo;
74 import android.content.res.Configuration;
75 import android.graphics.Rect;
76 import android.os.Bundle;
77 import android.os.IBinder;
78 import android.os.RemoteException;
79 import android.util.Slog;
80 import android.util.proto.ProtoOutputStream;
81 import android.view.Display;
82 import android.view.IApplicationToken;
83 import android.view.IDisplayFoldListener;
84 import android.view.IWindowManager;
85 import android.view.KeyEvent;
86 import android.view.WindowManager;
87 import android.view.WindowManagerGlobal;
88 import android.view.WindowManagerPolicyConstants;
89 import android.view.animation.Animation;
90 
91 import com.android.internal.policy.IKeyguardDismissCallback;
92 import com.android.internal.policy.IShortcutService;
93 import com.android.server.wm.DisplayRotation;
94 import com.android.server.wm.WindowFrames;
95 
96 import java.io.PrintWriter;
97 import java.lang.annotation.Retention;
98 import java.lang.annotation.RetentionPolicy;
99 
100 /**
101  * This interface supplies all UI-specific behavior of the window manager.  An
102  * instance of it is created by the window manager when it starts up, and allows
103  * customization of window layering, special window types, key dispatching, and
104  * layout.
105  *
106  * <p>Because this provides deep interaction with the system window manager,
107  * specific methods on this interface can be called from a variety of contexts
108  * with various restrictions on what they can do.  These are encoded through
109  * a suffixes at the end of a method encoding the thread the method is called
110  * from and any locks that are held when it is being called; if no suffix
111  * is attached to a method, then it is not called with any locks and may be
112  * called from the main window manager thread or another thread calling into
113  * the window manager.
114  *
115  * <p>The current suffixes are:
116  *
117  * <dl>
118  * <dt> Ti <dd> Called from the input thread.  This is the thread that
119  * collects pending input events and dispatches them to the appropriate window.
120  * It may block waiting for events to be processed, so that the input stream is
121  * properly serialized.
122  * <dt> Tq <dd> Called from the low-level input queue thread.  This is the
123  * thread that reads events out of the raw input devices and places them
124  * into the global input queue that is read by the <var>Ti</var> thread.
125  * This thread should not block for a long period of time on anything but the
126  * key driver.
127  * <dt> Lw <dd> Called with the main window manager lock held.  Because the
128  * window manager is a very low-level system service, there are few other
129  * system services you can call with this lock held.  It is explicitly okay to
130  * make calls into the package manager and power manager; it is explicitly not
131  * okay to make calls into the activity manager or most other services.  Note that
132  * {@link android.content.Context#checkPermission(String, int, int)} and
133  * variations require calling into the activity manager.
134  * <dt> Li <dd> Called with the input thread lock held.  This lock can be
135  * acquired by the window manager while it holds the window lock, so this is
136  * even more restrictive than <var>Lw</var>.
137  * </dl>
138  */
139 public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
140     @Retention(SOURCE)
141     @IntDef({NAV_BAR_LEFT, NAV_BAR_RIGHT, NAV_BAR_BOTTOM})
142     @interface NavigationBarPosition {}
143 
144     /**
145      * Pass this event to the user / app.  To be returned from
146      * {@link #interceptKeyBeforeQueueing}.
147      */
148     int ACTION_PASS_TO_USER = 0x00000001;
149     /** Layout state may have changed (so another layout will be performed) */
150     int FINISH_LAYOUT_REDO_LAYOUT = 0x0001;
151     /** Configuration state may have changed */
152     int FINISH_LAYOUT_REDO_CONFIG = 0x0002;
153     /** Wallpaper may need to move */
154     int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004;
155     /** Need to recompute animations */
156     int FINISH_LAYOUT_REDO_ANIM = 0x0008;
157     /** Layer for the screen off animation */
158     int COLOR_FADE_LAYER = 0x40000001;
159 
160     /**
161      * Register shortcuts for window manager to dispatch.
162      * Shortcut code is packed as (metaState << Integer.SIZE) | keyCode
163      * @hide
164      */
registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)165     void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)
166             throws RemoteException;
167 
168     /**
169      * Called when the Keyguard occluded state changed.
170      * @param occluded Whether Keyguard is currently occluded or not.
171      */
onKeyguardOccludedChangedLw(boolean occluded)172     void onKeyguardOccludedChangedLw(boolean occluded);
173 
174     /**
175      * Interface to the Window Manager state associated with a particular
176      * window. You can hold on to an instance of this interface from the call
177      * to prepareAddWindow() until removeWindow().
178      */
179     public interface WindowState {
180         /**
181          * Return the uid of the app that owns this window.
182          */
getOwningUid()183         int getOwningUid();
184 
185         /**
186          * Return the package name of the app that owns this window.
187          */
getOwningPackage()188         String getOwningPackage();
189 
190         /**
191          * Perform standard frame computation.  The result can be obtained with
192          * getFrame() if so desired.  Must be called with the window manager
193          * lock held.
194          *
195          */
computeFrameLw()196         public void computeFrameLw();
197 
198         /**
199          * Retrieve the current frame of the window that has been assigned by
200          * the window manager.  Must be called with the window manager lock held.
201          *
202          * @return Rect The rectangle holding the window frame.
203          */
getFrameLw()204         public Rect getFrameLw();
205 
206         /**
207          * Retrieve the frame of the display that this window was last
208          * laid out in.  Must be called with the
209          * window manager lock held.
210          *
211          * @return Rect The rectangle holding the display frame.
212          */
getDisplayFrameLw()213         public Rect getDisplayFrameLw();
214 
215         /**
216          * Retrieve the frame of the content area that this window was last
217          * laid out in.  This is the area in which the content of the window
218          * should be placed.  It will be smaller than the display frame to
219          * account for screen decorations such as a status bar or soft
220          * keyboard.  Must be called with the
221          * window manager lock held.
222          *
223          * @return Rect The rectangle holding the content frame.
224          */
getContentFrameLw()225         public Rect getContentFrameLw();
226 
227         /**
228          * Retrieve the frame of the visible area that this window was last
229          * laid out in.  This is the area of the screen in which the window
230          * will actually be fully visible.  It will be smaller than the
231          * content frame to account for transient UI elements blocking it
232          * such as an input method's candidates UI.  Must be called with the
233          * window manager lock held.
234          *
235          * @return Rect The rectangle holding the visible frame.
236          */
getVisibleFrameLw()237         public Rect getVisibleFrameLw();
238 
239         /**
240          * Returns true if this window is waiting to receive its given
241          * internal insets from the client app, and so should not impact the
242          * layout of other windows.
243          */
getGivenInsetsPendingLw()244         public boolean getGivenInsetsPendingLw();
245 
246         /**
247          * Retrieve the insets given by this window's client for the content
248          * area of windows behind it.  Must be called with the
249          * window manager lock held.
250          *
251          * @return Rect The left, top, right, and bottom insets, relative
252          * to the window's frame, of the actual contents.
253          */
getGivenContentInsetsLw()254         public Rect getGivenContentInsetsLw();
255 
256         /**
257          * Retrieve the insets given by this window's client for the visible
258          * area of windows behind it.  Must be called with the
259          * window manager lock held.
260          *
261          * @return Rect The left, top, right, and bottom insets, relative
262          * to the window's frame, of the actual visible area.
263          */
getGivenVisibleInsetsLw()264         public Rect getGivenVisibleInsetsLw();
265 
266         /**
267          * Retrieve the current LayoutParams of the window.
268          *
269          * @return WindowManager.LayoutParams The window's internal LayoutParams
270          *         instance.
271          */
getAttrs()272         public WindowManager.LayoutParams getAttrs();
273 
274         /**
275          * Retrieve the current system UI visibility flags associated with
276          * this window.
277          */
getSystemUiVisibility()278         public int getSystemUiVisibility();
279 
280         /**
281          * Get the layer at which this window's surface will be Z-ordered.
282          */
getSurfaceLayer()283         public int getSurfaceLayer();
284 
285         /**
286          * Retrieve the type of the top-level window.
287          *
288          * @return the base type of the parent window if attached or its own type otherwise
289          */
getBaseType()290         public int getBaseType();
291 
292         /**
293          * Return the token for the application (actually activity) that owns
294          * this window.  May return null for system windows.
295          *
296          * @return An IApplicationToken identifying the owning activity.
297          */
getAppToken()298         public IApplicationToken getAppToken();
299 
300         /**
301          * Return true if this window is participating in voice interaction.
302          */
isVoiceInteraction()303         public boolean isVoiceInteraction();
304 
305         /**
306          * Return true if, at any point, the application token associated with
307          * this window has actually displayed any windows.  This is most useful
308          * with the "starting up" window to determine if any windows were
309          * displayed when it is closed.
310          *
311          * @return Returns true if one or more windows have been displayed,
312          *         else false.
313          */
hasAppShownWindows()314         public boolean hasAppShownWindows();
315 
316         /**
317          * Is this window visible?  It is not visible if there is no
318          * surface, or we are in the process of running an exit animation
319          * that will remove the surface.
320          */
isVisibleLw()321         boolean isVisibleLw();
322 
323         /**
324          * Is this window currently visible to the user on-screen?  It is
325          * displayed either if it is visible or it is currently running an
326          * animation before no longer being visible.  Must be called with the
327          * window manager lock held.
328          */
isDisplayedLw()329         boolean isDisplayedLw();
330 
331         /**
332          * Return true if this window (or a window it is attached to, but not
333          * considering its app token) is currently animating.
334          */
isAnimatingLw()335         boolean isAnimatingLw();
336 
337         /**
338          * Is this window considered to be gone for purposes of layout?
339          */
isGoneForLayoutLw()340         boolean isGoneForLayoutLw();
341 
342         /**
343          * Returns true if the window has a surface that it has drawn a
344          * complete UI in to. Note that this is different from {@link #hasDrawnLw()}
345          * in that it also returns true if the window is READY_TO_SHOW, but was not yet
346          * promoted to HAS_DRAWN.
347          */
isDrawnLw()348         boolean isDrawnLw();
349 
350         /**
351          * Returns true if this window has been shown on screen at some time in
352          * the past.  Must be called with the window manager lock held.
353          *
354          * @deprecated Use {@link #isDrawnLw} or any of the other drawn/visibility methods.
355          */
356         @Deprecated
hasDrawnLw()357         public boolean hasDrawnLw();
358 
359         /**
360          * Can be called by the policy to force a window to be hidden,
361          * regardless of whether the client or window manager would like
362          * it shown.  Must be called with the window manager lock held.
363          * Returns true if {@link #showLw} was last called for the window.
364          */
hideLw(boolean doAnimation)365         public boolean hideLw(boolean doAnimation);
366 
367         /**
368          * Can be called to undo the effect of {@link #hideLw}, allowing a
369          * window to be shown as long as the window manager and client would
370          * also like it to be shown.  Must be called with the window manager
371          * lock held.
372          * Returns true if {@link #hideLw} was last called for the window.
373          */
showLw(boolean doAnimation)374         public boolean showLw(boolean doAnimation);
375 
376         /**
377          * Check whether the process hosting this window is currently alive.
378          */
isAlive()379         public boolean isAlive();
380 
381         /**
382          * Check if window is on {@link Display#DEFAULT_DISPLAY}.
383          * @return true if window is on default display.
384          */
isDefaultDisplay()385         public boolean isDefaultDisplay();
386 
387         /**
388          * Check whether the window is currently dimming.
389          */
isDimming()390         public boolean isDimming();
391 
392         /**
393          * Returns true if the window is letterboxed for the display cutout.
394          */
isLetterboxedForDisplayCutoutLw()395         default boolean isLetterboxedForDisplayCutoutLw() {
396             return false;
397         }
398 
399         /** @return the current windowing mode of this window. */
getWindowingMode()400         int getWindowingMode();
401 
402         /**
403          * Returns the {@link WindowConfiguration.ActivityType} associated with the configuration
404          * of this window.
405          */
getActivityType()406         default int getActivityType() {
407             return WindowConfiguration.WINDOWING_MODE_UNDEFINED;
408         }
409 
410         /**
411          * Returns true if the window is current in multi-windowing mode. i.e. it shares the
412          * screen with other application windows.
413          */
inMultiWindowMode()414         boolean inMultiWindowMode();
415 
getRotationAnimationHint()416         public int getRotationAnimationHint();
417 
isInputMethodWindow()418         public boolean isInputMethodWindow();
419 
isInputMethodTarget()420         public boolean isInputMethodTarget();
421 
getDisplayId()422         public int getDisplayId();
423 
424         /**
425          * Returns true if the window owner can add internal system windows.
426          * That is, they have {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}.
427          */
canAddInternalSystemWindow()428         default boolean canAddInternalSystemWindow() {
429             return false;
430         }
431 
432         /**
433          * Returns true if the window owner has the permission to acquire a sleep token when it's
434          * visible. That is, they have the permission {@link Manifest.permission#DEVICE_POWER}.
435          */
canAcquireSleepToken()436         boolean canAcquireSleepToken();
437 
438         /** @return true if this window desires key events. */
canReceiveKeys()439         boolean canReceiveKeys();
440 
441         /** @return true if the window can show over keyguard. */
canShowWhenLocked()442         boolean canShowWhenLocked();
443 
444         /**
445          * Writes {@link com.android.server.wm.IdentifierProto} to stream.
446          */
writeIdentifierToProto(ProtoOutputStream proto, long fieldId)447         void writeIdentifierToProto(ProtoOutputStream proto, long fieldId);
448 
449         /**
450          * @return The {@link WindowFrames} associated with this {@link WindowState}
451          */
getWindowFrames()452         WindowFrames getWindowFrames();
453     }
454 
455     /**
456      * Representation of a input consumer that the policy has added to the
457      * window manager to consume input events going to windows below it.
458      */
459     public interface InputConsumer {
460         /**
461          * Remove the input consumer from the window manager.
462          */
dismiss()463         void dismiss();
464         /**
465          * Dispose the input consumer and input receiver from UI thread.
466          */
dispose()467         void dispose();
468     }
469 
470     /**
471      * Holds the contents of a starting window. {@link #addSplashScreen} needs to wrap the
472      * contents of the starting window into an class implementing this interface, which then will be
473      * held by WM and released with {@link #remove} when no longer needed.
474      */
475     interface StartingSurface {
476 
477         /**
478          * Removes the starting window surface. Do not hold the window manager lock when calling
479          * this method!
480          */
remove()481         void remove();
482     }
483 
484     /**
485      * Interface for calling back in to the window manager that is private
486      * between it and the policy.
487      */
488     public interface WindowManagerFuncs {
489         public static final int LID_ABSENT = -1;
490         public static final int LID_CLOSED = 0;
491         public static final int LID_OPEN = 1;
492 
493         public static final int LID_BEHAVIOR_NONE = 0;
494         public static final int LID_BEHAVIOR_SLEEP = 1;
495         public static final int LID_BEHAVIOR_LOCK = 2;
496 
497         public static final int CAMERA_LENS_COVER_ABSENT = -1;
498         public static final int CAMERA_LENS_UNCOVERED = 0;
499         public static final int CAMERA_LENS_COVERED = 1;
500 
501         /**
502          * Returns a code that describes the current state of the lid switch.
503          */
getLidState()504         public int getLidState();
505 
506         /**
507          * Lock the device now.
508          */
lockDeviceNow()509         public void lockDeviceNow();
510 
511         /**
512          * Returns a code that descripbes whether the camera lens is covered or not.
513          */
getCameraLensCoverState()514         public int getCameraLensCoverState();
515 
516         /**
517          * Switch the keyboard layout for the given device.
518          * Direction should be +1 or -1 to go to the next or previous keyboard layout.
519          */
switchKeyboardLayout(int deviceId, int direction)520         public void switchKeyboardLayout(int deviceId, int direction);
521 
shutdown(boolean confirm)522         public void shutdown(boolean confirm);
reboot(boolean confirm)523         public void reboot(boolean confirm);
rebootSafeMode(boolean confirm)524         public void rebootSafeMode(boolean confirm);
525 
526         /**
527          * Return the window manager lock needed to correctly call "Lw" methods.
528          */
getWindowManagerLock()529         public Object getWindowManagerLock();
530 
531         /** Register a system listener for touch events */
registerPointerEventListener(PointerEventListener listener, int displayId)532         void registerPointerEventListener(PointerEventListener listener, int displayId);
533 
534         /** Unregister a system listener for touch events */
unregisterPointerEventListener(PointerEventListener listener, int displayId)535         void unregisterPointerEventListener(PointerEventListener listener, int displayId);
536 
537         /**
538          * @return The currently active input method window.
539          */
getInputMethodWindowLw()540         WindowState getInputMethodWindowLw();
541 
542         /**
543          * Notifies window manager that {@link #isKeyguardTrustedLw} has changed.
544          */
notifyKeyguardTrustedChanged()545         void notifyKeyguardTrustedChanged();
546 
547         /**
548          * Notifies the window manager that screen is being turned off.
549          *
550          * @param listener callback to call when display can be turned off
551          */
screenTurningOff(ScreenOffListener listener)552         void screenTurningOff(ScreenOffListener listener);
553 
554         /**
555          * Convert the lid state to a human readable format.
556          */
lidStateToString(int lid)557         static String lidStateToString(int lid) {
558             switch (lid) {
559                 case LID_ABSENT:
560                     return "LID_ABSENT";
561                 case LID_CLOSED:
562                     return "LID_CLOSED";
563                 case LID_OPEN:
564                     return "LID_OPEN";
565                 default:
566                     return Integer.toString(lid);
567             }
568         }
569 
570         /**
571          * Convert the camera lens state to a human readable format.
572          */
cameraLensStateToString(int lens)573         static String cameraLensStateToString(int lens) {
574             switch (lens) {
575                 case CAMERA_LENS_COVER_ABSENT:
576                     return "CAMERA_LENS_COVER_ABSENT";
577                 case CAMERA_LENS_UNCOVERED:
578                     return "CAMERA_LENS_UNCOVERED";
579                 case CAMERA_LENS_COVERED:
580                     return "CAMERA_LENS_COVERED";
581                 default:
582                     return Integer.toString(lens);
583             }
584         }
585 
586         /**
587          * Hint to window manager that the user has started a navigation action that should
588          * abort animations that have no timeout, in case they got stuck.
589          */
triggerAnimationFailsafe()590         void triggerAnimationFailsafe();
591 
592         /**
593          * The keyguard showing state has changed
594          */
onKeyguardShowingAndNotOccludedChanged()595         void onKeyguardShowingAndNotOccludedChanged();
596 
597         /**
598          * Notifies window manager that power key is being pressed.
599          */
onPowerKeyDown(boolean isScreenOn)600         void onPowerKeyDown(boolean isScreenOn);
601 
602         /**
603          * Notifies window manager that user is switched.
604          */
onUserSwitched()605         void onUserSwitched();
606 
607         /**
608          * Hint to window manager that the user is interacting with a display that should be treated
609          * as the top display.
610          */
moveDisplayToTop(int displayId)611         void moveDisplayToTop(int displayId);
612     }
613 
614     /**
615      * Provides the rotation of a device.
616      *
617      * @see com.android.server.policy.WindowOrientationListener
618      */
619     public interface RotationSource {
getProposedRotation()620         int getProposedRotation();
621 
setCurrentRotation(int rotation)622         void setCurrentRotation(int rotation);
623     }
624 
625     /**
626      * Interface to get public information of a display content.
627      */
628     public interface DisplayContentInfo {
getDisplayRotation()629         DisplayRotation getDisplayRotation();
getDisplay()630         Display getDisplay();
631     }
632 
633     /** Window has been added to the screen. */
634     public static final int TRANSIT_ENTER = 1;
635     /** Window has been removed from the screen. */
636     public static final int TRANSIT_EXIT = 2;
637     /** Window has been made visible. */
638     public static final int TRANSIT_SHOW = 3;
639     /** Window has been made invisible.
640      * TODO: Consider removal as this is unused. */
641     public static final int TRANSIT_HIDE = 4;
642     /** The "application starting" preview window is no longer needed, and will
643      * animate away to show the real window. */
644     public static final int TRANSIT_PREVIEW_DONE = 5;
645 
646     // NOTE: screen off reasons are in order of significance, with more
647     // important ones lower than less important ones.
648 
649     /** @hide */
650     @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED})
651     @Retention(RetentionPolicy.SOURCE)
652     public @interface UserRotationMode {}
653 
654     /** When not otherwise specified by the activity's screenOrientation, rotation should be
655      * determined by the system (that is, using sensors). */
656     public final int USER_ROTATION_FREE = 0;
657     /** When not otherwise specified by the activity's screenOrientation, rotation is set by
658      * the user. */
659     public final int USER_ROTATION_LOCKED = 1;
660 
661     /**
662      * Set the default display content to provide basic functions for the policy.
663      */
setDefaultDisplay(DisplayContentInfo displayContentInfo)664     public void setDefaultDisplay(DisplayContentInfo displayContentInfo);
665 
666     /**
667      * Perform initialization of the policy.
668      *
669      * @param context The system context we are running in.
670      */
init(Context context, IWindowManager windowManager, WindowManagerFuncs windowManagerFuncs)671     public void init(Context context, IWindowManager windowManager,
672             WindowManagerFuncs windowManagerFuncs);
673 
674     /**
675      * Check permissions when adding a window or a window token from
676      * {@link android.app.WindowContext}.
677      *
678      * @param type The window type
679      * @param isRoundedCornerOverlay {@code true} to indicate the adding window is
680      *                                           round corner overlay.
681      * @param packageName package name
682      * @param outAppOp First element will be filled with the app op corresponding to
683      *                 this window, or OP_NONE.
684      *
685      * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed;
686      *      else an error code, usually
687      *      {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add.
688      *
689      * @see IWindowManager#addWindowTokenWithOptions(IBinder, int, int, Bundle, String)
690      * @see WindowManager.LayoutParams#PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY
691      */
checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName, int[] outAppOp)692     int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName,
693             int[] outAppOp);
694 
695     /**
696      * After the window manager has computed the current configuration based
697      * on its knowledge of the display and input devices, it gives the policy
698      * a chance to adjust the information contained in it.  If you want to
699      * leave it as-is, simply do nothing.
700      *
701      * <p>This method may be called by any thread in the window manager, but
702      * no internal locks in the window manager will be held.
703      *
704      * @param config The Configuration being computed, for you to change as
705      * desired.
706      * @param keyboardPresence Flags that indicate whether internal or external
707      * keyboards are present.
708      * @param navigationPresence Flags that indicate whether internal or external
709      * navigation devices are present.
710      */
adjustConfigurationLw(Configuration config, int keyboardPresence, int navigationPresence)711     public void adjustConfigurationLw(Configuration config, int keyboardPresence,
712             int navigationPresence);
713 
714     /**
715      * Returns the layer assignment for the window state. Allows you to control how different
716      * kinds of windows are ordered on-screen.
717      *
718      * @param win The window state
719      * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
720      */
getWindowLayerLw(WindowState win)721     default int getWindowLayerLw(WindowState win) {
722         return getWindowLayerFromTypeLw(win.getBaseType(), win.canAddInternalSystemWindow());
723     }
724 
725     /**
726      * Returns the layer assignment for the window type. Allows you to control how different
727      * kinds of windows are ordered on-screen.
728      *
729      * @param type The type of window being assigned.
730      * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
731      */
getWindowLayerFromTypeLw(int type)732     default int getWindowLayerFromTypeLw(int type) {
733         if (isSystemAlertWindowType(type)) {
734             throw new IllegalArgumentException("Use getWindowLayerFromTypeLw() or"
735                     + " getWindowLayerLw() for alert window types");
736         }
737         return getWindowLayerFromTypeLw(type, false /* canAddInternalSystemWindow */);
738     }
739 
740     /**
741      * Returns the layer assignment for the window type. Allows you to control how different
742      * kinds of windows are ordered on-screen.
743      *
744      * @param type The type of window being assigned.
745      * @param canAddInternalSystemWindow If the owner window associated with the type we are
746      *        evaluating can add internal system windows. I.e they have
747      *        {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}. If true, alert window
748      *        types {@link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)}
749      *        can be assigned layers greater than the layer for
750      *        {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} Else, their
751      *        layers would be lesser.
752      * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
753      */
getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow)754     default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow) {
755         if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
756             return APPLICATION_LAYER;
757         }
758 
759         switch (type) {
760             case TYPE_WALLPAPER:
761                 // wallpaper is at the bottom, though the window manager may move it.
762                 return  1;
763             case TYPE_PRESENTATION:
764             case TYPE_PRIVATE_PRESENTATION:
765                 return  APPLICATION_LAYER;
766             case TYPE_DOCK_DIVIDER:
767                 return  APPLICATION_LAYER;
768             case TYPE_QS_DIALOG:
769                 return  APPLICATION_LAYER;
770             case TYPE_PHONE:
771                 return  3;
772             case TYPE_SEARCH_BAR:
773             case TYPE_VOICE_INTERACTION_STARTING:
774                 return  4;
775             case TYPE_VOICE_INTERACTION:
776                 // voice interaction layer is almost immediately above apps.
777                 return  5;
778             case TYPE_INPUT_CONSUMER:
779                 return  6;
780             case TYPE_SYSTEM_DIALOG:
781                 return  7;
782             case TYPE_TOAST:
783                 // toasts and the plugged-in battery thing
784                 return  8;
785             case TYPE_PRIORITY_PHONE:
786                 // SIM errors and unlock.  Not sure if this really should be in a high layer.
787                 return  9;
788             case TYPE_SYSTEM_ALERT:
789                 // like the ANR / app crashed dialogs
790                 // Type is deprecated for non-system apps. For system apps, this type should be
791                 // in a higher layer than TYPE_APPLICATION_OVERLAY.
792                 return  canAddInternalSystemWindow ? 13 : 10;
793             case TYPE_APPLICATION_OVERLAY:
794             case TYPE_TRUSTED_APPLICATION_OVERLAY:
795                 return  12;
796             case TYPE_INPUT_METHOD:
797                 // on-screen keyboards and other such input method user interfaces go here.
798                 return  15;
799             case TYPE_INPUT_METHOD_DIALOG:
800                 // on-screen keyboards and other such input method user interfaces go here.
801                 return  16;
802             case TYPE_STATUS_BAR:
803                 return  17;
804             case TYPE_STATUS_BAR_ADDITIONAL:
805                 return  18;
806             case TYPE_NOTIFICATION_SHADE:
807                 return  19;
808             case TYPE_STATUS_BAR_SUB_PANEL:
809                 return  20;
810             case TYPE_KEYGUARD_DIALOG:
811                 return  21;
812             case TYPE_VOLUME_OVERLAY:
813                 // the on-screen volume indicator and controller shown when the user
814                 // changes the device volume
815                 return  22;
816             case TYPE_SYSTEM_OVERLAY:
817                 // the on-screen volume indicator and controller shown when the user
818                 // changes the device volume
819                 return  canAddInternalSystemWindow ? 23 : 11;
820             case TYPE_NAVIGATION_BAR:
821                 // the navigation bar, if available, shows atop most things
822                 return  24;
823             case TYPE_NAVIGATION_BAR_PANEL:
824                 // some panels (e.g. search) need to show on top of the navigation bar
825                 return  25;
826             case TYPE_SCREENSHOT:
827                 // screenshot selection layer shouldn't go above system error, but it should cover
828                 // navigation bars at the very least.
829                 return  26;
830             case TYPE_SYSTEM_ERROR:
831                 // system-level error dialogs
832                 return  canAddInternalSystemWindow ? 27 : 10;
833             case TYPE_MAGNIFICATION_OVERLAY:
834                 // used to highlight the magnified portion of a display
835                 return  28;
836             case TYPE_DISPLAY_OVERLAY:
837                 // used to simulate secondary display devices
838                 return  29;
839             case TYPE_DRAG:
840                 // the drag layer: input for drag-and-drop is associated with this window,
841                 // which sits above all other focusable windows
842                 return  30;
843             case TYPE_ACCESSIBILITY_OVERLAY:
844                 // overlay put by accessibility services to intercept user interaction
845                 return  31;
846             case TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY:
847                 return 32;
848             case TYPE_SECURE_SYSTEM_OVERLAY:
849                 return  33;
850             case TYPE_BOOT_PROGRESS:
851                 return  34;
852             case TYPE_POINTER:
853                 // the (mouse) pointer layer
854                 return  35;
855             default:
856                 Slog.e("WindowManager", "Unknown window type: " + type);
857                 return APPLICATION_LAYER;
858         }
859     }
860 
getMaxWindowLayer()861     default int getMaxWindowLayer() {
862         return 35;
863     }
864 
865     /**
866      * Return how to Z-order sub-windows in relation to the window they are attached to.
867      * Return positive to have them ordered in front, negative for behind.
868      *
869      * @param type The sub-window type code.
870      *
871      * @return int Layer in relation to the attached window, where positive is
872      *         above and negative is below.
873      */
getSubWindowLayerFromTypeLw(int type)874     default int getSubWindowLayerFromTypeLw(int type) {
875         switch (type) {
876             case TYPE_APPLICATION_PANEL:
877             case TYPE_APPLICATION_ATTACHED_DIALOG:
878                 return APPLICATION_PANEL_SUBLAYER;
879             case TYPE_APPLICATION_MEDIA:
880                 return APPLICATION_MEDIA_SUBLAYER;
881             case TYPE_APPLICATION_MEDIA_OVERLAY:
882                 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
883             case TYPE_APPLICATION_SUB_PANEL:
884                 return APPLICATION_SUB_PANEL_SUBLAYER;
885             case TYPE_APPLICATION_ABOVE_SUB_PANEL:
886                 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
887         }
888         Slog.e("WindowManager", "Unknown sub-window type: " + type);
889         return 0;
890     }
891 
892     /**
893      * Get the highest layer (actually one more than) that the wallpaper is
894      * allowed to be in.
895      */
getMaxWallpaperLayer()896     public int getMaxWallpaperLayer();
897 
898     /**
899      * Return whether the given window can become the Keyguard window. Typically returns true for
900      * the StatusBar.
901      */
isKeyguardHostWindow(WindowManager.LayoutParams attrs)902     public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs);
903 
904     /**
905      * @return whether {@param win} can be hidden by Keyguard
906      */
canBeHiddenByKeyguardLw(WindowState win)907     public boolean canBeHiddenByKeyguardLw(WindowState win);
908 
909     /**
910      * Called when the system would like to show a UI to indicate that an
911      * application is starting.  You can use this to add a
912      * APPLICATION_STARTING_TYPE window with the given appToken to the window
913      * manager (using the normal window manager APIs) that will be shown until
914      * the application displays its own window.  This is called without the
915      * window manager locked so that you can call back into it.
916      *
917      * @param appToken Token of the application being started.
918      * @param packageName The name of the application package being started.
919      * @param theme Resource defining the application's overall visual theme.
920      * @param nonLocalizedLabel The default title label of the application if
921      *        no data is found in the resource.
922      * @param labelRes The resource ID the application would like to use as its name.
923      * @param icon The resource ID the application would like to use as its icon.
924      * @param windowFlags Window layout flags.
925      * @param overrideConfig override configuration to consider when generating
926      *        context to for resources.
927      * @param displayId Id of the display to show the splash screen at.
928      *
929      * @return The starting surface.
930      *
931      */
addSplashScreen(IBinder appToken, String packageName, int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, Configuration overrideConfig, int displayId)932     public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme,
933             CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
934             int logo, int windowFlags, Configuration overrideConfig, int displayId);
935 
936     /**
937      * Set or clear a window which can behave as the keyguard.
938      *
939      * @param win The window which can behave as the keyguard.
940      */
setKeyguardCandidateLw(@ullable WindowState win)941     void setKeyguardCandidateLw(@Nullable WindowState win);
942 
943     /**
944      * Create and return an animation to re-display a window that was force hidden by Keyguard.
945      */
createHiddenByKeyguardExit(boolean onWallpaper, boolean goingToNotificationShade, boolean subtleAnimation)946     public Animation createHiddenByKeyguardExit(boolean onWallpaper,
947             boolean goingToNotificationShade, boolean subtleAnimation);
948 
949     /**
950      * Create and return an animation to let the wallpaper disappear after being shown behind
951      * Keyguard.
952      */
createKeyguardWallpaperExit(boolean goingToNotificationShade)953     public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade);
954 
955     /**
956      * Called from the input reader thread before a key is enqueued.
957      *
958      * <p>There are some actions that need to be handled here because they
959      * affect the power state of the device, for example, the power keys.
960      * Generally, it's best to keep as little as possible in the queue thread
961      * because it's the most fragile.
962      * @param event The key event.
963      * @param policyFlags The policy flags associated with the key.
964      *
965      * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
966      */
interceptKeyBeforeQueueing(KeyEvent event, int policyFlags)967     public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
968 
969     /**
970      * Called from the input reader thread before a motion is enqueued when the device is in a
971      * non-interactive state.
972      *
973      * <p>There are some actions that need to be handled here because they
974      * affect the power state of the device, for example, waking on motions.
975      * Generally, it's best to keep as little as possible in the queue thread
976      * because it's the most fragile.
977      * @param displayId The display ID of the motion event.
978      * @param policyFlags The policy flags associated with the motion.
979      *
980      * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
981      */
interceptMotionBeforeQueueingNonInteractive(int displayId, long whenNanos, int policyFlags)982     int interceptMotionBeforeQueueingNonInteractive(int displayId, long whenNanos,
983             int policyFlags);
984 
985     /**
986      * Called from the input dispatcher thread before a key is dispatched to a window.
987      *
988      * <p>Allows you to define
989      * behavior for keys that can not be overridden by applications.
990      * This method is called from the input thread, with no locks held.
991      *
992      * @param focusedToken Client window token that currently has focus. This is where the key
993      *            event will normally go.
994      * @param event The key event.
995      * @param policyFlags The policy flags associated with the key.
996      * @return 0 if the key should be dispatched immediately, -1 if the key should
997      * not be dispatched ever, or a positive value indicating the number of
998      * milliseconds by which the key dispatch should be delayed before trying
999      * again.
1000      */
interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event, int policyFlags)1001     long interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event, int policyFlags);
1002 
1003     /**
1004      * Called from the input dispatcher thread when an application did not handle
1005      * a key that was dispatched to it.
1006      *
1007      * <p>Allows you to define default global behavior for keys that were not handled
1008      * by applications.  This method is called from the input thread, with no locks held.
1009      *
1010      * @param focusedToken Client window token that currently has focus. This is where the key
1011      *            event will normally go.
1012      * @param event The key event.
1013      * @param policyFlags The policy flags associated with the key.
1014      * @return Returns an alternate key event to redispatch as a fallback, or null to give up.
1015      * The caller is responsible for recycling the key event.
1016      */
dispatchUnhandledKey(IBinder focusedToken, KeyEvent event, int policyFlags)1017     KeyEvent dispatchUnhandledKey(IBinder focusedToken, KeyEvent event, int policyFlags);
1018 
1019     /**
1020      * Called when the top focused display is changed.
1021      *
1022      * @param displayId The ID of the top focused display.
1023      */
setTopFocusedDisplay(int displayId)1024     void setTopFocusedDisplay(int displayId);
1025 
1026     /**
1027      * Apply the keyguard policy to a specific window.
1028      *
1029      * @param win The window to apply the keyguard policy.
1030      * @param imeTarget The current IME target window.
1031      */
applyKeyguardPolicyLw(WindowState win, WindowState imeTarget)1032     void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget);
1033 
1034     /**
1035      * Called when the state of allow-lockscreen-when-on of the display is changed. See
1036      * {@link WindowManager.LayoutParams#FLAG_ALLOW_LOCK_WHILE_SCREEN_ON}
1037      *
1038      * @param displayId The ID of the display.
1039      * @param allow Whether the display allows showing lockscreen when it is on.
1040      */
setAllowLockscreenWhenOn(int displayId, boolean allow)1041     void setAllowLockscreenWhenOn(int displayId, boolean allow);
1042 
1043     /**
1044      * Called when the device has started waking up.
1045      */
startedWakingUp(@nReason int reason)1046     void startedWakingUp(@OnReason int reason);
1047 
1048     /**
1049      * Called when the device has finished waking up.
1050      */
finishedWakingUp(@nReason int reason)1051     void finishedWakingUp(@OnReason int reason);
1052 
1053     /**
1054      * Called when the device has started going to sleep.
1055      *
1056      * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
1057      * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
1058      */
startedGoingToSleep(int why)1059     public void startedGoingToSleep(int why);
1060 
1061     /**
1062      * Called when the device has finished going to sleep.
1063      *
1064      * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
1065      * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
1066      */
finishedGoingToSleep(int why)1067     public void finishedGoingToSleep(int why);
1068 
1069     /**
1070      * Called when the device is about to turn on the screen to show content.
1071      * When waking up, this method will be called once after the call to wakingUp().
1072      * When dozing, the method will be called sometime after the call to goingToSleep() and
1073      * may be called repeatedly in the case where the screen is pulsing on and off.
1074      *
1075      * Must call back on the listener to tell it when the higher-level system
1076      * is ready for the screen to go on (i.e. the lock screen is shown).
1077      */
screenTurningOn(ScreenOnListener screenOnListener)1078     public void screenTurningOn(ScreenOnListener screenOnListener);
1079 
1080     /**
1081      * Called when the device has actually turned on the screen, i.e. the display power state has
1082      * been set to ON and the screen is unblocked.
1083      */
screenTurnedOn()1084     public void screenTurnedOn();
1085 
1086     /**
1087      * Called when the display would like to be turned off. This gives policy a chance to do some
1088      * things before the display power state is actually changed to off.
1089      *
1090      * @param screenOffListener Must be called to tell that the display power state can actually be
1091      *                          changed now after policy has done its work.
1092      */
screenTurningOff(ScreenOffListener screenOffListener)1093     public void screenTurningOff(ScreenOffListener screenOffListener);
1094 
1095     /**
1096      * Called when the device has turned the screen off.
1097      */
screenTurnedOff()1098     public void screenTurnedOff();
1099 
1100     public interface ScreenOnListener {
onScreenOn()1101         void onScreenOn();
1102     }
1103 
1104     /**
1105      * See {@link #screenTurnedOff}
1106      */
1107     public interface ScreenOffListener {
onScreenOff()1108         void onScreenOff();
1109     }
1110 
1111     /**
1112      * Return whether the default display is on and not blocked by a black surface.
1113      */
isScreenOn()1114     public boolean isScreenOn();
1115 
1116     /**
1117      * @return whether the device is currently allowed to animate.
1118      *
1119      * Note: this can be true even if it is not appropriate to animate for reasons that are outside
1120      *       of the policy's authority.
1121      */
okToAnimate()1122     boolean okToAnimate();
1123 
1124     /**
1125      * Tell the policy that the lid switch has changed state.
1126      * @param whenNanos The time when the change occurred in uptime nanoseconds.
1127      * @param lidOpen True if the lid is now open.
1128      */
notifyLidSwitchChanged(long whenNanos, boolean lidOpen)1129     public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
1130 
1131     /**
1132      * Tell the policy that the camera lens has been covered or uncovered.
1133      * @param whenNanos The time when the change occurred in uptime nanoseconds.
1134      * @param lensCovered True if the lens is covered.
1135      */
notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered)1136     public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered);
1137 
1138     /**
1139      * Tell the policy if anyone is requesting that keyguard not come on.
1140      *
1141      * @param enabled Whether keyguard can be on or not.  does not actually
1142      * turn it on, unless it was previously disabled with this function.
1143      *
1144      * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard()
1145      * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard()
1146      */
1147     @SuppressWarnings("javadoc")
enableKeyguard(boolean enabled)1148     public void enableKeyguard(boolean enabled);
1149 
1150     /**
1151      * Callback used by {@link #exitKeyguardSecurely}
1152      */
1153     interface OnKeyguardExitResult {
onKeyguardExitResult(boolean success)1154         void onKeyguardExitResult(boolean success);
1155     }
1156 
1157     /**
1158      * Tell the policy if anyone is requesting the keyguard to exit securely
1159      * (this would be called after the keyguard was disabled)
1160      * @param callback Callback to send the result back.
1161      * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)
1162      */
1163     @SuppressWarnings("javadoc")
exitKeyguardSecurely(OnKeyguardExitResult callback)1164     void exitKeyguardSecurely(OnKeyguardExitResult callback);
1165 
1166     /**
1167      * isKeyguardLocked
1168      *
1169      * Return whether the keyguard is currently locked.
1170      *
1171      * @return true if in keyguard is locked.
1172      */
isKeyguardLocked()1173     public boolean isKeyguardLocked();
1174 
1175     /**
1176      * isKeyguardSecure
1177      *
1178      * Return whether the keyguard requires a password to unlock.
1179      * @param userId
1180      *
1181      * @return true if in keyguard is secure.
1182      */
isKeyguardSecure(int userId)1183     public boolean isKeyguardSecure(int userId);
1184 
1185     /**
1186      * Return whether the keyguard is currently occluded.
1187      *
1188      * @return true if in keyguard is occluded, false otherwise
1189      */
isKeyguardOccluded()1190     public boolean isKeyguardOccluded();
1191 
1192     /**
1193      * @return true if in keyguard is on.
1194      */
isKeyguardShowing()1195     boolean isKeyguardShowing();
1196 
1197     /**
1198      * @return true if in keyguard is on and not occluded.
1199      */
isKeyguardShowingAndNotOccluded()1200     public boolean isKeyguardShowingAndNotOccluded();
1201 
1202     /**
1203      * @return whether Keyguard is in trusted state and can be dismissed without credentials
1204      */
isKeyguardTrustedLw()1205     public boolean isKeyguardTrustedLw();
1206 
1207     /**
1208      * inKeyguardRestrictedKeyInputMode
1209      *
1210      * If keyguard screen is showing or in restricted key input mode (i.e. in
1211      * keyguard password emergency screen). When in such mode, certain keys,
1212      * such as the Home key and the right soft keys, don't work.
1213      *
1214      * @return true if in keyguard restricted input mode.
1215      */
inKeyguardRestrictedKeyInputMode()1216     public boolean inKeyguardRestrictedKeyInputMode();
1217 
1218     /**
1219      * Ask the policy to dismiss the keyguard, if it is currently shown.
1220      *
1221      * @param callback Callback to be informed about the result.
1222      * @param message A message that should be displayed in the keyguard.
1223      */
dismissKeyguardLw(@ullable IKeyguardDismissCallback callback, CharSequence message)1224     public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback,
1225             CharSequence message);
1226 
1227     /**
1228      * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method
1229      * returns true as soon as we know that Keyguard is disabled.
1230      *
1231      * @return true if the keyguard has drawn.
1232      */
isKeyguardDrawnLw()1233     public boolean isKeyguardDrawnLw();
1234 
1235     /**
1236      * Called when the system is mostly done booting to set whether
1237      * the system should go into safe mode.
1238      */
setSafeMode(boolean safeMode)1239     public void setSafeMode(boolean safeMode);
1240 
1241     /**
1242      * Called when the system is mostly done booting.
1243      */
systemReady()1244     public void systemReady();
1245 
1246     /**
1247      * Called when the system is done booting to the point where the
1248      * user can start interacting with it.
1249      */
systemBooted()1250     public void systemBooted();
1251 
1252     /**
1253      * Show boot time message to the user.
1254      */
showBootMessage(final CharSequence msg, final boolean always)1255     public void showBootMessage(final CharSequence msg, final boolean always);
1256 
1257     /**
1258      * Hide the UI for showing boot messages, never to be displayed again.
1259      */
hideBootMessages()1260     public void hideBootMessages();
1261 
1262     /**
1263      * Called when userActivity is signalled in the power manager.
1264      * This is safe to call from any thread, with any window manager locks held or not.
1265      */
userActivity()1266     public void userActivity();
1267 
1268     /**
1269      * Called when we have finished booting and can now display the home
1270      * screen to the user.  This will happen after systemReady(), and at
1271      * this point the display is active.
1272      */
enableScreenAfterBoot()1273     public void enableScreenAfterBoot();
1274 
1275     /**
1276      * Call from application to perform haptic feedback on its window.
1277      */
performHapticFeedback(int uid, String packageName, int effectId, boolean always, String reason)1278     public boolean performHapticFeedback(int uid, String packageName, int effectId,
1279             boolean always, String reason);
1280 
1281     /**
1282      * Called when we have started keeping the screen on because a window
1283      * requesting this has become visible.
1284      */
keepScreenOnStartedLw()1285     public void keepScreenOnStartedLw();
1286 
1287     /**
1288      * Called when we have stopped keeping the screen on because the last window
1289      * requesting this is no longer visible.
1290      */
keepScreenOnStoppedLw()1291     public void keepScreenOnStoppedLw();
1292 
1293     /**
1294      * Called by System UI to notify of changes to the visibility of Recents.
1295      */
setRecentsVisibilityLw(boolean visible)1296     public void setRecentsVisibilityLw(boolean visible);
1297 
1298     /**
1299      * Called by System UI to notify of changes to the visibility of PIP.
1300      */
setPipVisibilityLw(boolean visible)1301     void setPipVisibilityLw(boolean visible);
1302 
1303     /**
1304      * Called by System UI to enable or disable haptic feedback on the navigation bar buttons.
1305      */
setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled)1306     void setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled);
1307 
1308     /**
1309      * Specifies whether there is an on-screen navigation bar separate from the status bar.
1310      */
hasNavigationBar()1311     public boolean hasNavigationBar();
1312 
1313     /**
1314      * Lock the device now.
1315      */
lockNow(Bundle options)1316     public void lockNow(Bundle options);
1317 
1318     /**
1319      * An internal callback (from InputMethodManagerService) to notify a state change regarding
1320      * whether the back key should dismiss the software keyboard (IME) or not.
1321      *
1322      * @param newValue {@code true} if the software keyboard is shown and the back key is expected
1323      *                 to dismiss the software keyboard.
1324      * @hide
1325      */
setDismissImeOnBackKeyPressed(boolean newValue)1326     default void setDismissImeOnBackKeyPressed(boolean newValue) {
1327         // Default implementation does nothing.
1328     }
1329 
1330     /**
1331      * Show the recents task list app.
1332      * @hide
1333      */
showRecentApps()1334     public void showRecentApps();
1335 
1336     /**
1337      * Show the global actions dialog.
1338      * @hide
1339      */
showGlobalActions()1340     public void showGlobalActions();
1341 
1342     /**
1343      * Returns whether the user setup is complete.
1344      */
isUserSetupComplete()1345     boolean isUserSetupComplete();
1346 
1347     /**
1348      * Returns the current UI mode.
1349      */
getUiMode()1350     int getUiMode();
1351 
1352     /**
1353      * Called when the current user changes. Guaranteed to be called before the broadcast
1354      * of the new user id is made to all listeners.
1355      *
1356      * @param newUserId The id of the incoming user.
1357      */
setCurrentUserLw(int newUserId)1358     public void setCurrentUserLw(int newUserId);
1359 
1360     /**
1361      * For a given user-switch operation, this will be called once with switching=true before the
1362      * user-switch and once with switching=false afterwards (or if the user-switch was cancelled).
1363      * This gives the policy a chance to alter its behavior for the duration of a user-switch.
1364      *
1365      * @param switching true if a user-switch is in progress
1366      */
setSwitchingUser(boolean switching)1367     void setSwitchingUser(boolean switching);
1368 
1369     /**
1370      * Print the WindowManagerPolicy's state into the given stream.
1371      *
1372      * @param prefix Text to print at the front of each line.
1373      * @param writer The PrintWriter to which you should dump your state.  This will be
1374      * closed for you after you return.
1375      * @param args additional arguments to the dump request.
1376      */
dump(String prefix, PrintWriter writer, String[] args)1377     public void dump(String prefix, PrintWriter writer, String[] args);
1378 
1379     /**
1380      * Write the WindowManagerPolicy's state into the protocol buffer.
1381      * The message is described in {@link com.android.server.wm.WindowManagerPolicyProto}
1382      *
1383      * @param proto The protocol buffer output stream to write to.
1384      */
dumpDebug(ProtoOutputStream proto, long fieldId)1385     void dumpDebug(ProtoOutputStream proto, long fieldId);
1386 
1387     /**
1388      * Returns whether a given window type is considered a top level one.
1389      * A top level window does not have a container, i.e. attached window,
1390      * or if it has a container it is laid out as a top-level window, not
1391      * as a child of its container.
1392      *
1393      * @param windowType The window type.
1394      * @return True if the window is a top level one.
1395      */
isTopLevelWindow(int windowType)1396     public boolean isTopLevelWindow(int windowType);
1397 
1398     /**
1399      * Notifies the keyguard to start fading out.
1400      *
1401      * @param startTime the start time of the animation in uptime milliseconds
1402      * @param fadeoutDuration the duration of the exit animation, in milliseconds
1403      */
startKeyguardExitAnimation(long startTime, long fadeoutDuration)1404     public void startKeyguardExitAnimation(long startTime, long fadeoutDuration);
1405 
1406     /**
1407      * Called when System UI has been started.
1408      */
onSystemUiStarted()1409     void onSystemUiStarted();
1410 
1411     /**
1412      * Checks whether the policy is ready for dismissing the boot animation and completing the boot.
1413      *
1414      * @return true if ready; false otherwise.
1415      */
canDismissBootAnimation()1416     boolean canDismissBootAnimation();
1417 
1418     /**
1419      * Convert the user rotation mode to a human readable format.
1420      */
userRotationModeToString(int mode)1421     static String userRotationModeToString(int mode) {
1422         switch(mode) {
1423             case USER_ROTATION_FREE:
1424                 return "USER_ROTATION_FREE";
1425             case USER_ROTATION_LOCKED:
1426                 return "USER_ROTATION_LOCKED";
1427             default:
1428                 return Integer.toString(mode);
1429         }
1430     }
1431 
1432     /**
1433      * Registers an IDisplayFoldListener.
1434      */
registerDisplayFoldListener(IDisplayFoldListener listener)1435     default void registerDisplayFoldListener(IDisplayFoldListener listener) {}
1436 
1437     /**
1438      * Unregisters an IDisplayFoldListener.
1439      */
unregisterDisplayFoldListener(IDisplayFoldListener listener)1440     default void unregisterDisplayFoldListener(IDisplayFoldListener listener) {}
1441 
1442     /**
1443      * Overrides the folded area.
1444      *
1445      * @param area the overriding folded area or an empty {@code Rect} to clear the override.
1446      */
setOverrideFoldedArea(@onNull Rect area)1447     default void setOverrideFoldedArea(@NonNull Rect area) {}
1448 
1449     /**
1450      * Get the display folded area.
1451      */
getFoldedArea()1452     default @NonNull Rect getFoldedArea() {
1453         return new Rect();
1454     }
1455 
1456     /**
1457      * A new window on default display has been focused.
1458      */
onDefaultDisplayFocusChangedLw(WindowState newFocus)1459     default void onDefaultDisplayFocusChangedLw(WindowState newFocus) {}
1460 
1461     /**
1462      * Updates the flag about whether AOD is showing.
1463      *
1464      * @return whether the value was changed.
1465      */
setAodShowing(boolean aodShowing)1466     boolean setAodShowing(boolean aodShowing);
1467 }
1468