Home | History | Annotate | Download | only in policy
      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_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;
     63 
     64 import static java.lang.annotation.RetentionPolicy.SOURCE;
     65 
     66 import android.Manifest;
     67 import android.annotation.IntDef;
     68 import android.annotation.Nullable;
     69 import android.app.ActivityManager;
     70 import android.content.Context;
     71 import android.content.pm.ActivityInfo;
     72 import android.content.res.CompatibilityInfo;
     73 import android.content.res.Configuration;
     74 import android.graphics.Point;
     75 import android.graphics.Rect;
     76 import android.os.Bundle;
     77 import android.os.IBinder;
     78 import android.os.Looper;
     79 import android.os.RemoteException;
     80 import android.util.Slog;
     81 import android.util.proto.ProtoOutputStream;
     82 import android.view.Display;
     83 import android.view.DisplayCutout;
     84 import android.view.IApplicationToken;
     85 import android.view.IWindowManager;
     86 import android.view.InputEventReceiver;
     87 import android.view.KeyEvent;
     88 import android.view.Surface;
     89 import android.view.WindowManager;
     90 import android.view.WindowManagerGlobal;
     91 import android.view.WindowManagerPolicyConstants;
     92 import android.view.animation.Animation;
     93 
     94 import com.android.internal.policy.IKeyguardDismissCallback;
     95 import com.android.internal.policy.IShortcutService;
     96 import com.android.server.wm.DisplayFrames;
     97 import com.android.server.wm.utils.WmDisplayCutout;
     98 
     99 import java.io.PrintWriter;
    100 import java.lang.annotation.Retention;
    101 import java.lang.annotation.RetentionPolicy;
    102 
    103 /**
    104  * This interface supplies all UI-specific behavior of the window manager.  An
    105  * instance of it is created by the window manager when it starts up, and allows
    106  * customization of window layering, special window types, key dispatching, and
    107  * layout.
    108  *
    109  * <p>Because this provides deep interaction with the system window manager,
    110  * specific methods on this interface can be called from a variety of contexts
    111  * with various restrictions on what they can do.  These are encoded through
    112  * a suffixes at the end of a method encoding the thread the method is called
    113  * from and any locks that are held when it is being called; if no suffix
    114  * is attached to a method, then it is not called with any locks and may be
    115  * called from the main window manager thread or another thread calling into
    116  * the window manager.
    117  *
    118  * <p>The current suffixes are:
    119  *
    120  * <dl>
    121  * <dt> Ti <dd> Called from the input thread.  This is the thread that
    122  * collects pending input events and dispatches them to the appropriate window.
    123  * It may block waiting for events to be processed, so that the input stream is
    124  * properly serialized.
    125  * <dt> Tq <dd> Called from the low-level input queue thread.  This is the
    126  * thread that reads events out of the raw input devices and places them
    127  * into the global input queue that is read by the <var>Ti</var> thread.
    128  * This thread should not block for a long period of time on anything but the
    129  * key driver.
    130  * <dt> Lw <dd> Called with the main window manager lock held.  Because the
    131  * window manager is a very low-level system service, there are few other
    132  * system services you can call with this lock held.  It is explicitly okay to
    133  * make calls into the package manager and power manager; it is explicitly not
    134  * okay to make calls into the activity manager or most other services.  Note that
    135  * {@link android.content.Context#checkPermission(String, int, int)} and
    136  * variations require calling into the activity manager.
    137  * <dt> Li <dd> Called with the input thread lock held.  This lock can be
    138  * acquired by the window manager while it holds the window lock, so this is
    139  * even more restrictive than <var>Lw</var>.
    140  * </dl>
    141  */
    142 public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
    143     @Retention(SOURCE)
    144     @IntDef({NAV_BAR_LEFT, NAV_BAR_RIGHT, NAV_BAR_BOTTOM})
    145     @interface NavigationBarPosition {}
    146 
    147     /**
    148      * Pass this event to the user / app.  To be returned from
    149      * {@link #interceptKeyBeforeQueueing}.
    150      */
    151     int ACTION_PASS_TO_USER = 0x00000001;
    152     /** Layout state may have changed (so another layout will be performed) */
    153     int FINISH_LAYOUT_REDO_LAYOUT = 0x0001;
    154     /** Configuration state may have changed */
    155     int FINISH_LAYOUT_REDO_CONFIG = 0x0002;
    156     /** Wallpaper may need to move */
    157     int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004;
    158     /** Need to recompute animations */
    159     int FINISH_LAYOUT_REDO_ANIM = 0x0008;
    160 
    161     /**
    162      * Register shortcuts for window manager to dispatch.
    163      * Shortcut code is packed as (metaState << Integer.SIZE) | keyCode
    164      * @hide
    165      */
    166     void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)
    167             throws RemoteException;
    168 
    169     /**
    170      * Called when the Keyguard occluded state changed.
    171      * @param occluded Whether Keyguard is currently occluded or not.
    172      */
    173     void onKeyguardOccludedChangedLw(boolean occluded);
    174 
    175     /**
    176      * Called when the resource overlays change.
    177      */
    178     default void onOverlayChangedLw() {}
    179 
    180     /**
    181      * Interface to the Window Manager state associated with a particular
    182      * window.  You can hold on to an instance of this interface from the call
    183      * to prepareAddWindow() until removeWindow().
    184      */
    185     public interface WindowState {
    186         /**
    187          * Return the uid of the app that owns this window.
    188          */
    189         int getOwningUid();
    190 
    191         /**
    192          * Return the package name of the app that owns this window.
    193          */
    194         String getOwningPackage();
    195 
    196         /**
    197          * Perform standard frame computation.  The result can be obtained with
    198          * getFrame() if so desired.  Must be called with the window manager
    199          * lock held.
    200          *
    201          * @param parentFrame The frame of the parent container this window
    202          * is in, used for computing its basic position.
    203          * @param displayFrame The frame of the overall display in which this
    204          * window can appear, used for constraining the overall dimensions
    205          * of the window.
    206          * @param overlayFrame The frame within the display that is inside
    207          * of the overlay region.
    208          * @param contentFrame The frame within the display in which we would
    209          * like active content to appear.  This will cause windows behind to
    210          * be resized to match the given content frame.
    211          * @param visibleFrame The frame within the display that the window
    212          * is actually visible, used for computing its visible insets to be
    213          * given to windows behind.
    214          * This can be used as a hint for scrolling (avoiding resizing)
    215          * the window to make certain that parts of its content
    216          * are visible.
    217          * @param decorFrame The decor frame specified by policy specific to this window,
    218          * to use for proper cropping during animation.
    219          * @param stableFrame The frame around which stable system decoration is positioned.
    220          * @param outsetFrame The frame that includes areas that aren't part of the surface but we
    221          * want to treat them as such.
    222          * @param displayCutout the display cutout
    223          * @param parentFrameWasClippedByDisplayCutout true if the parent frame would have been
    224          * different if there was no display cutout.
    225          */
    226         public void computeFrameLw(Rect parentFrame, Rect displayFrame,
    227                 Rect overlayFrame, Rect contentFrame, Rect visibleFrame, Rect decorFrame,
    228                 Rect stableFrame, @Nullable Rect outsetFrame, WmDisplayCutout displayCutout,
    229                 boolean parentFrameWasClippedByDisplayCutout);
    230 
    231         /**
    232          * Retrieve the current frame of the window that has been assigned by
    233          * the window manager.  Must be called with the window manager lock held.
    234          *
    235          * @return Rect The rectangle holding the window frame.
    236          */
    237         public Rect getFrameLw();
    238 
    239         /**
    240          * Retrieve the frame of the display that this window was last
    241          * laid out in.  Must be called with the
    242          * window manager lock held.
    243          *
    244          * @return Rect The rectangle holding the display frame.
    245          */
    246         public Rect getDisplayFrameLw();
    247 
    248         /**
    249          * Retrieve the frame of the area inside the overscan region of the
    250          * display that this window was last laid out in.  Must be called with the
    251          * window manager lock held.
    252          *
    253          * @return Rect The rectangle holding the display overscan frame.
    254          */
    255         public Rect getOverscanFrameLw();
    256 
    257         /**
    258          * Retrieve the frame of the content area that this window was last
    259          * laid out in.  This is the area in which the content of the window
    260          * should be placed.  It will be smaller than the display frame to
    261          * account for screen decorations such as a status bar or soft
    262          * keyboard.  Must be called with the
    263          * window manager lock held.
    264          *
    265          * @return Rect The rectangle holding the content frame.
    266          */
    267         public Rect getContentFrameLw();
    268 
    269         /**
    270          * Retrieve the frame of the visible area that this window was last
    271          * laid out in.  This is the area of the screen in which the window
    272          * will actually be fully visible.  It will be smaller than the
    273          * content frame to account for transient UI elements blocking it
    274          * such as an input method's candidates UI.  Must be called with the
    275          * window manager lock held.
    276          *
    277          * @return Rect The rectangle holding the visible frame.
    278          */
    279         public Rect getVisibleFrameLw();
    280 
    281         /**
    282          * Returns true if this window is waiting to receive its given
    283          * internal insets from the client app, and so should not impact the
    284          * layout of other windows.
    285          */
    286         public boolean getGivenInsetsPendingLw();
    287 
    288         /**
    289          * Retrieve the insets given by this window's client for the content
    290          * area of windows behind it.  Must be called with the
    291          * window manager lock held.
    292          *
    293          * @return Rect The left, top, right, and bottom insets, relative
    294          * to the window's frame, of the actual contents.
    295          */
    296         public Rect getGivenContentInsetsLw();
    297 
    298         /**
    299          * Retrieve the insets given by this window's client for the visible
    300          * area of windows behind it.  Must be called with the
    301          * window manager lock held.
    302          *
    303          * @return Rect The left, top, right, and bottom insets, relative
    304          * to the window's frame, of the actual visible area.
    305          */
    306         public Rect getGivenVisibleInsetsLw();
    307 
    308         /**
    309          * Retrieve the current LayoutParams of the window.
    310          *
    311          * @return WindowManager.LayoutParams The window's internal LayoutParams
    312          *         instance.
    313          */
    314         public WindowManager.LayoutParams getAttrs();
    315 
    316         /**
    317          * Return whether this window needs the menu key shown.  Must be called
    318          * with window lock held, because it may need to traverse down through
    319          * window list to determine the result.
    320          * @param bottom The bottom-most window to consider when determining this.
    321          */
    322         public boolean getNeedsMenuLw(WindowState bottom);
    323 
    324         /**
    325          * Retrieve the current system UI visibility flags associated with
    326          * this window.
    327          */
    328         public int getSystemUiVisibility();
    329 
    330         /**
    331          * Get the layer at which this window's surface will be Z-ordered.
    332          */
    333         public int getSurfaceLayer();
    334 
    335         /**
    336          * Retrieve the type of the top-level window.
    337          *
    338          * @return the base type of the parent window if attached or its own type otherwise
    339          */
    340         public int getBaseType();
    341 
    342         /**
    343          * Return the token for the application (actually activity) that owns
    344          * this window.  May return null for system windows.
    345          *
    346          * @return An IApplicationToken identifying the owning activity.
    347          */
    348         public IApplicationToken getAppToken();
    349 
    350         /**
    351          * Return true if this window is participating in voice interaction.
    352          */
    353         public boolean isVoiceInteraction();
    354 
    355         /**
    356          * Return true if, at any point, the application token associated with
    357          * this window has actually displayed any windows.  This is most useful
    358          * with the "starting up" window to determine if any windows were
    359          * displayed when it is closed.
    360          *
    361          * @return Returns true if one or more windows have been displayed,
    362          *         else false.
    363          */
    364         public boolean hasAppShownWindows();
    365 
    366         /**
    367          * Is this window visible?  It is not visible if there is no
    368          * surface, or we are in the process of running an exit animation
    369          * that will remove the surface.
    370          */
    371         boolean isVisibleLw();
    372 
    373         /**
    374          * Is this window currently visible to the user on-screen?  It is
    375          * displayed either if it is visible or it is currently running an
    376          * animation before no longer being visible.  Must be called with the
    377          * window manager lock held.
    378          */
    379         boolean isDisplayedLw();
    380 
    381         /**
    382          * Return true if this window (or a window it is attached to, but not
    383          * considering its app token) is currently animating.
    384          */
    385         boolean isAnimatingLw();
    386 
    387         /**
    388          * @return Whether the window can affect SystemUI flags, meaning that SystemUI (system bars,
    389          *         for example) will be  affected by the flags specified in this window. This is the
    390          *         case when the surface is on screen but not exiting.
    391          */
    392         boolean canAffectSystemUiFlags();
    393 
    394         /**
    395          * Is this window considered to be gone for purposes of layout?
    396          */
    397         boolean isGoneForLayoutLw();
    398 
    399         /**
    400          * Returns true if the window has a surface that it has drawn a
    401          * complete UI in to. Note that this is different from {@link #hasDrawnLw()}
    402          * in that it also returns true if the window is READY_TO_SHOW, but was not yet
    403          * promoted to HAS_DRAWN.
    404          */
    405         boolean isDrawnLw();
    406 
    407         /**
    408          * Returns true if this window has been shown on screen at some time in
    409          * the past.  Must be called with the window manager lock held.
    410          *
    411          * @deprecated Use {@link #isDrawnLw} or any of the other drawn/visibility methods.
    412          */
    413         @Deprecated
    414         public boolean hasDrawnLw();
    415 
    416         /**
    417          * Can be called by the policy to force a window to be hidden,
    418          * regardless of whether the client or window manager would like
    419          * it shown.  Must be called with the window manager lock held.
    420          * Returns true if {@link #showLw} was last called for the window.
    421          */
    422         public boolean hideLw(boolean doAnimation);
    423 
    424         /**
    425          * Can be called to undo the effect of {@link #hideLw}, allowing a
    426          * window to be shown as long as the window manager and client would
    427          * also like it to be shown.  Must be called with the window manager
    428          * lock held.
    429          * Returns true if {@link #hideLw} was last called for the window.
    430          */
    431         public boolean showLw(boolean doAnimation);
    432 
    433         /**
    434          * Check whether the process hosting this window is currently alive.
    435          */
    436         public boolean isAlive();
    437 
    438         /**
    439          * Check if window is on {@link Display#DEFAULT_DISPLAY}.
    440          * @return true if window is on default display.
    441          */
    442         public boolean isDefaultDisplay();
    443 
    444         /**
    445          * Check whether the window is currently dimming.
    446          */
    447         public boolean isDimming();
    448 
    449         /**
    450          * Returns true if the window is letterboxed for the display cutout.
    451          */
    452         default boolean isLetterboxedForDisplayCutoutLw() {
    453             return false;
    454         }
    455 
    456         /**
    457          * Returns true if the window has a letterbox and any part of that letterbox overlaps with
    458          * the given {@code rect}.
    459          */
    460         default boolean isLetterboxedOverlappingWith(Rect rect) {
    461             return false;
    462         }
    463 
    464         /** @return the current windowing mode of this window. */
    465         int getWindowingMode();
    466 
    467         /**
    468          * Returns true if the window is current in multi-windowing mode. i.e. it shares the
    469          * screen with other application windows.
    470          */
    471         public boolean isInMultiWindowMode();
    472 
    473         public int getRotationAnimationHint();
    474 
    475         public boolean isInputMethodWindow();
    476 
    477         public boolean isInputMethodTarget();
    478 
    479         public int getDisplayId();
    480 
    481         /**
    482          * Returns true if the window owner can add internal system windows.
    483          * That is, they have {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}.
    484          */
    485         default boolean canAddInternalSystemWindow() {
    486             return false;
    487         }
    488 
    489         /**
    490          * Returns true if the window owner has the permission to acquire a sleep token when it's
    491          * visible. That is, they have the permission {@link Manifest.permission#DEVICE_POWER}.
    492          */
    493         boolean canAcquireSleepToken();
    494 
    495         /**
    496          * Writes {@link com.android.server.wm.IdentifierProto} to stream.
    497          */
    498         void writeIdentifierToProto(ProtoOutputStream proto, long fieldId);
    499     }
    500 
    501     /**
    502      * Representation of a input consumer that the policy has added to the
    503      * window manager to consume input events going to windows below it.
    504      */
    505     public interface InputConsumer {
    506         /**
    507          * Remove the input consumer from the window manager.
    508          */
    509         void dismiss();
    510     }
    511 
    512     /**
    513      * Holds the contents of a starting window. {@link #addSplashScreen} needs to wrap the
    514      * contents of the starting window into an class implementing this interface, which then will be
    515      * held by WM and released with {@link #remove} when no longer needed.
    516      */
    517     interface StartingSurface {
    518 
    519         /**
    520          * Removes the starting window surface. Do not hold the window manager lock when calling
    521          * this method!
    522          */
    523         void remove();
    524     }
    525 
    526     /**
    527      * Interface for calling back in to the window manager that is private
    528      * between it and the policy.
    529      */
    530     public interface WindowManagerFuncs {
    531         public static final int LID_ABSENT = -1;
    532         public static final int LID_CLOSED = 0;
    533         public static final int LID_OPEN = 1;
    534 
    535         public static final int CAMERA_LENS_COVER_ABSENT = -1;
    536         public static final int CAMERA_LENS_UNCOVERED = 0;
    537         public static final int CAMERA_LENS_COVERED = 1;
    538 
    539         /**
    540          * Ask the window manager to re-evaluate the system UI flags.
    541          */
    542         public void reevaluateStatusBarVisibility();
    543 
    544         /**
    545          * Add a input consumer which will consume all input events going to any window below it.
    546          */
    547         public InputConsumer createInputConsumer(Looper looper, String name,
    548                 InputEventReceiver.Factory inputEventReceiverFactory);
    549 
    550         /**
    551          * Returns a code that describes the current state of the lid switch.
    552          */
    553         public int getLidState();
    554 
    555         /**
    556          * Lock the device now.
    557          */
    558         public void lockDeviceNow();
    559 
    560         /**
    561          * Returns a code that descripbes whether the camera lens is covered or not.
    562          */
    563         public int getCameraLensCoverState();
    564 
    565         /**
    566          * Switch the keyboard layout for the given device.
    567          * Direction should be +1 or -1 to go to the next or previous keyboard layout.
    568          */
    569         public void switchKeyboardLayout(int deviceId, int direction);
    570 
    571         /**
    572          * Switch the input method, to be precise, input method subtype.
    573          *
    574          * @param forwardDirection {@code true} to rotate in a forward direction.
    575          */
    576         public void switchInputMethod(boolean forwardDirection);
    577 
    578         public void shutdown(boolean confirm);
    579         public void reboot(boolean confirm);
    580         public void rebootSafeMode(boolean confirm);
    581 
    582         /**
    583          * Return the window manager lock needed to correctly call "Lw" methods.
    584          */
    585         public Object getWindowManagerLock();
    586 
    587         /** Register a system listener for touch events */
    588         void registerPointerEventListener(PointerEventListener listener);
    589 
    590         /** Unregister a system listener for touch events */
    591         void unregisterPointerEventListener(PointerEventListener listener);
    592 
    593         /**
    594          * @return The content insets of the docked divider window.
    595          */
    596         int getDockedDividerInsetsLw();
    597 
    598         /**
    599          * Retrieves the {@param outBounds} from the stack matching the {@param windowingMode} and
    600          * {@param activityType}.
    601          */
    602         void getStackBounds(int windowingMode, int activityType, Rect outBounds);
    603 
    604         /**
    605          * Notifies window manager that {@link #isShowingDreamLw} has changed.
    606          */
    607         void notifyShowingDreamChanged();
    608 
    609         /**
    610          * @return The currently active input method window.
    611          */
    612         WindowState getInputMethodWindowLw();
    613 
    614         /**
    615          * Notifies window manager that {@link #isKeyguardTrustedLw} has changed.
    616          */
    617         void notifyKeyguardTrustedChanged();
    618 
    619         /**
    620          * Notifies the window manager that screen is being turned off.
    621          *
    622          * @param listener callback to call when display can be turned off
    623          */
    624         void screenTurningOff(ScreenOffListener listener);
    625 
    626         /**
    627          * Convert the lid state to a human readable format.
    628          */
    629         static String lidStateToString(int lid) {
    630             switch (lid) {
    631                 case LID_ABSENT:
    632                     return "LID_ABSENT";
    633                 case LID_CLOSED:
    634                     return "LID_CLOSED";
    635                 case LID_OPEN:
    636                     return "LID_OPEN";
    637                 default:
    638                     return Integer.toString(lid);
    639             }
    640         }
    641 
    642         /**
    643          * Convert the camera lens state to a human readable format.
    644          */
    645         static String cameraLensStateToString(int lens) {
    646             switch (lens) {
    647                 case CAMERA_LENS_COVER_ABSENT:
    648                     return "CAMERA_LENS_COVER_ABSENT";
    649                 case CAMERA_LENS_UNCOVERED:
    650                     return "CAMERA_LENS_UNCOVERED";
    651                 case CAMERA_LENS_COVERED:
    652                     return "CAMERA_LENS_COVERED";
    653                 default:
    654                     return Integer.toString(lens);
    655             }
    656         }
    657 
    658         /**
    659          * Hint to window manager that the user has started a navigation action that should
    660          * abort animations that have no timeout, in case they got stuck.
    661          */
    662         void triggerAnimationFailsafe();
    663 
    664         /**
    665          * The keyguard showing state has changed
    666          */
    667         void onKeyguardShowingAndNotOccludedChanged();
    668     }
    669 
    670     /** Window has been added to the screen. */
    671     public static final int TRANSIT_ENTER = 1;
    672     /** Window has been removed from the screen. */
    673     public static final int TRANSIT_EXIT = 2;
    674     /** Window has been made visible. */
    675     public static final int TRANSIT_SHOW = 3;
    676     /** Window has been made invisible.
    677      * TODO: Consider removal as this is unused. */
    678     public static final int TRANSIT_HIDE = 4;
    679     /** The "application starting" preview window is no longer needed, and will
    680      * animate away to show the real window. */
    681     public static final int TRANSIT_PREVIEW_DONE = 5;
    682 
    683     // NOTE: screen off reasons are in order of significance, with more
    684     // important ones lower than less important ones.
    685 
    686     /** @hide */
    687     @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED})
    688     @Retention(RetentionPolicy.SOURCE)
    689     public @interface UserRotationMode {}
    690 
    691     /** When not otherwise specified by the activity's screenOrientation, rotation should be
    692      * determined by the system (that is, using sensors). */
    693     public final int USER_ROTATION_FREE = 0;
    694     /** When not otherwise specified by the activity's screenOrientation, rotation is set by
    695      * the user. */
    696     public final int USER_ROTATION_LOCKED = 1;
    697 
    698     /**
    699      * Perform initialization of the policy.
    700      *
    701      * @param context The system context we are running in.
    702      */
    703     public void init(Context context, IWindowManager windowManager,
    704             WindowManagerFuncs windowManagerFuncs);
    705 
    706     /**
    707      * @return true if com.android.internal.R.bool#config_forceDefaultOrientation is true.
    708      */
    709     public boolean isDefaultOrientationForced();
    710 
    711     /**
    712      * Called by window manager once it has the initial, default native
    713      * display dimensions.
    714      */
    715     public void setInitialDisplaySize(Display display, int width, int height, int density);
    716 
    717     /**
    718      * Check permissions when adding a window.
    719      *
    720      * @param attrs The window's LayoutParams.
    721      * @param outAppOp First element will be filled with the app op corresponding to
    722      *                 this window, or OP_NONE.
    723      *
    724      * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed;
    725      *      else an error code, usually
    726      *      {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add.
    727      */
    728     public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp);
    729 
    730     /**
    731      * Check permissions when adding a window.
    732      *
    733      * @param attrs The window's LayoutParams.
    734      *
    735      * @return True if the window may only be shown to the current user, false if the window can
    736      * be shown on all users' windows.
    737      */
    738     public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs);
    739 
    740     /**
    741      * Sanitize the layout parameters coming from a client.  Allows the policy
    742      * to do things like ensure that windows of a specific type can't take
    743      * input focus.
    744      *
    745      * @param attrs The window layout parameters to be modified.  These values
    746      * are modified in-place.
    747      */
    748     public void adjustWindowParamsLw(WindowState win, WindowManager.LayoutParams attrs,
    749             boolean hasStatusBarServicePermission);
    750 
    751     /**
    752      * After the window manager has computed the current configuration based
    753      * on its knowledge of the display and input devices, it gives the policy
    754      * a chance to adjust the information contained in it.  If you want to
    755      * leave it as-is, simply do nothing.
    756      *
    757      * <p>This method may be called by any thread in the window manager, but
    758      * no internal locks in the window manager will be held.
    759      *
    760      * @param config The Configuration being computed, for you to change as
    761      * desired.
    762      * @param keyboardPresence Flags that indicate whether internal or external
    763      * keyboards are present.
    764      * @param navigationPresence Flags that indicate whether internal or external
    765      * navigation devices are present.
    766      */
    767     public void adjustConfigurationLw(Configuration config, int keyboardPresence,
    768             int navigationPresence);
    769 
    770     /**
    771      * Returns the layer assignment for the window state. Allows you to control how different
    772      * kinds of windows are ordered on-screen.
    773      *
    774      * @param win The window state
    775      * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
    776      */
    777     default int getWindowLayerLw(WindowState win) {
    778         return getWindowLayerFromTypeLw(win.getBaseType(), win.canAddInternalSystemWindow());
    779     }
    780 
    781     /**
    782      * Returns the layer assignment for the window type. Allows you to control how different
    783      * kinds of windows are ordered on-screen.
    784      *
    785      * @param type The type of window being assigned.
    786      * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
    787      */
    788     default int getWindowLayerFromTypeLw(int type) {
    789         if (isSystemAlertWindowType(type)) {
    790             throw new IllegalArgumentException("Use getWindowLayerFromTypeLw() or"
    791                     + " getWindowLayerLw() for alert window types");
    792         }
    793         return getWindowLayerFromTypeLw(type, false /* canAddInternalSystemWindow */);
    794     }
    795 
    796     /**
    797      * Returns the layer assignment for the window type. Allows you to control how different
    798      * kinds of windows are ordered on-screen.
    799      *
    800      * @param type The type of window being assigned.
    801      * @param canAddInternalSystemWindow If the owner window associated with the type we are
    802      *        evaluating can add internal system windows. I.e they have
    803      *        {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}. If true, alert window
    804      *        types {@link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)}
    805      *        can be assigned layers greater than the layer for
    806      *        {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} Else, their
    807      *        layers would be lesser.
    808      * @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
    809      */
    810     default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow) {
    811         if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
    812             return APPLICATION_LAYER;
    813         }
    814 
    815         switch (type) {
    816             case TYPE_WALLPAPER:
    817                 // wallpaper is at the bottom, though the window manager may move it.
    818                 return  1;
    819             case TYPE_PRESENTATION:
    820             case TYPE_PRIVATE_PRESENTATION:
    821                 return  APPLICATION_LAYER;
    822             case TYPE_DOCK_DIVIDER:
    823                 return  APPLICATION_LAYER;
    824             case TYPE_QS_DIALOG:
    825                 return  APPLICATION_LAYER;
    826             case TYPE_PHONE:
    827                 return  3;
    828             case TYPE_SEARCH_BAR:
    829             case TYPE_VOICE_INTERACTION_STARTING:
    830                 return  4;
    831             case TYPE_VOICE_INTERACTION:
    832                 // voice interaction layer is almost immediately above apps.
    833                 return  5;
    834             case TYPE_INPUT_CONSUMER:
    835                 return  6;
    836             case TYPE_SYSTEM_DIALOG:
    837                 return  7;
    838             case TYPE_TOAST:
    839                 // toasts and the plugged-in battery thing
    840                 return  8;
    841             case TYPE_PRIORITY_PHONE:
    842                 // SIM errors and unlock.  Not sure if this really should be in a high layer.
    843                 return  9;
    844             case TYPE_SYSTEM_ALERT:
    845                 // like the ANR / app crashed dialogs
    846                 return  canAddInternalSystemWindow ? 11 : 10;
    847             case TYPE_APPLICATION_OVERLAY:
    848                 return  12;
    849             case TYPE_DREAM:
    850                 // used for Dreams (screensavers with TYPE_DREAM windows)
    851                 return  13;
    852             case TYPE_INPUT_METHOD:
    853                 // on-screen keyboards and other such input method user interfaces go here.
    854                 return  14;
    855             case TYPE_INPUT_METHOD_DIALOG:
    856                 // on-screen keyboards and other such input method user interfaces go here.
    857                 return  15;
    858             case TYPE_STATUS_BAR:
    859                 return  17;
    860             case TYPE_STATUS_BAR_PANEL:
    861                 return  18;
    862             case TYPE_STATUS_BAR_SUB_PANEL:
    863                 return  19;
    864             case TYPE_KEYGUARD_DIALOG:
    865                 return  20;
    866             case TYPE_VOLUME_OVERLAY:
    867                 // the on-screen volume indicator and controller shown when the user
    868                 // changes the device volume
    869                 return  21;
    870             case TYPE_SYSTEM_OVERLAY:
    871                 // the on-screen volume indicator and controller shown when the user
    872                 // changes the device volume
    873                 return  canAddInternalSystemWindow ? 22 : 11;
    874             case TYPE_NAVIGATION_BAR:
    875                 // the navigation bar, if available, shows atop most things
    876                 return  23;
    877             case TYPE_NAVIGATION_BAR_PANEL:
    878                 // some panels (e.g. search) need to show on top of the navigation bar
    879                 return  24;
    880             case TYPE_SCREENSHOT:
    881                 // screenshot selection layer shouldn't go above system error, but it should cover
    882                 // navigation bars at the very least.
    883                 return  25;
    884             case TYPE_SYSTEM_ERROR:
    885                 // system-level error dialogs
    886                 return  canAddInternalSystemWindow ? 26 : 10;
    887             case TYPE_MAGNIFICATION_OVERLAY:
    888                 // used to highlight the magnified portion of a display
    889                 return  27;
    890             case TYPE_DISPLAY_OVERLAY:
    891                 // used to simulate secondary display devices
    892                 return  28;
    893             case TYPE_DRAG:
    894                 // the drag layer: input for drag-and-drop is associated with this window,
    895                 // which sits above all other focusable windows
    896                 return  29;
    897             case TYPE_ACCESSIBILITY_OVERLAY:
    898                 // overlay put by accessibility services to intercept user interaction
    899                 return  30;
    900             case TYPE_SECURE_SYSTEM_OVERLAY:
    901                 return  31;
    902             case TYPE_BOOT_PROGRESS:
    903                 return  32;
    904             case TYPE_POINTER:
    905                 // the (mouse) pointer layer
    906                 return  33;
    907             default:
    908                 Slog.e("WindowManager", "Unknown window type: " + type);
    909                 return APPLICATION_LAYER;
    910         }
    911     }
    912 
    913     /**
    914      * Return how to Z-order sub-windows in relation to the window they are attached to.
    915      * Return positive to have them ordered in front, negative for behind.
    916      *
    917      * @param type The sub-window type code.
    918      *
    919      * @return int Layer in relation to the attached window, where positive is
    920      *         above and negative is below.
    921      */
    922     default int getSubWindowLayerFromTypeLw(int type) {
    923         switch (type) {
    924             case TYPE_APPLICATION_PANEL:
    925             case TYPE_APPLICATION_ATTACHED_DIALOG:
    926                 return APPLICATION_PANEL_SUBLAYER;
    927             case TYPE_APPLICATION_MEDIA:
    928                 return APPLICATION_MEDIA_SUBLAYER;
    929             case TYPE_APPLICATION_MEDIA_OVERLAY:
    930                 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
    931             case TYPE_APPLICATION_SUB_PANEL:
    932                 return APPLICATION_SUB_PANEL_SUBLAYER;
    933             case TYPE_APPLICATION_ABOVE_SUB_PANEL:
    934                 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
    935         }
    936         Slog.e("WindowManager", "Unknown sub-window type: " + type);
    937         return 0;
    938     }
    939 
    940     /**
    941      * Get the highest layer (actually one more than) that the wallpaper is
    942      * allowed to be in.
    943      */
    944     public int getMaxWallpaperLayer();
    945 
    946     /**
    947      * Return the display width available after excluding any screen
    948      * decorations that could never be removed in Honeycomb. That is, system bar or
    949      * button bar.
    950      */
    951     public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
    952             int uiMode, int displayId, DisplayCutout displayCutout);
    953 
    954     /**
    955      * Return the display height available after excluding any screen
    956      * decorations that could never be removed in Honeycomb. That is, system bar or
    957      * button bar.
    958      */
    959     public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
    960             int uiMode, int displayId, DisplayCutout displayCutout);
    961 
    962     /**
    963      * Return the available screen width that we should report for the
    964      * configuration.  This must be no larger than
    965      * {@link #getNonDecorDisplayWidth(int, int, int, int, int, DisplayCutout)}; it may be smaller
    966      * than that to account for more transient decoration like a status bar.
    967      */
    968     public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation,
    969             int uiMode, int displayId, DisplayCutout displayCutout);
    970 
    971     /**
    972      * Return the available screen height that we should report for the
    973      * configuration.  This must be no larger than
    974      * {@link #getNonDecorDisplayHeight(int, int, int, int, int, DisplayCutout)}; it may be smaller
    975      * than that to account for more transient decoration like a status bar.
    976      */
    977     public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation,
    978             int uiMode, int displayId, DisplayCutout displayCutout);
    979 
    980     /**
    981      * Return whether the given window can become the Keyguard window. Typically returns true for
    982      * the StatusBar.
    983      */
    984     public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs);
    985 
    986     /**
    987      * @return whether {@param win} can be hidden by Keyguard
    988      */
    989     public boolean canBeHiddenByKeyguardLw(WindowState win);
    990 
    991     /**
    992      * Called when the system would like to show a UI to indicate that an
    993      * application is starting.  You can use this to add a
    994      * APPLICATION_STARTING_TYPE window with the given appToken to the window
    995      * manager (using the normal window manager APIs) that will be shown until
    996      * the application displays its own window.  This is called without the
    997      * window manager locked so that you can call back into it.
    998      *
    999      * @param appToken Token of the application being started.
   1000      * @param packageName The name of the application package being started.
   1001      * @param theme Resource defining the application's overall visual theme.
   1002      * @param nonLocalizedLabel The default title label of the application if
   1003      *        no data is found in the resource.
   1004      * @param labelRes The resource ID the application would like to use as its name.
   1005      * @param icon The resource ID the application would like to use as its icon.
   1006      * @param windowFlags Window layout flags.
   1007      * @param overrideConfig override configuration to consider when generating
   1008      *        context to for resources.
   1009      * @param displayId Id of the display to show the splash screen at.
   1010      *
   1011      * @return The starting surface.
   1012      *
   1013      */
   1014     public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme,
   1015             CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
   1016             int logo, int windowFlags, Configuration overrideConfig, int displayId);
   1017 
   1018     /**
   1019      * Prepare for a window being added to the window manager.  You can throw an
   1020      * exception here to prevent the window being added, or do whatever setup
   1021      * you need to keep track of the window.
   1022      *
   1023      * @param win The window being added.
   1024      * @param attrs The window's LayoutParams.
   1025      *
   1026      * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed, else an
   1027      *         error code to abort the add.
   1028      */
   1029     public int prepareAddWindowLw(WindowState win,
   1030             WindowManager.LayoutParams attrs);
   1031 
   1032     /**
   1033      * Called when a window is being removed from a window manager.  Must not
   1034      * throw an exception -- clean up as much as possible.
   1035      *
   1036      * @param win The window being removed.
   1037      */
   1038     public void removeWindowLw(WindowState win);
   1039 
   1040     /**
   1041      * Control the animation to run when a window's state changes.  Return a
   1042      * non-0 number to force the animation to a specific resource ID, or 0
   1043      * to use the default animation.
   1044      *
   1045      * @param win The window that is changing.
   1046      * @param transit What is happening to the window: {@link #TRANSIT_ENTER},
   1047      *                {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or
   1048      *                {@link #TRANSIT_HIDE}.
   1049      *
   1050      * @return Resource ID of the actual animation to use, or 0 for none.
   1051      */
   1052     public int selectAnimationLw(WindowState win, int transit);
   1053 
   1054     /**
   1055      * Determine the animation to run for a rotation transition based on the
   1056      * top fullscreen windows {@link WindowManager.LayoutParams#rotationAnimation}
   1057      * and whether it is currently fullscreen and frontmost.
   1058      *
   1059      * @param anim The exiting animation resource id is stored in anim[0], the
   1060      * entering animation resource id is stored in anim[1].
   1061      */
   1062     public void selectRotationAnimationLw(int anim[]);
   1063 
   1064     /**
   1065      * Validate whether the current top fullscreen has specified the same
   1066      * {@link WindowManager.LayoutParams#rotationAnimation} value as that
   1067      * being passed in from the previous top fullscreen window.
   1068      *
   1069      * @param exitAnimId exiting resource id from the previous window.
   1070      * @param enterAnimId entering resource id from the previous window.
   1071      * @param forceDefault For rotation animations only, if true ignore the
   1072      * animation values and just return false.
   1073      * @return true if the previous values are still valid, false if they
   1074      * should be replaced with the default.
   1075      */
   1076     public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
   1077             boolean forceDefault);
   1078 
   1079     /**
   1080      * Create and return an animation to re-display a window that was force hidden by Keyguard.
   1081      */
   1082     public Animation createHiddenByKeyguardExit(boolean onWallpaper,
   1083             boolean goingToNotificationShade);
   1084 
   1085     /**
   1086      * Create and return an animation to let the wallpaper disappear after being shown behind
   1087      * Keyguard.
   1088      */
   1089     public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade);
   1090 
   1091     /**
   1092      * Called from the input reader thread before a key is enqueued.
   1093      *
   1094      * <p>There are some actions that need to be handled here because they
   1095      * affect the power state of the device, for example, the power keys.
   1096      * Generally, it's best to keep as little as possible in the queue thread
   1097      * because it's the most fragile.
   1098      * @param event The key event.
   1099      * @param policyFlags The policy flags associated with the key.
   1100      *
   1101      * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
   1102      */
   1103     public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
   1104 
   1105     /**
   1106      * Called from the input reader thread before a motion is enqueued when the device is in a
   1107      * non-interactive state.
   1108      *
   1109      * <p>There are some actions that need to be handled here because they
   1110      * affect the power state of the device, for example, waking on motions.
   1111      * Generally, it's best to keep as little as possible in the queue thread
   1112      * because it's the most fragile.
   1113      * @param policyFlags The policy flags associated with the motion.
   1114      *
   1115      * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
   1116      */
   1117     public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags);
   1118 
   1119     /**
   1120      * Called from the input dispatcher thread before a key is dispatched to a window.
   1121      *
   1122      * <p>Allows you to define
   1123      * behavior for keys that can not be overridden by applications.
   1124      * This method is called from the input thread, with no locks held.
   1125      *
   1126      * @param win The window that currently has focus.  This is where the key
   1127      *            event will normally go.
   1128      * @param event The key event.
   1129      * @param policyFlags The policy flags associated with the key.
   1130      * @return 0 if the key should be dispatched immediately, -1 if the key should
   1131      * not be dispatched ever, or a positive value indicating the number of
   1132      * milliseconds by which the key dispatch should be delayed before trying
   1133      * again.
   1134      */
   1135     public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags);
   1136 
   1137     /**
   1138      * Called from the input dispatcher thread when an application did not handle
   1139      * a key that was dispatched to it.
   1140      *
   1141      * <p>Allows you to define default global behavior for keys that were not handled
   1142      * by applications.  This method is called from the input thread, with no locks held.
   1143      *
   1144      * @param win The window that currently has focus.  This is where the key
   1145      *            event will normally go.
   1146      * @param event The key event.
   1147      * @param policyFlags The policy flags associated with the key.
   1148      * @return Returns an alternate key event to redispatch as a fallback, or null to give up.
   1149      * The caller is responsible for recycling the key event.
   1150      */
   1151     public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags);
   1152 
   1153     /**
   1154      * Called when layout of the windows is about to start.
   1155      *
   1156      * @param displayFrames frames of the display we are doing layout on.
   1157      * @param uiMode The current uiMode in configuration.
   1158      */
   1159     default void beginLayoutLw(DisplayFrames displayFrames, int uiMode) {}
   1160 
   1161     /**
   1162      * Returns the bottom-most layer of the system decor, above which no policy decor should
   1163      * be applied.
   1164      */
   1165     public int getSystemDecorLayerLw();
   1166 
   1167     /**
   1168      * Called for each window attached to the window manager as layout is proceeding. The
   1169      * implementation of this function must take care of setting the window's frame, either here or
   1170      * in finishLayout().
   1171      *
   1172      * @param win The window being positioned.
   1173      * @param attached For sub-windows, the window it is attached to; this
   1174      *                 window will already have had layoutWindow() called on it
   1175      *                 so you can use its Rect.  Otherwise null.
   1176      * @param displayFrames The display frames.
   1177      */
   1178     default void layoutWindowLw(
   1179             WindowState win, WindowState attached, DisplayFrames displayFrames) {}
   1180 
   1181 
   1182     /**
   1183      * Return the layout hints for a newly added window. These values are computed on the
   1184      * most recent layout, so they are not guaranteed to be correct.
   1185      *
   1186      * @param attrs The LayoutParams of the window.
   1187      * @param taskBounds The bounds of the task this window is on or {@code null} if no task is
   1188      *                   associated with the window.
   1189      * @param displayFrames display frames.
   1190      * @param outFrame The frame of the window.
   1191      * @param outContentInsets The areas covered by system windows, expressed as positive insets.
   1192      * @param outStableInsets The areas covered by stable system windows irrespective of their
   1193      *                        current visibility. Expressed as positive insets.
   1194      * @param outOutsets The areas that are not real display, but we would like to treat as such.
   1195      * @param outDisplayCutout The area that has been cut away from the display.
   1196      * @return Whether to always consume the navigation bar.
   1197      *         See {@link #isNavBarForcedShownLw(WindowState)}.
   1198      */
   1199     default boolean getLayoutHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
   1200             DisplayFrames displayFrames, Rect outFrame, Rect outContentInsets,
   1201             Rect outStableInsets, Rect outOutsets,
   1202             DisplayCutout.ParcelableWrapper outDisplayCutout) {
   1203         return false;
   1204     }
   1205 
   1206     /**
   1207      * Called following layout of all windows before each window has policy applied.
   1208      *
   1209      * @param displayWidth The current full width of the screen.
   1210      * @param displayHeight The current full height of the screen.
   1211      */
   1212     public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight);
   1213 
   1214     /**
   1215      * Called following layout of all window to apply policy to each window.
   1216      *
   1217      * @param win The window being positioned.
   1218      * @param attrs The LayoutParams of the window.
   1219      * @param attached For sub-windows, the window it is attached to. Otherwise null.
   1220      */
   1221     public void applyPostLayoutPolicyLw(WindowState win,
   1222             WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget);
   1223 
   1224     /**
   1225      * Called following layout of all windows and after policy has been applied
   1226      * to each window. If in this function you do
   1227      * something that may have modified the animation state of another window,
   1228      * be sure to return non-zero in order to perform another pass through layout.
   1229      *
   1230      * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT},
   1231      * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER},
   1232      * or {@link #FINISH_LAYOUT_REDO_ANIM}.
   1233      */
   1234     public int finishPostLayoutPolicyLw();
   1235 
   1236     /**
   1237      * Return true if it is okay to perform animations for an app transition
   1238      * that is about to occur. You may return false for this if, for example,
   1239      * the dream window is currently displayed so the switch should happen
   1240      * immediately.
   1241      */
   1242     public boolean allowAppAnimationsLw();
   1243 
   1244     /**
   1245      * A new window has been focused.
   1246      */
   1247     public int focusChangedLw(WindowState lastFocus, WindowState newFocus);
   1248 
   1249     /**
   1250      * Called when the device has started waking up.
   1251      */
   1252     public void startedWakingUp();
   1253 
   1254     /**
   1255      * Called when the device has finished waking up.
   1256      */
   1257     public void finishedWakingUp();
   1258 
   1259     /**
   1260      * Called when the device has started going to sleep.
   1261      *
   1262      * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
   1263      * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
   1264      */
   1265     public void startedGoingToSleep(int why);
   1266 
   1267     /**
   1268      * Called when the device has finished going to sleep.
   1269      *
   1270      * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
   1271      * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
   1272      */
   1273     public void finishedGoingToSleep(int why);
   1274 
   1275     /**
   1276      * Called when the device is about to turn on the screen to show content.
   1277      * When waking up, this method will be called once after the call to wakingUp().
   1278      * When dozing, the method will be called sometime after the call to goingToSleep() and
   1279      * may be called repeatedly in the case where the screen is pulsing on and off.
   1280      *
   1281      * Must call back on the listener to tell it when the higher-level system
   1282      * is ready for the screen to go on (i.e. the lock screen is shown).
   1283      */
   1284     public void screenTurningOn(ScreenOnListener screenOnListener);
   1285 
   1286     /**
   1287      * Called when the device has actually turned on the screen, i.e. the display power state has
   1288      * been set to ON and the screen is unblocked.
   1289      */
   1290     public void screenTurnedOn();
   1291 
   1292     /**
   1293      * Called when the display would like to be turned off. This gives policy a chance to do some
   1294      * things before the display power state is actually changed to off.
   1295      *
   1296      * @param screenOffListener Must be called to tell that the display power state can actually be
   1297      *                          changed now after policy has done its work.
   1298      */
   1299     public void screenTurningOff(ScreenOffListener screenOffListener);
   1300 
   1301     /**
   1302      * Called when the device has turned the screen off.
   1303      */
   1304     public void screenTurnedOff();
   1305 
   1306     public interface ScreenOnListener {
   1307         void onScreenOn();
   1308     }
   1309 
   1310     /**
   1311      * See {@link #screenTurnedOff}
   1312      */
   1313     public interface ScreenOffListener {
   1314         void onScreenOff();
   1315     }
   1316 
   1317     /**
   1318      * Return whether the default display is on and not blocked by a black surface.
   1319      */
   1320     public boolean isScreenOn();
   1321 
   1322     /**
   1323      * @return whether the device is currently allowed to animate.
   1324      *
   1325      * Note: this can be true even if it is not appropriate to animate for reasons that are outside
   1326      *       of the policy's authority.
   1327      */
   1328     boolean okToAnimate();
   1329 
   1330     /**
   1331      * Tell the policy that the lid switch has changed state.
   1332      * @param whenNanos The time when the change occurred in uptime nanoseconds.
   1333      * @param lidOpen True if the lid is now open.
   1334      */
   1335     public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
   1336 
   1337     /**
   1338      * Tell the policy that the camera lens has been covered or uncovered.
   1339      * @param whenNanos The time when the change occurred in uptime nanoseconds.
   1340      * @param lensCovered True if the lens is covered.
   1341      */
   1342     public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered);
   1343 
   1344     /**
   1345      * Tell the policy if anyone is requesting that keyguard not come on.
   1346      *
   1347      * @param enabled Whether keyguard can be on or not.  does not actually
   1348      * turn it on, unless it was previously disabled with this function.
   1349      *
   1350      * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard()
   1351      * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard()
   1352      */
   1353     @SuppressWarnings("javadoc")
   1354     public void enableKeyguard(boolean enabled);
   1355 
   1356     /**
   1357      * Callback used by {@link #exitKeyguardSecurely}
   1358      */
   1359     interface OnKeyguardExitResult {
   1360         void onKeyguardExitResult(boolean success);
   1361     }
   1362 
   1363     /**
   1364      * Tell the policy if anyone is requesting the keyguard to exit securely
   1365      * (this would be called after the keyguard was disabled)
   1366      * @param callback Callback to send the result back.
   1367      * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)
   1368      */
   1369     @SuppressWarnings("javadoc")
   1370     void exitKeyguardSecurely(OnKeyguardExitResult callback);
   1371 
   1372     /**
   1373      * isKeyguardLocked
   1374      *
   1375      * Return whether the keyguard is currently locked.
   1376      *
   1377      * @return true if in keyguard is locked.
   1378      */
   1379     public boolean isKeyguardLocked();
   1380 
   1381     /**
   1382      * isKeyguardSecure
   1383      *
   1384      * Return whether the keyguard requires a password to unlock.
   1385      * @param userId
   1386      *
   1387      * @return true if in keyguard is secure.
   1388      */
   1389     public boolean isKeyguardSecure(int userId);
   1390 
   1391     /**
   1392      * Return whether the keyguard is currently occluded.
   1393      *
   1394      * @return true if in keyguard is occluded, false otherwise
   1395      */
   1396     public boolean isKeyguardOccluded();
   1397 
   1398     /**
   1399      * @return true if in keyguard is on and not occluded.
   1400      */
   1401     public boolean isKeyguardShowingAndNotOccluded();
   1402 
   1403     /**
   1404      * @return whether Keyguard is in trusted state and can be dismissed without credentials
   1405      */
   1406     public boolean isKeyguardTrustedLw();
   1407 
   1408     /**
   1409      * inKeyguardRestrictedKeyInputMode
   1410      *
   1411      * If keyguard screen is showing or in restricted key input mode (i.e. in
   1412      * keyguard password emergency screen). When in such mode, certain keys,
   1413      * such as the Home key and the right soft keys, don't work.
   1414      *
   1415      * @return true if in keyguard restricted input mode.
   1416      */
   1417     public boolean inKeyguardRestrictedKeyInputMode();
   1418 
   1419     /**
   1420      * Ask the policy to dismiss the keyguard, if it is currently shown.
   1421      *
   1422      * @param callback Callback to be informed about the result.
   1423      * @param message A message that should be displayed in the keyguard.
   1424      */
   1425     public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback,
   1426             CharSequence message);
   1427 
   1428     /**
   1429      * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method
   1430      * returns true as soon as we know that Keyguard is disabled.
   1431      *
   1432      * @return true if the keyguard has drawn.
   1433      */
   1434     public boolean isKeyguardDrawnLw();
   1435 
   1436     public boolean isShowingDreamLw();
   1437 
   1438     /**
   1439      * Given an orientation constant, returns the appropriate surface rotation,
   1440      * taking into account sensors, docking mode, rotation lock, and other factors.
   1441      *
   1442      * @param orientation An orientation constant, such as
   1443      * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
   1444      * @param lastRotation The most recently used rotation.
   1445      * @param defaultDisplay Flag indicating whether the rotation is computed for the default
   1446      *                       display. Currently for all non-default displays sensors, docking mode,
   1447      *                       rotation lock and other factors are ignored.
   1448      * @return The surface rotation to use.
   1449      */
   1450     public int rotationForOrientationLw(@ActivityInfo.ScreenOrientation int orientation,
   1451             int lastRotation, boolean defaultDisplay);
   1452 
   1453     /**
   1454      * Given an orientation constant and a rotation, returns true if the rotation
   1455      * has compatible metrics to the requested orientation.  For example, if
   1456      * the application requested landscape and got seascape, then the rotation
   1457      * has compatible metrics; if the application requested portrait and got landscape,
   1458      * then the rotation has incompatible metrics; if the application did not specify
   1459      * a preference, then anything goes.
   1460      *
   1461      * @param orientation An orientation constant, such as
   1462      * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
   1463      * @param rotation The rotation to check.
   1464      * @return True if the rotation is compatible with the requested orientation.
   1465      */
   1466     public boolean rotationHasCompatibleMetricsLw(@ActivityInfo.ScreenOrientation int orientation,
   1467             int rotation);
   1468 
   1469     /**
   1470      * Called by the window manager when the rotation changes.
   1471      *
   1472      * @param rotation The new rotation.
   1473      */
   1474     public void setRotationLw(int rotation);
   1475 
   1476     /**
   1477      * Called when the system is mostly done booting to set whether
   1478      * the system should go into safe mode.
   1479      */
   1480     public void setSafeMode(boolean safeMode);
   1481 
   1482     /**
   1483      * Called when the system is mostly done booting.
   1484      */
   1485     public void systemReady();
   1486 
   1487     /**
   1488      * Called when the system is done booting to the point where the
   1489      * user can start interacting with it.
   1490      */
   1491     public void systemBooted();
   1492 
   1493     /**
   1494      * Show boot time message to the user.
   1495      */
   1496     public void showBootMessage(final CharSequence msg, final boolean always);
   1497 
   1498     /**
   1499      * Hide the UI for showing boot messages, never to be displayed again.
   1500      */
   1501     public void hideBootMessages();
   1502 
   1503     /**
   1504      * Called when userActivity is signalled in the power manager.
   1505      * This is safe to call from any thread, with any window manager locks held or not.
   1506      */
   1507     public void userActivity();
   1508 
   1509     /**
   1510      * Called when we have finished booting and can now display the home
   1511      * screen to the user.  This will happen after systemReady(), and at
   1512      * this point the display is active.
   1513      */
   1514     public void enableScreenAfterBoot();
   1515 
   1516     public void setCurrentOrientationLw(@ActivityInfo.ScreenOrientation int newOrientation);
   1517 
   1518     /**
   1519      * Call from application to perform haptic feedback on its window.
   1520      */
   1521     public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always);
   1522 
   1523     /**
   1524      * Called when we have started keeping the screen on because a window
   1525      * requesting this has become visible.
   1526      */
   1527     public void keepScreenOnStartedLw();
   1528 
   1529     /**
   1530      * Called when we have stopped keeping the screen on because the last window
   1531      * requesting this is no longer visible.
   1532      */
   1533     public void keepScreenOnStoppedLw();
   1534 
   1535     /**
   1536      * Gets the current user rotation mode.
   1537      *
   1538      * @return The rotation mode.
   1539      *
   1540      * @see #USER_ROTATION_LOCKED
   1541      * @see #USER_ROTATION_FREE
   1542      */
   1543     @UserRotationMode
   1544     public int getUserRotationMode();
   1545 
   1546     /**
   1547      * Inform the policy that the user has chosen a preferred orientation ("rotation lock").
   1548      *
   1549      * @param mode One of {@link #USER_ROTATION_LOCKED} or {@link #USER_ROTATION_FREE}.
   1550      * @param rotation One of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90},
   1551      *                 {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270}.
   1552      */
   1553     public void setUserRotationMode(@UserRotationMode int mode, @Surface.Rotation int rotation);
   1554 
   1555     /**
   1556      * Called when a new system UI visibility is being reported, allowing
   1557      * the policy to adjust what is actually reported.
   1558      * @param visibility The raw visibility reported by the status bar.
   1559      * @return The new desired visibility.
   1560      */
   1561     public int adjustSystemUiVisibilityLw(int visibility);
   1562 
   1563     /**
   1564      * Called by System UI to notify of changes to the visibility of Recents.
   1565      */
   1566     public void setRecentsVisibilityLw(boolean visible);
   1567 
   1568     /**
   1569      * Called by System UI to notify of changes to the visibility of PIP.
   1570      */
   1571     void setPipVisibilityLw(boolean visible);
   1572 
   1573     /**
   1574      * Called by System UI to enable or disable haptic feedback on the navigation bar buttons.
   1575      */
   1576     void setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled);
   1577 
   1578     /**
   1579      * Specifies whether there is an on-screen navigation bar separate from the status bar.
   1580      */
   1581     public boolean hasNavigationBar();
   1582 
   1583     /**
   1584      * Lock the device now.
   1585      */
   1586     public void lockNow(Bundle options);
   1587 
   1588     /**
   1589      * Set the last used input method window state. This state is used to make IME transition
   1590      * smooth.
   1591      * @hide
   1592      */
   1593     public void setLastInputMethodWindowLw(WindowState ime, WindowState target);
   1594 
   1595     /**
   1596      * An internal callback (from InputMethodManagerService) to notify a state change regarding
   1597      * whether the back key should dismiss the software keyboard (IME) or not.
   1598      *
   1599      * @param newValue {@code true} if the software keyboard is shown and the back key is expected
   1600      *                 to dismiss the software keyboard.
   1601      * @hide
   1602      */
   1603     default void setDismissImeOnBackKeyPressed(boolean newValue) {
   1604         // Default implementation does nothing.
   1605     }
   1606 
   1607     /**
   1608      * Show the recents task list app.
   1609      * @hide
   1610      */
   1611     public void showRecentApps();
   1612 
   1613     /**
   1614      * Show the global actions dialog.
   1615      * @hide
   1616      */
   1617     public void showGlobalActions();
   1618 
   1619     /**
   1620      * Called when the current user changes. Guaranteed to be called before the broadcast
   1621      * of the new user id is made to all listeners.
   1622      *
   1623      * @param newUserId The id of the incoming user.
   1624      */
   1625     public void setCurrentUserLw(int newUserId);
   1626 
   1627     /**
   1628      * For a given user-switch operation, this will be called once with switching=true before the
   1629      * user-switch and once with switching=false afterwards (or if the user-switch was cancelled).
   1630      * This gives the policy a chance to alter its behavior for the duration of a user-switch.
   1631      *
   1632      * @param switching true if a user-switch is in progress
   1633      */
   1634     void setSwitchingUser(boolean switching);
   1635 
   1636     /**
   1637      * Print the WindowManagerPolicy's state into the given stream.
   1638      *
   1639      * @param prefix Text to print at the front of each line.
   1640      * @param writer The PrintWriter to which you should dump your state.  This will be
   1641      * closed for you after you return.
   1642      * @param args additional arguments to the dump request.
   1643      */
   1644     public void dump(String prefix, PrintWriter writer, String[] args);
   1645 
   1646     /**
   1647      * Write the WindowManagerPolicy's state into the protocol buffer.
   1648      * The message is described in {@link com.android.server.wm.WindowManagerPolicyProto}
   1649      *
   1650      * @param proto The protocol buffer output stream to write to.
   1651      */
   1652     void writeToProto(ProtoOutputStream proto, long fieldId);
   1653 
   1654     /**
   1655      * Returns whether a given window type is considered a top level one.
   1656      * A top level window does not have a container, i.e. attached window,
   1657      * or if it has a container it is laid out as a top-level window, not
   1658      * as a child of its container.
   1659      *
   1660      * @param windowType The window type.
   1661      * @return True if the window is a top level one.
   1662      */
   1663     public boolean isTopLevelWindow(int windowType);
   1664 
   1665     /**
   1666      * Notifies the keyguard to start fading out.
   1667      *
   1668      * @param startTime the start time of the animation in uptime milliseconds
   1669      * @param fadeoutDuration the duration of the exit animation, in milliseconds
   1670      */
   1671     public void startKeyguardExitAnimation(long startTime, long fadeoutDuration);
   1672 
   1673     /**
   1674      * Calculates the stable insets without running a layout.
   1675      *
   1676      * @param displayRotation the current display rotation
   1677      * @param displayWidth the current display width
   1678      * @param displayHeight the current display height
   1679      * @param displayCutout the current display cutout
   1680      * @param outInsets the insets to return
   1681      */
   1682     public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
   1683             DisplayCutout displayCutout, Rect outInsets);
   1684 
   1685 
   1686     /**
   1687      * @return true if the navigation bar is forced to stay visible
   1688      */
   1689     public boolean isNavBarForcedShownLw(WindowState win);
   1690 
   1691     /**
   1692      * @return The side of the screen where navigation bar is positioned.
   1693      * @see #NAV_BAR_LEFT
   1694      * @see #NAV_BAR_RIGHT
   1695      * @see #NAV_BAR_BOTTOM
   1696      */
   1697     @NavigationBarPosition
   1698     int getNavBarPosition();
   1699 
   1700     /**
   1701      * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system
   1702      * bar or button bar. See {@link #getNonDecorDisplayWidth}.
   1703      *
   1704      * @param displayRotation the current display rotation
   1705      * @param displayWidth the current display width
   1706      * @param displayHeight the current display height
   1707      * @param displayCutout the current display cutout
   1708      * @param outInsets the insets to return
   1709      */
   1710     public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
   1711             DisplayCutout displayCutout, Rect outInsets);
   1712 
   1713     /**
   1714      * @param displayRotation the current display rotation
   1715      * @param displayWidth the current display width
   1716      * @param displayHeight the current display height
   1717      * @param dockSide the dockside asking if allowed
   1718      * @param originalDockSide the side that was original docked to in split screen
   1719      * @return True if a specified {@param dockSide} is allowed on the current device, or false
   1720      *         otherwise. It is guaranteed that at least one dock side for a particular orientation
   1721      *         is allowed, so for example, if DOCKED_RIGHT is not allowed, DOCKED_LEFT is allowed.
   1722      *         If navigation bar is movable then the docked side would bias towards the
   1723      *         {@param originalDockSide}.
   1724      */
   1725     public boolean isDockSideAllowed(int dockSide, int originalDockSide, int displayWidth,
   1726             int displayHeight, int displayRotation);
   1727 
   1728     /**
   1729      * Called when the configuration has changed, and it's safe to load new values from resources.
   1730      */
   1731     public void onConfigurationChanged();
   1732 
   1733     public boolean shouldRotateSeamlessly(int oldRotation, int newRotation);
   1734 
   1735     /**
   1736      * Called when System UI has been started.
   1737      */
   1738     void onSystemUiStarted();
   1739 
   1740     /**
   1741      * Checks whether the policy is ready for dismissing the boot animation and completing the boot.
   1742      *
   1743      * @return true if ready; false otherwise.
   1744      */
   1745     boolean canDismissBootAnimation();
   1746 
   1747     /**
   1748      * Convert the user rotation mode to a human readable format.
   1749      */
   1750     static String userRotationModeToString(int mode) {
   1751         switch(mode) {
   1752             case USER_ROTATION_FREE:
   1753                 return "USER_ROTATION_FREE";
   1754             case USER_ROTATION_LOCKED:
   1755                 return "USER_ROTATION_LOCKED";
   1756             default:
   1757                 return Integer.toString(mode);
   1758         }
   1759     }
   1760 
   1761     /**
   1762      * Requests that the WindowManager sends WindowManagerPolicy#ACTION_USER_ACTIVITY_NOTIFICATION
   1763      * on the next user activity.
   1764      */
   1765     public void requestUserActivityNotification();
   1766 
   1767     /**
   1768      * Called when the state of lock task mode changes. This should be used to disable immersive
   1769      * mode confirmation.
   1770      *
   1771      * @param lockTaskState the new lock task mode state. One of
   1772      *                      {@link ActivityManager#LOCK_TASK_MODE_NONE},
   1773      *                      {@link ActivityManager#LOCK_TASK_MODE_LOCKED},
   1774      *                      {@link ActivityManager#LOCK_TASK_MODE_PINNED}.
   1775      */
   1776     void onLockTaskStateChangedLw(int lockTaskState);
   1777 
   1778     /**
   1779      * Updates the flag about whether AOD is showing.
   1780      *
   1781      * @return whether the value was changed.
   1782      */
   1783     boolean setAodShowing(boolean aodShowing);
   1784 }
   1785