2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.server.policy;
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_OVERLAY;
22 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL;
23 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
24 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
25 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
26 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
27 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
28 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
29 import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
30 import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
31 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
32 import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
33 import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
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_PHONE;
42 import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
43 import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
44 import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
45 import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
46 import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
47 import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
48 import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
49 import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
50 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
51 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
52 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
53 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
54 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
55 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
56 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
57 import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
58 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
59 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING;
60 import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
61 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
62 import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
64 import static java.lang.annotation.RetentionPolicy.SOURCE;
66 import android.annotation.IntDef;
67 import android.annotation.NonNull;
68 import android.annotation.Nullable;
69 import android.app.WindowConfiguration;
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.Looper;
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.InputEventReceiver;
85 import android.view.KeyEvent;
86 import android.view.WindowManager;
87 import android.view.WindowManagerGlobal;
88 import android.view.WindowManagerPolicyConstants;
89 import android.view.animation.Animation;
91 import com.android.internal.policy.IKeyguardDismissCallback;
92 import com.android.internal.policy.IShortcutService;
93 import com.android.server.wm.DisplayRotation;
94 import com.android.server.wm.WindowFrames;
96 import java.io.PrintWriter;
97 import java.lang.annotation.Retention;
98 import java.lang.annotation.RetentionPolicy;
101 * This interface supplies all UI-specific behavior of the window manager. An
102 * instance of it is created by the window manager when it starts up, and allows
103 * customization of window layering, special window types, key dispatching, and
106 * <p>Because this provides deep interaction with the system window manager,
107 * specific methods on this interface can be called from a variety of contexts
108 * with various restrictions on what they can do. These are encoded through
109 * a suffixes at the end of a method encoding the thread the method is called
110 * from and any locks that are held when it is being called; if no suffix
111 * is attached to a method, then it is not called with any locks and may be
112 * called from the main window manager thread or another thread calling into
113 * the window manager.
115 * <p>The current suffixes are:
118 * <dt> Ti <dd> Called from the input thread. This is the thread that
119 * collects pending input events and dispatches them to the appropriate window.
120 * It may block waiting for events to be processed, so that the input stream is
121 * properly serialized.
122 * <dt> Tq <dd> Called from the low-level input queue thread. This is the
123 * thread that reads events out of the raw input devices and places them
124 * into the global input queue that is read by the <var>Ti</var> thread.
125 * This thread should not block for a long period of time on anything but the
127 * <dt> Lw <dd> Called with the main window manager lock held. Because the
128 * window manager is a very low-level system service, there are few other
129 * system services you can call with this lock held. It is explicitly okay to
130 * make calls into the package manager and power manager; it is explicitly not
131 * okay to make calls into the activity manager or most other services. Note that
132 * {@link android.content.Context#checkPermission(String, int, int)} and
133 * variations require calling into the activity manager.
134 * <dt> Li <dd> Called with the input thread lock held. This lock can be
135 * acquired by the window manager while it holds the window lock, so this is
136 * even more restrictive than <var>Lw</var>.
139 public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
141 @IntDef({NAV_BAR_LEFT, NAV_BAR_RIGHT, NAV_BAR_BOTTOM})
142 @interface NavigationBarPosition {}
145 * Pass this event to the user / app. To be returned from
146 * {@link #interceptKeyBeforeQueueing}.
148 int ACTION_PASS_TO_USER = 0x00000001;
149 /** Layout state may have changed (so another layout will be performed) */
150 int FINISH_LAYOUT_REDO_LAYOUT = 0x0001;
151 /** Configuration state may have changed */
152 int FINISH_LAYOUT_REDO_CONFIG = 0x0002;
153 /** Wallpaper may need to move */
154 int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004;
155 /** Need to recompute animations */
156 int FINISH_LAYOUT_REDO_ANIM = 0x0008;
157 /** Layer for the screen off animation */
158 int COLOR_FADE_LAYER = 0x40000001;
161 * Register shortcuts for window manager to dispatch.
162 * Shortcut code is packed as (metaState << Integer.SIZE) | keyCode
165 void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)
166 throws RemoteException;
169 * Called when the Keyguard occluded state changed.
170 * @param occluded Whether Keyguard is currently occluded or not.
172 void onKeyguardOccludedChangedLw(boolean occluded);
175 * Interface to the Window Manager state associated with a particular
176 * window. You can hold on to an instance of this interface from the call
177 * to prepareAddWindow() until removeWindow().
179 public interface WindowState {
181 * Return the uid of the app that owns this window.
186 * Return the package name of the app that owns this window.
188 String getOwningPackage();
191 * Perform standard frame computation. The result can be obtained with
192 * getFrame() if so desired. Must be called with the window manager
196 public void computeFrameLw();
199 * Retrieve the current frame of the window that has been assigned by
200 * the window manager. Must be called with the window manager lock held.
202 * @return Rect The rectangle holding the window frame.
204 public Rect getFrameLw();
207 * Retrieve the frame of the display that this window was last
208 * laid out in. Must be called with the
209 * window manager lock held.
211 * @return Rect The rectangle holding the display frame.
213 public Rect getDisplayFrameLw();
216 * Retrieve the frame of the area inside the overscan region of the
217 * display that this window was last laid out in. Must be called with the
218 * window manager lock held.
220 * @return Rect The rectangle holding the display overscan frame.
222 public Rect getOverscanFrameLw();
225 * Retrieve the frame of the content area that this window was last
226 * laid out in. This is the area in which the content of the window
227 * should be placed. It will be smaller than the display frame to
228 * account for screen decorations such as a status bar or soft
229 * keyboard. Must be called with the
230 * window manager lock held.
232 * @return Rect The rectangle holding the content frame.
234 public Rect getContentFrameLw();
237 * Retrieve the frame of the visible area that this window was last
238 * laid out in. This is the area of the screen in which the window
239 * will actually be fully visible. It will be smaller than the
240 * content frame to account for transient UI elements blocking it
241 * such as an input method's candidates UI. Must be called with the
242 * window manager lock held.
244 * @return Rect The rectangle holding the visible frame.
246 public Rect getVisibleFrameLw();
249 * Returns true if this window is waiting to receive its given
250 * internal insets from the client app, and so should not impact the
251 * layout of other windows.
253 public boolean getGivenInsetsPendingLw();
256 * Retrieve the insets given by this window's client for the content
257 * area of windows behind it. Must be called with the
258 * window manager lock held.
260 * @return Rect The left, top, right, and bottom insets, relative
261 * to the window's frame, of the actual contents.
263 public Rect getGivenContentInsetsLw();
266 * Retrieve the insets given by this window's client for the visible
267 * area of windows behind it. Must be called with the
268 * window manager lock held.
270 * @return Rect The left, top, right, and bottom insets, relative
271 * to the window's frame, of the actual visible area.
273 public Rect getGivenVisibleInsetsLw();
276 * Retrieve the current LayoutParams of the window.
278 * @return WindowManager.LayoutParams The window's internal LayoutParams
281 public WindowManager.LayoutParams getAttrs();
284 * Return whether this window needs the menu key shown. Must be called
285 * with window lock held, because it may need to traverse down through
286 * window list to determine the result.
287 * @param bottom The bottom-most window to consider when determining this.
289 public boolean getNeedsMenuLw(WindowState bottom);
292 * Retrieve the current system UI visibility flags associated with
295 public int getSystemUiVisibility();
298 * Get the layer at which this window's surface will be Z-ordered.
300 public int getSurfaceLayer();
303 * Retrieve the type of the top-level window.
305 * @return the base type of the parent window if attached or its own type otherwise
307 public int getBaseType();
310 * Return the token for the application (actually activity) that owns
311 * this window. May return null for system windows.
313 * @return An IApplicationToken identifying the owning activity.
315 public IApplicationToken getAppToken();
318 * Return true if this window is participating in voice interaction.
320 public boolean isVoiceInteraction();
323 * Return true if, at any point, the application token associated with
324 * this window has actually displayed any windows. This is most useful
325 * with the "starting up" window to determine if any windows were
326 * displayed when it is closed.
328 * @return Returns true if one or more windows have been displayed,
331 public boolean hasAppShownWindows();
334 * Is this window visible? It is not visible if there is no
335 * surface, or we are in the process of running an exit animation
336 * that will remove the surface.
338 boolean isVisibleLw();
341 * Is this window currently visible to the user on-screen? It is
342 * displayed either if it is visible or it is currently running an
343 * animation before no longer being visible. Must be called with the
344 * window manager lock held.
346 boolean isDisplayedLw();
349 * Return true if this window (or a window it is attached to, but not
350 * considering its app token) is currently animating.
352 boolean isAnimatingLw();
355 * @return Whether the window can affect SystemUI flags, meaning that SystemUI (system bars,
356 * for example) will be affected by the flags specified in this window. This is the
357 * case when the surface is on screen but not exiting.
359 boolean canAffectSystemUiFlags();
362 * Is this window considered to be gone for purposes of layout?
364 boolean isGoneForLayoutLw();
367 * Returns true if the window has a surface that it has drawn a
368 * complete UI in to. Note that this is different from {@link #hasDrawnLw()}
369 * in that it also returns true if the window is READY_TO_SHOW, but was not yet
370 * promoted to HAS_DRAWN.
375 * Returns true if this window has been shown on screen at some time in
376 * the past. Must be called with the window manager lock held.
378 * @deprecated Use {@link #isDrawnLw} or any of the other drawn/visibility methods.
381 public boolean hasDrawnLw();
384 * Can be called by the policy to force a window to be hidden,
385 * regardless of whether the client or window manager would like
386 * it shown. Must be called with the window manager lock held.
387 * Returns true if {@link #showLw} was last called for the window.
389 public boolean hideLw(boolean doAnimation);
392 * Can be called to undo the effect of {@link #hideLw}, allowing a
393 * window to be shown as long as the window manager and client would
394 * also like it to be shown. Must be called with the window manager
396 * Returns true if {@link #hideLw} was last called for the window.
398 public boolean showLw(boolean doAnimation);
401 * Check whether the process hosting this window is currently alive.
403 public boolean isAlive();
406 * Check if window is on {@link Display#DEFAULT_DISPLAY}.
407 * @return true if window is on default display.
409 public boolean isDefaultDisplay();
412 * Check whether the window is currently dimming.
414 public boolean isDimming();
417 * Returns true if the window is letterboxed for the display cutout.
419 default boolean isLetterboxedForDisplayCutoutLw() {
424 * Returns true if the window has a letterbox and any part of that letterbox overlaps with
425 * the given {@code rect}.
427 default boolean isLetterboxedOverlappingWith(Rect rect) {
431 /** @return the current windowing mode of this window. */
432 int getWindowingMode();
435 * Returns the {@link WindowConfiguration.ActivityType} associated with the configuration
438 default int getActivityType() {
439 return WindowConfiguration.WINDOWING_MODE_UNDEFINED;
443 * Returns true if the window is current in multi-windowing mode. i.e. it shares the
444 * screen with other application windows.
446 boolean inMultiWindowMode();
448 public int getRotationAnimationHint();
450 public boolean isInputMethodWindow();
452 public boolean isInputMethodTarget();
454 public int getDisplayId();
457 * Returns true if the window owner can add internal system windows.
458 * That is, they have {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}.
460 default boolean canAddInternalSystemWindow() {
465 * Returns true if the window owner has the permission to acquire a sleep token when it's
466 * visible. That is, they have the permission {@link Manifest.permission#DEVICE_POWER}.
468 boolean canAcquireSleepToken();
470 /** @return true if this window desires key events. */
471 boolean canReceiveKeys();
473 /** @return true if the window can show over keyguard. */
474 boolean canShowWhenLocked();
477 * Writes {@link com.android.server.wm.IdentifierProto} to stream.
479 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId);
482 * @return The {@link WindowFrames} associated with this {@link WindowState}
484 WindowFrames getWindowFrames();
488 * Representation of a input consumer that the policy has added to the
489 * window manager to consume input events going to windows below it.
491 public interface InputConsumer {
493 * Remove the input consumer from the window manager.
499 * Holds the contents of a starting window. {@link #addSplashScreen} needs to wrap the
500 * contents of the starting window into an class implementing this interface, which then will be
501 * held by WM and released with {@link #remove} when no longer needed.
503 interface StartingSurface {
506 * Removes the starting window surface. Do not hold the window manager lock when calling
513 * Interface for calling back in to the window manager that is private
514 * between it and the policy.
516 public interface WindowManagerFuncs {
517 public static final int LID_ABSENT = -1;
518 public static final int LID_CLOSED = 0;
519 public static final int LID_OPEN = 1;
521 public static final int LID_BEHAVIOR_NONE = 0;
522 public static final int LID_BEHAVIOR_SLEEP = 1;
523 public static final int LID_BEHAVIOR_LOCK = 2;
525 public static final int CAMERA_LENS_COVER_ABSENT = -1;
526 public static final int CAMERA_LENS_UNCOVERED = 0;
527 public static final int CAMERA_LENS_COVERED = 1;
530 * Add a input consumer which will consume all input events going to any window below it.
532 public InputConsumer createInputConsumer(Looper looper, String name,
533 InputEventReceiver.Factory inputEventReceiverFactory, int displayId);
536 * Returns a code that describes the current state of the lid switch.
538 public int getLidState();
541 * Lock the device now.
543 public void lockDeviceNow();
546 * Returns a code that descripbes whether the camera lens is covered or not.
548 public int getCameraLensCoverState();
551 * Switch the keyboard layout for the given device.
552 * Direction should be +1 or -1 to go to the next or previous keyboard layout.
554 public void switchKeyboardLayout(int deviceId, int direction);
556 public void shutdown(boolean confirm);
557 public void reboot(boolean confirm);
558 public void rebootSafeMode(boolean confirm);
561 * Return the window manager lock needed to correctly call "Lw" methods.
563 public Object getWindowManagerLock();
565 /** Register a system listener for touch events */
566 void registerPointerEventListener(PointerEventListener listener, int displayId);
568 /** Unregister a system listener for touch events */
569 void unregisterPointerEventListener(PointerEventListener listener, int displayId);
572 * Retrieves the {@param outBounds} from the stack matching the {@param windowingMode} and
573 * {@param activityType}.
575 void getStackBounds(int windowingMode, int activityType, Rect outBounds);
578 * @return The currently active input method window.
580 WindowState getInputMethodWindowLw();
583 * Notifies window manager that {@link #isKeyguardTrustedLw} has changed.
585 void notifyKeyguardTrustedChanged();
588 * Notifies the window manager that screen is being turned off.
590 * @param listener callback to call when display can be turned off
592 void screenTurningOff(ScreenOffListener listener);
595 * Convert the lid state to a human readable format.
597 static String lidStateToString(int lid) {
606 return Integer.toString(lid);
611 * Convert the camera lens state to a human readable format.
613 static String cameraLensStateToString(int lens) {
615 case CAMERA_LENS_COVER_ABSENT:
616 return "CAMERA_LENS_COVER_ABSENT";
617 case CAMERA_LENS_UNCOVERED:
618 return "CAMERA_LENS_UNCOVERED";
619 case CAMERA_LENS_COVERED:
620 return "CAMERA_LENS_COVERED";
622 return Integer.toString(lens);
627 * Hint to window manager that the user has started a navigation action that should
628 * abort animations that have no timeout, in case they got stuck.
630 void triggerAnimationFailsafe();
633 * The keyguard showing state has changed
635 void onKeyguardShowingAndNotOccludedChanged();
638 * Notifies window manager that power key is being pressed.
640 void onPowerKeyDown(boolean isScreenOn);
643 * Notifies window manager that user is switched.
645 void onUserSwitched();
648 * Hint to window manager that the user is interacting with a display that should be treated
649 * as the top display.
651 void moveDisplayToTop(int displayId);
655 * Provides the rotation of a device.
657 * @see com.android.server.policy.WindowOrientationListener
659 public interface RotationSource {
660 int getProposedRotation();
662 void setCurrentRotation(int rotation);
666 * Interface to get public information of a display content.
668 public interface DisplayContentInfo {
669 DisplayRotation getDisplayRotation();
670 Display getDisplay();
673 /** Window has been added to the screen. */
674 public static final int TRANSIT_ENTER = 1;
675 /** Window has been removed from the screen. */
676 public static final int TRANSIT_EXIT = 2;
677 /** Window has been made visible. */
678 public static final int TRANSIT_SHOW = 3;
679 /** Window has been made invisible.
680 * TODO: Consider removal as this is unused. */
681 public static final int TRANSIT_HIDE = 4;
682 /** The "application starting" preview window is no longer needed, and will
683 * animate away to show the real window. */
684 public static final int TRANSIT_PREVIEW_DONE = 5;
686 // NOTE: screen off reasons are in order of significance, with more
687 // important ones lower than less important ones.
690 @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED})
691 @Retention(RetentionPolicy.SOURCE)
692 public @interface UserRotationMode {}
694 /** When not otherwise specified by the activity's screenOrientation, rotation should be
695 * determined by the system (that is, using sensors). */
696 public final int USER_ROTATION_FREE = 0;
697 /** When not otherwise specified by the activity's screenOrientation, rotation is set by
699 public final int USER_ROTATION_LOCKED = 1;
702 * Set the default display content to provide basic functions for the policy.
704 public void setDefaultDisplay(DisplayContentInfo displayContentInfo);
707 * Perform initialization of the policy.
709 * @param context The system context we are running in.
711 public void init(Context context, IWindowManager windowManager,
712 WindowManagerFuncs windowManagerFuncs);
715 * Check permissions when adding a window.
717 * @param attrs The window's LayoutParams.
718 * @param outAppOp First element will be filled with the app op corresponding to
719 * this window, or OP_NONE.
721 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed;
722 * else an error code, usually
723 * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add.
725 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp);
728 * Check permissions when adding a window.
730 * @param attrs The window's LayoutParams.
732 * @return True if the window may only be shown to the current user, false if the window can
733 * be shown on all users' windows.
735 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs);
738 * After the window manager has computed the current configuration based
739 * on its knowledge of the display and input devices, it gives the policy
740 * a chance to adjust the information contained in it. If you want to
741 * leave it as-is, simply do nothing.
743 * <p>This method may be called by any thread in the window manager, but
744 * no internal locks in the window manager will be held.
746 * @param config The Configuration being computed, for you to change as
748 * @param keyboardPresence Flags that indicate whether internal or external
749 * keyboards are present.
750 * @param navigationPresence Flags that indicate whether internal or external
751 * navigation devices are present.
753 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
754 int navigationPresence);
757 * Returns the layer assignment for the window state. Allows you to control how different
758 * kinds of windows are ordered on-screen.
760 * @param win The window state
761 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
763 default int getWindowLayerLw(WindowState win) {
764 return getWindowLayerFromTypeLw(win.getBaseType(), win.canAddInternalSystemWindow());
768 * Returns the layer assignment for the window type. Allows you to control how different
769 * kinds of windows are ordered on-screen.
771 * @param type The type of window being assigned.
772 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
774 default int getWindowLayerFromTypeLw(int type) {
775 if (isSystemAlertWindowType(type)) {
776 throw new IllegalArgumentException("Use getWindowLayerFromTypeLw() or"
777 + " getWindowLayerLw() for alert window types");
779 return getWindowLayerFromTypeLw(type, false /* canAddInternalSystemWindow */);
783 * Returns the layer assignment for the window type. Allows you to control how different
784 * kinds of windows are ordered on-screen.
786 * @param type The type of window being assigned.
787 * @param canAddInternalSystemWindow If the owner window associated with the type we are
788 * evaluating can add internal system windows. I.e they have
789 * {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}. If true, alert window
790 * types {@link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)}
791 * can be assigned layers greater than the layer for
792 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} Else, their
793 * layers would be lesser.
794 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
796 default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow) {
797 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
798 return APPLICATION_LAYER;
803 // wallpaper is at the bottom, though the window manager may move it.
805 case TYPE_PRESENTATION:
806 case TYPE_PRIVATE_PRESENTATION:
807 return APPLICATION_LAYER;
808 case TYPE_DOCK_DIVIDER:
809 return APPLICATION_LAYER;
811 return APPLICATION_LAYER;
814 case TYPE_SEARCH_BAR:
815 case TYPE_VOICE_INTERACTION_STARTING:
817 case TYPE_VOICE_INTERACTION:
818 // voice interaction layer is almost immediately above apps.
820 case TYPE_INPUT_CONSUMER:
822 case TYPE_SYSTEM_DIALOG:
825 // toasts and the plugged-in battery thing
827 case TYPE_PRIORITY_PHONE:
828 // SIM errors and unlock. Not sure if this really should be in a high layer.
830 case TYPE_SYSTEM_ALERT:
831 // like the ANR / app crashed dialogs
832 // Type is deprecated for non-system apps. For system apps, this type should be
833 // in a higher layer than TYPE_APPLICATION_OVERLAY.
834 return canAddInternalSystemWindow ? 13 : 10;
835 case TYPE_APPLICATION_OVERLAY:
838 // used for Dreams (screensavers with TYPE_DREAM windows)
840 case TYPE_INPUT_METHOD:
841 // on-screen keyboards and other such input method user interfaces go here.
843 case TYPE_INPUT_METHOD_DIALOG:
844 // on-screen keyboards and other such input method user interfaces go here.
846 case TYPE_STATUS_BAR:
848 case TYPE_STATUS_BAR_PANEL:
850 case TYPE_STATUS_BAR_SUB_PANEL:
852 case TYPE_KEYGUARD_DIALOG:
854 case TYPE_VOLUME_OVERLAY:
855 // the on-screen volume indicator and controller shown when the user
856 // changes the device volume
858 case TYPE_SYSTEM_OVERLAY:
859 // the on-screen volume indicator and controller shown when the user
860 // changes the device volume
861 return canAddInternalSystemWindow ? 22 : 11;
862 case TYPE_NAVIGATION_BAR:
863 // the navigation bar, if available, shows atop most things
865 case TYPE_NAVIGATION_BAR_PANEL:
866 // some panels (e.g. search) need to show on top of the navigation bar
868 case TYPE_SCREENSHOT:
869 // screenshot selection layer shouldn't go above system error, but it should cover
870 // navigation bars at the very least.
872 case TYPE_SYSTEM_ERROR:
873 // system-level error dialogs
874 return canAddInternalSystemWindow ? 26 : 10;
875 case TYPE_MAGNIFICATION_OVERLAY:
876 // used to highlight the magnified portion of a display
878 case TYPE_DISPLAY_OVERLAY:
879 // used to simulate secondary display devices
882 // the drag layer: input for drag-and-drop is associated with this window,
883 // which sits above all other focusable windows
885 case TYPE_ACCESSIBILITY_OVERLAY:
886 // overlay put by accessibility services to intercept user interaction
888 case TYPE_SECURE_SYSTEM_OVERLAY:
890 case TYPE_BOOT_PROGRESS:
893 // the (mouse) pointer layer
896 Slog.e("WindowManager", "Unknown window type: " + type);
897 return APPLICATION_LAYER;
902 * Return how to Z-order sub-windows in relation to the window they are attached to.
903 * Return positive to have them ordered in front, negative for behind.
905 * @param type The sub-window type code.
907 * @return int Layer in relation to the attached window, where positive is
908 * above and negative is below.
910 default int getSubWindowLayerFromTypeLw(int type) {
912 case TYPE_APPLICATION_PANEL:
913 case TYPE_APPLICATION_ATTACHED_DIALOG:
914 return APPLICATION_PANEL_SUBLAYER;
915 case TYPE_APPLICATION_MEDIA:
916 return APPLICATION_MEDIA_SUBLAYER;
917 case TYPE_APPLICATION_MEDIA_OVERLAY:
918 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
919 case TYPE_APPLICATION_SUB_PANEL:
920 return APPLICATION_SUB_PANEL_SUBLAYER;
921 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
922 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
924 Slog.e("WindowManager", "Unknown sub-window type: " + type);
929 * Get the highest layer (actually one more than) that the wallpaper is
932 public int getMaxWallpaperLayer();
935 * Return whether the given window can become the Keyguard window. Typically returns true for
938 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs);
941 * @return whether {@param win} can be hidden by Keyguard
943 public boolean canBeHiddenByKeyguardLw(WindowState win);
946 * Called when the system would like to show a UI to indicate that an
947 * application is starting. You can use this to add a
948 * APPLICATION_STARTING_TYPE window with the given appToken to the window
949 * manager (using the normal window manager APIs) that will be shown until
950 * the application displays its own window. This is called without the
951 * window manager locked so that you can call back into it.
953 * @param appToken Token of the application being started.
954 * @param packageName The name of the application package being started.
955 * @param theme Resource defining the application's overall visual theme.
956 * @param nonLocalizedLabel The default title label of the application if
957 * no data is found in the resource.
958 * @param labelRes The resource ID the application would like to use as its name.
959 * @param icon The resource ID the application would like to use as its icon.
960 * @param windowFlags Window layout flags.
961 * @param overrideConfig override configuration to consider when generating
962 * context to for resources.
963 * @param displayId Id of the display to show the splash screen at.
965 * @return The starting surface.
968 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme,
969 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
970 int logo, int windowFlags, Configuration overrideConfig, int displayId);
973 * Set or clear a window which can behave as the keyguard.
975 * @param win The window which can behave as the keyguard.
977 void setKeyguardCandidateLw(@Nullable WindowState win);
980 * Create and return an animation to re-display a window that was force hidden by Keyguard.
982 public Animation createHiddenByKeyguardExit(boolean onWallpaper,
983 boolean goingToNotificationShade);
986 * Create and return an animation to let the wallpaper disappear after being shown behind
989 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade);
992 * Called from the input reader thread before a key is enqueued.
994 * <p>There are some actions that need to be handled here because they
995 * affect the power state of the device, for example, the power keys.
996 * Generally, it's best to keep as little as possible in the queue thread
997 * because it's the most fragile.
998 * @param event The key event.
999 * @param policyFlags The policy flags associated with the key.
1001 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
1003 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
1006 * Called from the input reader thread before a motion is enqueued when the device is in a
1007 * non-interactive state.
1009 * <p>There are some actions that need to be handled here because they
1010 * affect the power state of the device, for example, waking on motions.
1011 * Generally, it's best to keep as little as possible in the queue thread
1012 * because it's the most fragile.
1013 * @param displayId The display ID of the motion event.
1014 * @param policyFlags The policy flags associated with the motion.
1016 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
1018 int interceptMotionBeforeQueueingNonInteractive(int displayId, long whenNanos,
1022 * Called from the input dispatcher thread before a key is dispatched to a window.
1024 * <p>Allows you to define
1025 * behavior for keys that can not be overridden by applications.
1026 * This method is called from the input thread, with no locks held.
1028 * @param win The window that currently has focus. This is where the key
1029 * event will normally go.
1030 * @param event The key event.
1031 * @param policyFlags The policy flags associated with the key.
1032 * @return 0 if the key should be dispatched immediately, -1 if the key should
1033 * not be dispatched ever, or a positive value indicating the number of
1034 * milliseconds by which the key dispatch should be delayed before trying
1037 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags);
1040 * Called from the input dispatcher thread when an application did not handle
1041 * a key that was dispatched to it.
1043 * <p>Allows you to define default global behavior for keys that were not handled
1044 * by applications. This method is called from the input thread, with no locks held.
1046 * @param win The window that currently has focus. This is where the key
1047 * event will normally go.
1048 * @param event The key event.
1049 * @param policyFlags The policy flags associated with the key.
1050 * @return Returns an alternate key event to redispatch as a fallback, or null to give up.
1051 * The caller is responsible for recycling the key event.
1053 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags);
1056 * Called when the top focused display is changed.
1058 * @param displayId The ID of the top focused display.
1060 void setTopFocusedDisplay(int displayId);
1063 * Apply the keyguard policy to a specific window.
1065 * @param win The window to apply the keyguard policy.
1066 * @param imeTarget The current IME target window.
1068 void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget);
1071 * Called when the state of allow-lockscreen-when-on of the display is changed. See
1072 * {@link WindowManager.LayoutParams#FLAG_ALLOW_LOCK_WHILE_SCREEN_ON}
1074 * @param displayId The ID of the display.
1075 * @param allow Whether the display allows showing lockscreen when it is on.
1077 void setAllowLockscreenWhenOn(int displayId, boolean allow);
1080 * Called when the device has started waking up.
1082 void startedWakingUp(@OnReason int reason);
1085 * Called when the device has finished waking up.
1087 void finishedWakingUp(@OnReason int reason);
1090 * Called when the device has started going to sleep.
1092 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
1093 * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
1095 public void startedGoingToSleep(int why);
1098 * Called when the device has finished going to sleep.
1100 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
1101 * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
1103 public void finishedGoingToSleep(int why);
1106 * Called when the device is about to turn on the screen to show content.
1107 * When waking up, this method will be called once after the call to wakingUp().
1108 * When dozing, the method will be called sometime after the call to goingToSleep() and
1109 * may be called repeatedly in the case where the screen is pulsing on and off.
1111 * Must call back on the listener to tell it when the higher-level system
1112 * is ready for the screen to go on (i.e. the lock screen is shown).
1114 public void screenTurningOn(ScreenOnListener screenOnListener);
1117 * Called when the device has actually turned on the screen, i.e. the display power state has
1118 * been set to ON and the screen is unblocked.
1120 public void screenTurnedOn();
1123 * Called when the display would like to be turned off. This gives policy a chance to do some
1124 * things before the display power state is actually changed to off.
1126 * @param screenOffListener Must be called to tell that the display power state can actually be
1127 * changed now after policy has done its work.
1129 public void screenTurningOff(ScreenOffListener screenOffListener);
1132 * Called when the device has turned the screen off.
1134 public void screenTurnedOff();
1136 public interface ScreenOnListener {
1141 * See {@link #screenTurnedOff}
1143 public interface ScreenOffListener {
1148 * Return whether the default display is on and not blocked by a black surface.
1150 public boolean isScreenOn();
1153 * @return whether the device is currently allowed to animate.
1155 * Note: this can be true even if it is not appropriate to animate for reasons that are outside
1156 * of the policy's authority.
1158 boolean okToAnimate();
1161 * Tell the policy that the lid switch has changed state.
1162 * @param whenNanos The time when the change occurred in uptime nanoseconds.
1163 * @param lidOpen True if the lid is now open.
1165 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
1168 * Tell the policy that the camera lens has been covered or uncovered.
1169 * @param whenNanos The time when the change occurred in uptime nanoseconds.
1170 * @param lensCovered True if the lens is covered.
1172 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered);
1175 * Tell the policy if anyone is requesting that keyguard not come on.
1177 * @param enabled Whether keyguard can be on or not. does not actually
1178 * turn it on, unless it was previously disabled with this function.
1180 * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard()
1181 * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard()
1183 @SuppressWarnings("javadoc")
1184 public void enableKeyguard(boolean enabled);
1187 * Callback used by {@link #exitKeyguardSecurely}
1189 interface OnKeyguardExitResult {
1190 void onKeyguardExitResult(boolean success);
1194 * Tell the policy if anyone is requesting the keyguard to exit securely
1195 * (this would be called after the keyguard was disabled)
1196 * @param callback Callback to send the result back.
1197 * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)
1199 @SuppressWarnings("javadoc")
1200 void exitKeyguardSecurely(OnKeyguardExitResult callback);
1205 * Return whether the keyguard is currently locked.
1207 * @return true if in keyguard is locked.
1209 public boolean isKeyguardLocked();
1214 * Return whether the keyguard requires a password to unlock.
1217 * @return true if in keyguard is secure.
1219 public boolean isKeyguardSecure(int userId);
1222 * Return whether the keyguard is currently occluded.
1224 * @return true if in keyguard is occluded, false otherwise
1226 public boolean isKeyguardOccluded();
1229 * @return true if in keyguard is on and not occluded.
1231 public boolean isKeyguardShowingAndNotOccluded();
1234 * @return whether Keyguard is in trusted state and can be dismissed without credentials
1236 public boolean isKeyguardTrustedLw();
1239 * inKeyguardRestrictedKeyInputMode
1241 * If keyguard screen is showing or in restricted key input mode (i.e. in
1242 * keyguard password emergency screen). When in such mode, certain keys,
1243 * such as the Home key and the right soft keys, don't work.
1245 * @return true if in keyguard restricted input mode.
1247 public boolean inKeyguardRestrictedKeyInputMode();
1250 * Ask the policy to dismiss the keyguard, if it is currently shown.
1252 * @param callback Callback to be informed about the result.
1253 * @param message A message that should be displayed in the keyguard.
1255 public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback,
1256 CharSequence message);
1259 * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method
1260 * returns true as soon as we know that Keyguard is disabled.
1262 * @return true if the keyguard has drawn.
1264 public boolean isKeyguardDrawnLw();
1267 * Called when the system is mostly done booting to set whether
1268 * the system should go into safe mode.
1270 public void setSafeMode(boolean safeMode);
1273 * Called when the system is mostly done booting.
1275 public void systemReady();
1278 * Called when the system is done booting to the point where the
1279 * user can start interacting with it.
1281 public void systemBooted();
1284 * Show boot time message to the user.
1286 public void showBootMessage(final CharSequence msg, final boolean always);
1289 * Hide the UI for showing boot messages, never to be displayed again.
1291 public void hideBootMessages();
1294 * Called when userActivity is signalled in the power manager.
1295 * This is safe to call from any thread, with any window manager locks held or not.
1297 public void userActivity();
1300 * Called when we have finished booting and can now display the home
1301 * screen to the user. This will happen after systemReady(), and at
1302 * this point the display is active.
1304 public void enableScreenAfterBoot();
1307 * Call from application to perform haptic feedback on its window.
1309 public boolean performHapticFeedback(int uid, String packageName, int effectId,
1310 boolean always, String reason);
1313 * Called when we have started keeping the screen on because a window
1314 * requesting this has become visible.
1316 public void keepScreenOnStartedLw();
1319 * Called when we have stopped keeping the screen on because the last window
1320 * requesting this is no longer visible.
1322 public void keepScreenOnStoppedLw();
1325 * Called by System UI to notify of changes to the visibility of Recents.
1327 public void setRecentsVisibilityLw(boolean visible);
1330 * Called by System UI to notify of changes to the visibility of PIP.
1332 void setPipVisibilityLw(boolean visible);
1335 * Called by System UI to enable or disable haptic feedback on the navigation bar buttons.
1337 void setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled);
1340 * Specifies whether there is an on-screen navigation bar separate from the status bar.
1342 public boolean hasNavigationBar();
1345 * Lock the device now.
1347 public void lockNow(Bundle options);
1350 * An internal callback (from InputMethodManagerService) to notify a state change regarding
1351 * whether the back key should dismiss the software keyboard (IME) or not.
1353 * @param newValue {@code true} if the software keyboard is shown and the back key is expected
1354 * to dismiss the software keyboard.
1357 default void setDismissImeOnBackKeyPressed(boolean newValue) {
1358 // Default implementation does nothing.
1362 * Show the recents task list app.
1365 public void showRecentApps();
1368 * Show the global actions dialog.
1371 public void showGlobalActions();
1374 * Returns whether the user setup is complete.
1376 boolean isUserSetupComplete();
1379 * Returns the current UI mode.
1384 * Called when the current user changes. Guaranteed to be called before the broadcast
1385 * of the new user id is made to all listeners.
1387 * @param newUserId The id of the incoming user.
1389 public void setCurrentUserLw(int newUserId);
1392 * For a given user-switch operation, this will be called once with switching=true before the
1393 * user-switch and once with switching=false afterwards (or if the user-switch was cancelled).
1394 * This gives the policy a chance to alter its behavior for the duration of a user-switch.
1396 * @param switching true if a user-switch is in progress
1398 void setSwitchingUser(boolean switching);
1401 * Print the WindowManagerPolicy's state into the given stream.
1403 * @param prefix Text to print at the front of each line.
1404 * @param writer The PrintWriter to which you should dump your state. This will be
1405 * closed for you after you return.
1406 * @param args additional arguments to the dump request.
1408 public void dump(String prefix, PrintWriter writer, String[] args);
1411 * Write the WindowManagerPolicy's state into the protocol buffer.
1412 * The message is described in {@link com.android.server.wm.WindowManagerPolicyProto}
1414 * @param proto The protocol buffer output stream to write to.
1416 void writeToProto(ProtoOutputStream proto, long fieldId);
1419 * Returns whether a given window type is considered a top level one.
1420 * A top level window does not have a container, i.e. attached window,
1421 * or if it has a container it is laid out as a top-level window, not
1422 * as a child of its container.
1424 * @param windowType The window type.
1425 * @return True if the window is a top level one.
1427 public boolean isTopLevelWindow(int windowType);
1430 * Notifies the keyguard to start fading out.
1432 * @param startTime the start time of the animation in uptime milliseconds
1433 * @param fadeoutDuration the duration of the exit animation, in milliseconds
1435 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration);
1438 * Called when System UI has been started.
1440 void onSystemUiStarted();
1443 * Checks whether the policy is ready for dismissing the boot animation and completing the boot.
1445 * @return true if ready; false otherwise.
1447 boolean canDismissBootAnimation();
1450 * Convert the user rotation mode to a human readable format.
1452 static String userRotationModeToString(int mode) {
1454 case USER_ROTATION_FREE:
1455 return "USER_ROTATION_FREE";
1456 case USER_ROTATION_LOCKED:
1457 return "USER_ROTATION_LOCKED";
1459 return Integer.toString(mode);
1464 * Requests that the WindowManager sends
1465 * WindowManagerPolicyConstants#ACTION_USER_ACTIVITY_NOTIFICATION on the next user activity.
1467 public void requestUserActivityNotification();
1470 * Registers an IDisplayFoldListener.
1472 default void registerDisplayFoldListener(IDisplayFoldListener listener) {}
1475 * Unregisters an IDisplayFoldListener.
1477 default void unregisterDisplayFoldListener(IDisplayFoldListener listener) {}
1480 * Overrides the folded area.
1482 * @param area the overriding folded area or an empty {@code Rect} to clear the override.
1484 default void setOverrideFoldedArea(@NonNull Rect area) {}
1487 * Get the display folded area.
1489 default @NonNull Rect getFoldedArea() {
1494 * A new window on default display has been focused.
1496 default void onDefaultDisplayFocusChangedLw(WindowState newFocus) {}
1499 * Updates the flag about whether AOD is showing.
1501 * @return whether the value was changed.
1503 boolean setAodShowing(boolean aodShowing);