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