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      * Interface to the Window Manager state associated with a particular
182      * window. You can hold on to an instance of this interface from the call
183      * to prepareAddWindow() until removeWindow().
184      */
185     public interface WindowState {
186         /**
187          * Return the package name of the app that owns this window.
188          */
getOwningPackage()189         String getOwningPackage();
190 
191         /**
192          * Retrieve the type of the top-level window.
193          *
194          * @return the base type of the parent window if attached or its own type otherwise
195          */
getBaseType()196         public int getBaseType();
197 
198         /**
199          * Return true if this window (or a window it is attached to, but not
200          * considering its app token) is currently animating.
201          */
isAnimatingLw()202         boolean isAnimatingLw();
203 
204         /**
205          * Returns true if the window owner can add internal system windows.
206          * That is, they have {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}.
207          */
canAddInternalSystemWindow()208         default boolean canAddInternalSystemWindow() {
209             return false;
210         }
211 
212         /** @return true if the window can show over keyguard. */
canShowWhenLocked()213         boolean canShowWhenLocked();
214     }
215 
216     /**
217      * Interface for calling back in to the window manager that is private
218      * between it and the policy.
219      */
220     public interface WindowManagerFuncs {
221         public static final int LID_ABSENT = -1;
222         public static final int LID_CLOSED = 0;
223         public static final int LID_OPEN = 1;
224 
225         public static final int LID_BEHAVIOR_NONE = 0;
226         public static final int LID_BEHAVIOR_SLEEP = 1;
227         public static final int LID_BEHAVIOR_LOCK = 2;
228 
229         public static final int CAMERA_LENS_COVER_ABSENT = -1;
230         public static final int CAMERA_LENS_UNCOVERED = 0;
231         public static final int CAMERA_LENS_COVERED = 1;
232 
233         /**
234          * Returns a code that describes the current state of the lid switch.
235          */
getLidState()236         public int getLidState();
237 
238         /**
239          * Lock the device now.
240          */
lockDeviceNow()241         public void lockDeviceNow();
242 
243         /**
244          * Returns a code that descripbes whether the camera lens is covered or not.
245          */
getCameraLensCoverState()246         public int getCameraLensCoverState();
247 
248         /**
249          * Switch the keyboard layout for the given device.
250          * Direction should be +1 or -1 to go to the next or previous keyboard layout.
251          */
switchKeyboardLayout(int deviceId, int direction)252         public void switchKeyboardLayout(int deviceId, int direction);
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 policyFlags The policy flags associated with the motion.
710      *
711      * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
712      */
interceptMotionBeforeQueueingNonInteractive(int displayId, long whenNanos, int policyFlags)713     int interceptMotionBeforeQueueingNonInteractive(int displayId, long whenNanos,
714             int policyFlags);
715 
716     /**
717      * Called from the input dispatcher thread before a key is dispatched to a window.
718      *
719      * <p>Allows you to define
720      * behavior for keys that can not be overridden by applications.
721      * This method is called from the input thread, with no locks held.
722      *
723      * @param focusedToken Client window token that currently has focus. This is where the key
724      *            event will normally go.
725      * @param event The key event.
726      * @param policyFlags The policy flags associated with the key.
727      * @return 0 if the key should be dispatched immediately, -1 if the key should
728      * not be dispatched ever, or a positive value indicating the number of
729      * milliseconds by which the key dispatch should be delayed before trying
730      * again.
731      */
interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event, int policyFlags)732     long interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event, int policyFlags);
733 
734     /**
735      * Called from the input dispatcher thread when an application did not handle
736      * a key that was dispatched to it.
737      *
738      * <p>Allows you to define default global behavior for keys that were not handled
739      * by applications.  This method is called from the input thread, with no locks held.
740      *
741      * @param focusedToken Client window token that currently has focus. This is where the key
742      *            event will normally go.
743      * @param event The key event.
744      * @param policyFlags The policy flags associated with the key.
745      * @return Returns an alternate key event to redispatch as a fallback, or null to give up.
746      * The caller is responsible for recycling the key event.
747      */
dispatchUnhandledKey(IBinder focusedToken, KeyEvent event, int policyFlags)748     KeyEvent dispatchUnhandledKey(IBinder focusedToken, KeyEvent event, int policyFlags);
749 
750     /**
751      * Called when the top focused display is changed.
752      *
753      * @param displayId The ID of the top focused display.
754      */
setTopFocusedDisplay(int displayId)755     void setTopFocusedDisplay(int displayId);
756 
757     /**
758      * Called when the state of allow-lockscreen-when-on of the display is changed. See
759      * {@link WindowManager.LayoutParams#FLAG_ALLOW_LOCK_WHILE_SCREEN_ON}
760      *
761      * @param displayId The ID of the display.
762      * @param allow Whether the display allows showing lockscreen when it is on.
763      */
setAllowLockscreenWhenOn(int displayId, boolean allow)764     void setAllowLockscreenWhenOn(int displayId, boolean allow);
765 
766     /**
767      * Called when the global wakefulness is becoming awake.
768      *
769      * @param reason One of PowerManager.WAKE_REASON_*, detailing the reason for the change.
770      */
startedWakingUpGlobal(@owerManager.WakeReason int reason)771     void startedWakingUpGlobal(@PowerManager.WakeReason int reason);
772 
773     /**
774      * Called when the global wakefulness has finished becoming awake.
775      *
776      * @param reason One of PowerManager.WAKE_REASON_*, detailing the reason for the change.
777      */
finishedWakingUpGlobal(@owerManager.WakeReason int reason)778     void finishedWakingUpGlobal(@PowerManager.WakeReason int reason);
779 
780     /**
781      * Called when the global wakefulness has started going to sleep.
782      *
783      * @param reason One of PowerManager.WAKE_REASON_*, detailing the reason for the change.
784      */
startedGoingToSleepGlobal(@owerManager.GoToSleepReason int reason)785     void startedGoingToSleepGlobal(@PowerManager.GoToSleepReason int reason);
786 
787     /**
788      * Called when the global wakefulness has finished going to sleep.
789      *
790      * @param reason One of PowerManager.WAKE_REASON_*, detailing the reason for the change.
791      */
finishedGoingToSleepGlobal(@owerManager.GoToSleepReason int reason)792     void finishedGoingToSleepGlobal(@PowerManager.GoToSleepReason int reason);
793 
794     /**
795      * Called when the device has started waking up.
796      *
797      * @param displayGroupId The id of the display group that has started waking up. This will often
798      *                       be {@link Display#DEFAULT_DISPLAY_GROUP}, but it is possible for other
799      *                       display groups to exist, for example when there is a
800      *                       {@link VirtualDevice} with one or more {@link VirtualDisplay}s.
801      * @param pmWakeReason One of PowerManager.WAKE_REASON_*, detailing the specific reason this
802      *                     display group is waking up, such as WAKE_REASON_POWER_BUTTON or
803      *                     WAKE_REASON_GESTURE.
804      */
startedWakingUp(int displayGroupId, @PowerManager.WakeReason int pmWakeReason)805     void startedWakingUp(int displayGroupId, @PowerManager.WakeReason int pmWakeReason);
806 
807     /**
808      * Called when the device has finished waking up.
809      *
810      * @param displayGroupId The id of the display group that has finished waking. This will often
811      *                       be {@link Display#DEFAULT_DISPLAY_GROUP}, but it is possible for other
812      *                       display groups to exist, for example when there is a
813      *                       {@link VirtualDevice} with one or more {@link VirtualDisplay}s.
814      * @param pmWakeReason One of PowerManager.WAKE_REASON_*, detailing the specific reason this
815      *                     display group is waking up, such as WAKE_REASON_POWER_BUTTON or
816      *                     WAKE_REASON_GESTURE.
817      */
finishedWakingUp(int displayGroupId, @PowerManager.WakeReason int pmWakeReason)818     void finishedWakingUp(int displayGroupId, @PowerManager.WakeReason int pmWakeReason);
819 
820     /**
821      * Called when the device has started going to sleep.
822      *
823      * @param displayGroupId The id of the display group that has started going to sleep. This
824      *                       will often be {@link Display#DEFAULT_DISPLAY_GROUP}, but it is
825      *                       possible for other display groups to exist, for example when there is a
826      *                       {@link VirtualDevice} with one or more {@link VirtualDisplay}s.
827      * @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the specific reason
828      *                      this display group is going to sleep, such as
829      *                      GO_TO_SLEEP_REASON_POWER_BUTTON or GO_TO_SLEEP_REASON_TIMEOUT.
830      */
startedGoingToSleep(int displayGroupId, @PowerManager.GoToSleepReason int pmSleepReason)831     void startedGoingToSleep(int displayGroupId, @PowerManager.GoToSleepReason int pmSleepReason);
832 
833     /**
834      * Called when the device has finished going to sleep.
835      *
836      * @param displayGroupId The id of the display group that has finished going to sleep. This
837      *                       will often be {@link Display#DEFAULT_DISPLAY_GROUP}, but it is
838      *                       possible for other display groups to exist, for example when there is a
839      *                       {@link VirtualDevice} with one or more {@link VirtualDisplay}s.
840      * @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the specific reason
841      *                      we're going to sleep, such as GO_TO_SLEEP_REASON_POWER_BUTTON or
842      *                      GO_TO_SLEEP_REASON_TIMEOUT.
843      */
finishedGoingToSleep(int displayGroupId, @PowerManager.GoToSleepReason int pmSleepReason)844     void finishedGoingToSleep(int displayGroupId, @PowerManager.GoToSleepReason int pmSleepReason);
845 
846     /**
847      * Called when the display is about to turn on to show content.
848      * When waking up, this method will be called once after the call to wakingUp().
849      * When dozing, the method will be called sometime after the call to goingToSleep() and
850      * may be called repeatedly in the case where the screen is pulsing on and off.
851      *
852      * Must call back on the listener to tell it when the higher-level system
853      * is ready for the screen to go on (i.e. the lock screen is shown).
854      */
screenTurningOn(int displayId, ScreenOnListener screenOnListener)855     public void screenTurningOn(int displayId, ScreenOnListener screenOnListener);
856 
857     /**
858      * Called when the display has actually turned on, i.e. the display power state has been set to
859      * ON and the screen is unblocked.
860      */
screenTurnedOn(int displayId)861     public void screenTurnedOn(int displayId);
862 
863     /**
864      * Called when the display would like to be turned off. This gives policy a chance to do some
865      * things before the display power state is actually changed to off.
866      *
867      * @param screenOffListener Must be called to tell that the display power state can actually be
868      *                          changed now after policy has done its work.
869      */
screenTurningOff(int displayId, ScreenOffListener screenOffListener)870     public void screenTurningOff(int displayId, ScreenOffListener screenOffListener);
871 
872     /**
873      * Called when the display has turned off.
874      * @param displayId The display to apply to.
875      * @param isSwappingDisplay Whether the display is swapping to another physical display.
876      */
screenTurnedOff(int displayId, boolean isSwappingDisplay)877     void screenTurnedOff(int displayId, boolean isSwappingDisplay);
878 
879     public interface ScreenOnListener {
onScreenOn()880         void onScreenOn();
881     }
882 
883     /**
884      * See {@link #screenTurnedOff}
885      */
886     public interface ScreenOffListener {
onScreenOff()887         void onScreenOff();
888     }
889 
890     /**
891      * Return whether the default display is on and not blocked by a black surface.
892      */
isScreenOn()893     public boolean isScreenOn();
894 
895     /**
896      * @param ignoreScreenOn {@code true} if screen state should be ignored.
897      * @return whether the device is currently allowed to animate.
898      *
899      * Note: this can be true even if it is not appropriate to animate for reasons that are outside
900      *       of the policy's authority.
901      */
okToAnimate(boolean ignoreScreenOn)902     boolean okToAnimate(boolean ignoreScreenOn);
903 
904     /**
905      * Tell the policy that the lid switch has changed state.
906      * @param whenNanos The time when the change occurred in uptime nanoseconds.
907      * @param lidOpen True if the lid is now open.
908      */
notifyLidSwitchChanged(long whenNanos, boolean lidOpen)909     public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
910 
911     /**
912      * Tell the policy that the camera lens has been covered or uncovered.
913      * @param whenNanos The time when the change occurred in uptime nanoseconds.
914      * @param lensCovered True if the lens is covered.
915      */
notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered)916     public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered);
917 
918     /**
919      * Tell the policy if anyone is requesting that keyguard not come on.
920      *
921      * @param enabled Whether keyguard can be on or not.  does not actually
922      * turn it on, unless it was previously disabled with this function.
923      *
924      * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard()
925      * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard()
926      */
927     @SuppressWarnings("javadoc")
enableKeyguard(boolean enabled)928     public void enableKeyguard(boolean enabled);
929 
930     /**
931      * Callback used by {@link #exitKeyguardSecurely}
932      */
933     interface OnKeyguardExitResult {
onKeyguardExitResult(boolean success)934         void onKeyguardExitResult(boolean success);
935     }
936 
937     /**
938      * Tell the policy if anyone is requesting the keyguard to exit securely
939      * (this would be called after the keyguard was disabled)
940      * @param callback Callback to send the result back.
941      * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)
942      */
943     @SuppressWarnings("javadoc")
exitKeyguardSecurely(OnKeyguardExitResult callback)944     void exitKeyguardSecurely(OnKeyguardExitResult callback);
945 
946     /**
947      * isKeyguardLocked
948      *
949      * Return whether the keyguard is currently locked.
950      *
951      * @return true if in keyguard is locked.
952      */
isKeyguardLocked()953     public boolean isKeyguardLocked();
954 
955     /**
956      * isKeyguardSecure
957      *
958      * Return whether the keyguard requires a password to unlock.
959      * @param userId
960      *
961      * @return true if in keyguard is secure.
962      */
isKeyguardSecure(int userId)963     public boolean isKeyguardSecure(int userId);
964 
965     /**
966      * Return whether the keyguard is currently occluded.
967      *
968      * @return true if in keyguard is occluded, false otherwise
969      */
isKeyguardOccluded()970     public boolean isKeyguardOccluded();
971 
972     /**
973      * Return whether the keyguard is unoccluding.
974      * @return {@code true} if the keyguard is unoccluding.
975      */
isKeyguardUnoccluding()976     default boolean isKeyguardUnoccluding() {
977         return false;
978     }
979 
980     /**
981      * @return true if in keyguard is on.
982      */
isKeyguardShowing()983     boolean isKeyguardShowing();
984 
985     /**
986      * @return true if in keyguard is on and not occluded.
987      */
isKeyguardShowingAndNotOccluded()988     public boolean isKeyguardShowingAndNotOccluded();
989 
990     /**
991      * @return whether Keyguard is in trusted state and can be dismissed without credentials
992      */
isKeyguardTrustedLw()993     public boolean isKeyguardTrustedLw();
994 
995     /**
996      * inKeyguardRestrictedKeyInputMode
997      *
998      * If keyguard screen is showing or in restricted key input mode (i.e. in
999      * keyguard password emergency screen). When in such mode, certain keys,
1000      * such as the Home key and the right soft keys, don't work.
1001      *
1002      * @return true if in keyguard restricted input mode.
1003      */
inKeyguardRestrictedKeyInputMode()1004     public boolean inKeyguardRestrictedKeyInputMode();
1005 
1006     /**
1007      * Ask the policy to dismiss the keyguard, if it is currently shown.
1008      *
1009      * @param callback Callback to be informed about the result.
1010      * @param message A message that should be displayed in the keyguard.
1011      */
dismissKeyguardLw(@ullable IKeyguardDismissCallback callback, CharSequence message)1012     public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback,
1013             CharSequence message);
1014 
1015     /**
1016      * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method
1017      * returns true as soon as we know that Keyguard is disabled.
1018      *
1019      * @return true if the keyguard has drawn.
1020      */
isKeyguardDrawnLw()1021     public boolean isKeyguardDrawnLw();
1022 
1023     /**
1024      * Called when the system is mostly done booting to set whether
1025      * the system should go into safe mode.
1026      */
setSafeMode(boolean safeMode)1027     public void setSafeMode(boolean safeMode);
1028 
1029     /**
1030      * Called when the system is mostly done booting.
1031      */
systemReady()1032     public void systemReady();
1033 
1034     /**
1035      * Called when the system is done booting to the point where the
1036      * user can start interacting with it.
1037      */
systemBooted()1038     public void systemBooted();
1039 
1040     /**
1041      * Show boot time message to the user.
1042      */
showBootMessage(final CharSequence msg, final boolean always)1043     public void showBootMessage(final CharSequence msg, final boolean always);
1044 
1045     /**
1046      * Hide the UI for showing boot messages, never to be displayed again.
1047      */
hideBootMessages()1048     public void hideBootMessages();
1049 
1050     /**
1051      * Called when userActivity is signalled in the power manager.
1052      * This is safe to call from any thread, with any window manager locks held or not.
1053      */
userActivity(int displayGroupId, int event)1054     void userActivity(int displayGroupId, int event);
1055 
1056     /**
1057      * Called when we have finished booting and can now display the home
1058      * screen to the user.  This will happen after systemReady(), and at
1059      * this point the display is active.
1060      */
enableScreenAfterBoot()1061     public void enableScreenAfterBoot();
1062 
1063     /**
1064      * Call from application to perform haptic feedback on its window.
1065      */
performHapticFeedback(int uid, String packageName, int effectId, boolean always, String reason)1066     public boolean performHapticFeedback(int uid, String packageName, int effectId,
1067             boolean always, String reason);
1068 
1069     /**
1070      * Called when we have started keeping the screen on because a window
1071      * requesting this has become visible.
1072      */
keepScreenOnStartedLw()1073     public void keepScreenOnStartedLw();
1074 
1075     /**
1076      * Called when we have stopped keeping the screen on because the last window
1077      * requesting this is no longer visible.
1078      */
keepScreenOnStoppedLw()1079     public void keepScreenOnStoppedLw();
1080 
1081     /**
1082      * Called by System UI to notify of changes to the visibility of Recents.
1083      */
setRecentsVisibilityLw(boolean visible)1084     public void setRecentsVisibilityLw(boolean visible);
1085 
1086     /**
1087      * Called by System UI to notify of changes to the visibility of PIP.
1088      */
setPipVisibilityLw(boolean visible)1089     void setPipVisibilityLw(boolean visible);
1090 
1091     /**
1092      * Called by System UI to enable or disable haptic feedback on the navigation bar buttons.
1093      */
setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled)1094     void setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled);
1095 
1096     /**
1097      * Specifies whether there is an on-screen navigation bar separate from the status bar.
1098      */
hasNavigationBar()1099     public boolean hasNavigationBar();
1100 
1101     /**
1102      * Lock the device now.
1103      */
lockNow(Bundle options)1104     public void lockNow(Bundle options);
1105 
1106     /**
1107      * An internal callback (from InputMethodManagerService) to notify a state change regarding
1108      * whether the back key should dismiss the software keyboard (IME) or not.
1109      *
1110      * @param newValue {@code true} if the software keyboard is shown and the back key is expected
1111      *                 to dismiss the software keyboard.
1112      * @hide
1113      */
setDismissImeOnBackKeyPressed(boolean newValue)1114     default void setDismissImeOnBackKeyPressed(boolean newValue) {
1115         // Default implementation does nothing.
1116     }
1117 
1118     /**
1119      * Show the recents task list app.
1120      * @hide
1121      */
showRecentApps()1122     public void showRecentApps();
1123 
1124     /**
1125      * Show the global actions dialog.
1126      * @hide
1127      */
showGlobalActions()1128     public void showGlobalActions();
1129 
1130     /**
1131      * Returns whether the user setup is complete.
1132      */
isUserSetupComplete()1133     boolean isUserSetupComplete();
1134 
1135     /**
1136      * Returns the current UI mode.
1137      */
getUiMode()1138     int getUiMode();
1139 
1140     /**
1141      * Called when the current user changes. Guaranteed to be called before the broadcast
1142      * of the new user id is made to all listeners.
1143      *
1144      * @param newUserId The id of the incoming user.
1145      */
setCurrentUserLw(int newUserId)1146     public void setCurrentUserLw(int newUserId);
1147 
1148     /**
1149      * For a given user-switch operation, this will be called once with switching=true before the
1150      * user-switch and once with switching=false afterwards (or if the user-switch was cancelled).
1151      * This gives the policy a chance to alter its behavior for the duration of a user-switch.
1152      *
1153      * @param switching true if a user-switch is in progress
1154      */
setSwitchingUser(boolean switching)1155     void setSwitchingUser(boolean switching);
1156 
1157     /**
1158      * Print the WindowManagerPolicy's state into the given stream.
1159      *
1160      * @param prefix Text to print at the front of each line.
1161      * @param writer The PrintWriter to which you should dump your state.  This will be
1162      * closed for you after you return.
1163      * @param args additional arguments to the dump request.
1164      */
dump(String prefix, PrintWriter writer, String[] args)1165     public void dump(String prefix, PrintWriter writer, String[] args);
1166 
1167     /**
1168      * Write the WindowManagerPolicy's state into the protocol buffer.
1169      * The message is described in {@link com.android.server.wm.WindowManagerPolicyProto}
1170      *
1171      * @param proto The protocol buffer output stream to write to.
1172      */
dumpDebug(ProtoOutputStream proto, long fieldId)1173     void dumpDebug(ProtoOutputStream proto, long fieldId);
1174 
1175     /**
1176      * Notifies the keyguard to start fading out.
1177      *  @param startTime the start time of the animation in uptime milliseconds
1178      *
1179      */
startKeyguardExitAnimation(long startTime)1180     void startKeyguardExitAnimation(long startTime);
1181 
1182     /**
1183      * Called when System UI has been started.
1184      */
onSystemUiStarted()1185     void onSystemUiStarted();
1186 
1187     /**
1188      * Checks whether the policy is ready for dismissing the boot animation and completing the boot.
1189      *
1190      * @return true if ready; false otherwise.
1191      */
canDismissBootAnimation()1192     boolean canDismissBootAnimation();
1193 
1194     /**
1195      * Convert the user rotation mode to a human readable format.
1196      */
userRotationModeToString(int mode)1197     static String userRotationModeToString(int mode) {
1198         switch(mode) {
1199             case USER_ROTATION_FREE:
1200                 return "USER_ROTATION_FREE";
1201             case USER_ROTATION_LOCKED:
1202                 return "USER_ROTATION_LOCKED";
1203             default:
1204                 return Integer.toString(mode);
1205         }
1206     }
1207 
1208     /**
1209      * Registers an IDisplayFoldListener.
1210      */
registerDisplayFoldListener(IDisplayFoldListener listener)1211     default void registerDisplayFoldListener(IDisplayFoldListener listener) {}
1212 
1213     /**
1214      * Unregisters an IDisplayFoldListener.
1215      */
unregisterDisplayFoldListener(IDisplayFoldListener listener)1216     default void unregisterDisplayFoldListener(IDisplayFoldListener listener) {}
1217 
1218     /**
1219      * Overrides the folded area.
1220      *
1221      * @param area the overriding folded area or an empty {@code Rect} to clear the override.
1222      */
setOverrideFoldedArea(@onNull Rect area)1223     default void setOverrideFoldedArea(@NonNull Rect area) {}
1224 
1225     /**
1226      * Get the display folded area.
1227      */
getFoldedArea()1228     default @NonNull Rect getFoldedArea() {
1229         return new Rect();
1230     }
1231 
1232     /**
1233      * A new window on default display has been focused.
1234      */
onDefaultDisplayFocusChangedLw(WindowState newFocus)1235     default void onDefaultDisplayFocusChangedLw(WindowState newFocus) {}
1236 
1237     /**
1238      * Returns {@code true} if the key will be handled globally and not forwarded to all apps.
1239      *
1240      * @param keyCode the key code to check
1241      * @return {@code true} if the key will be handled globally.
1242      */
isGlobalKey(int keyCode)1243     boolean isGlobalKey(int keyCode);
1244 }
1245