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