Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2006 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 android.view;
     18 
     19 import android.content.Context;
     20 import android.content.res.Configuration;
     21 import android.graphics.Rect;
     22 import android.os.IBinder;
     23 import android.os.LocalPowerManager;
     24 import android.view.animation.Animation;
     25 
     26 /**
     27  * This interface supplies all UI-specific behavior of the window manager.  An
     28  * instance of it is created by the window manager when it starts up, and allows
     29  * customization of window layering, special window types, key dispatching, and
     30  * layout.
     31  *
     32  * <p>Because this provides deep interaction with the system window manager,
     33  * specific methods on this interface can be called from a variety of contexts
     34  * with various restrictions on what they can do.  These are encoded through
     35  * a suffixes at the end of a method encoding the thread the method is called
     36  * from and any locks that are held when it is being called; if no suffix
     37  * is attached to a method, then it is not called with any locks and may be
     38  * called from the main window manager thread or another thread calling into
     39  * the window manager.
     40  *
     41  * <p>The current suffixes are:
     42  *
     43  * <dl>
     44  * <dt> Ti <dd> Called from the input thread.  This is the thread that
     45  * collects pending input events and dispatches them to the appropriate window.
     46  * It may block waiting for events to be processed, so that the input stream is
     47  * properly serialized.
     48  * <dt> Tq <dd> Called from the low-level input queue thread.  This is the
     49  * thread that reads events out of the raw input devices and places them
     50  * into the global input queue that is read by the <var>Ti</var> thread.
     51  * This thread should not block for a long period of time on anything but the
     52  * key driver.
     53  * <dt> Lw <dd> Called with the main window manager lock held.  Because the
     54  * window manager is a very low-level system service, there are few other
     55  * system services you can call with this lock held.  It is explicitly okay to
     56  * make calls into the package manager and power manager; it is explicitly not
     57  * okay to make calls into the activity manager or most other services.  Note that
     58  * {@link android.content.Context#checkPermission(String, int, int)} and
     59  * variations require calling into the activity manager.
     60  * <dt> Li <dd> Called with the input thread lock held.  This lock can be
     61  * acquired by the window manager while it holds the window lock, so this is
     62  * even more restrictive than <var>Lw</var>.
     63  * </dl>
     64  *
     65  * @hide
     66  */
     67 public interface WindowManagerPolicy {
     68     // Policy flags.  These flags are also defined in frameworks/base/include/ui/Input.h.
     69     public final static int FLAG_WAKE = 0x00000001;
     70     public final static int FLAG_WAKE_DROPPED = 0x00000002;
     71     public final static int FLAG_SHIFT = 0x00000004;
     72     public final static int FLAG_CAPS_LOCK = 0x00000008;
     73     public final static int FLAG_ALT = 0x00000010;
     74     public final static int FLAG_ALT_GR = 0x00000020;
     75     public final static int FLAG_MENU = 0x00000040;
     76     public final static int FLAG_LAUNCHER = 0x00000080;
     77     public final static int FLAG_VIRTUAL = 0x00000100;
     78 
     79     public final static int FLAG_INJECTED = 0x01000000;
     80     public final static int FLAG_TRUSTED = 0x02000000;
     81 
     82     public final static int FLAG_WOKE_HERE = 0x10000000;
     83     public final static int FLAG_BRIGHT_HERE = 0x20000000;
     84     public final static int FLAG_PASS_TO_USER = 0x40000000;
     85 
     86     public final static boolean WATCH_POINTER = false;
     87 
     88     // flags for interceptKeyTq
     89     /**
     90      * Pass this event to the user / app.  To be returned from {@link #interceptKeyTq}.
     91      */
     92     public final static int ACTION_PASS_TO_USER = 0x00000001;
     93 
     94     /**
     95      * This key event should extend the user activity timeout and turn the lights on.
     96      * To be returned from {@link #interceptKeyTq}. Do not return this and
     97      * {@link #ACTION_GO_TO_SLEEP} or {@link #ACTION_PASS_TO_USER}.
     98      */
     99     public final static int ACTION_POKE_USER_ACTIVITY = 0x00000002;
    100 
    101     /**
    102      * This key event should put the device to sleep (and engage keyguard if necessary)
    103      * To be returned from {@link #interceptKeyTq}.  Do not return this and
    104      * {@link #ACTION_POKE_USER_ACTIVITY} or {@link #ACTION_PASS_TO_USER}.
    105      */
    106     public final static int ACTION_GO_TO_SLEEP = 0x00000004;
    107 
    108     /**
    109      * Interface to the Window Manager state associated with a particular
    110      * window.  You can hold on to an instance of this interface from the call
    111      * to prepareAddWindow() until removeWindow().
    112      */
    113     public interface WindowState {
    114         /**
    115          * Perform standard frame computation.  The result can be obtained with
    116          * getFrame() if so desired.  Must be called with the window manager
    117          * lock held.
    118          *
    119          * @param parentFrame The frame of the parent container this window
    120          * is in, used for computing its basic position.
    121          * @param displayFrame The frame of the overall display in which this
    122          * window can appear, used for constraining the overall dimensions
    123          * of the window.
    124          * @param contentFrame The frame within the display in which we would
    125          * like active content to appear.  This will cause windows behind to
    126          * be resized to match the given content frame.
    127          * @param visibleFrame The frame within the display that the window
    128          * is actually visible, used for computing its visible insets to be
    129          * given to windows behind.
    130          * This can be used as a hint for scrolling (avoiding resizing)
    131          * the window to make certain that parts of its content
    132          * are visible.
    133          */
    134         public void computeFrameLw(Rect parentFrame, Rect displayFrame,
    135                 Rect contentFrame, Rect visibleFrame);
    136 
    137         /**
    138          * Retrieve the current frame of the window that has been assigned by
    139          * the window manager.  Must be called with the window manager lock held.
    140          *
    141          * @return Rect The rectangle holding the window frame.
    142          */
    143         public Rect getFrameLw();
    144 
    145         /**
    146          * Retrieve the current frame of the window that is actually shown.
    147          * Must be called with the window manager lock held.
    148          *
    149          * @return Rect The rectangle holding the shown window frame.
    150          */
    151         public Rect getShownFrameLw();
    152 
    153         /**
    154          * Retrieve the frame of the display that this window was last
    155          * laid out in.  Must be called with the
    156          * window manager lock held.
    157          *
    158          * @return Rect The rectangle holding the display frame.
    159          */
    160         public Rect getDisplayFrameLw();
    161 
    162         /**
    163          * Retrieve the frame of the content area that this window was last
    164          * laid out in.  This is the area in which the content of the window
    165          * should be placed.  It will be smaller than the display frame to
    166          * account for screen decorations such as a status bar or soft
    167          * keyboard.  Must be called with the
    168          * window manager lock held.
    169          *
    170          * @return Rect The rectangle holding the content frame.
    171          */
    172         public Rect getContentFrameLw();
    173 
    174         /**
    175          * Retrieve the frame of the visible area that this window was last
    176          * laid out in.  This is the area of the screen in which the window
    177          * will actually be fully visible.  It will be smaller than the
    178          * content frame to account for transient UI elements blocking it
    179          * such as an input method's candidates UI.  Must be called with the
    180          * window manager lock held.
    181          *
    182          * @return Rect The rectangle holding the visible frame.
    183          */
    184         public Rect getVisibleFrameLw();
    185 
    186         /**
    187          * Returns true if this window is waiting to receive its given
    188          * internal insets from the client app, and so should not impact the
    189          * layout of other windows.
    190          */
    191         public boolean getGivenInsetsPendingLw();
    192 
    193         /**
    194          * Retrieve the insets given by this window's client for the content
    195          * area of windows behind it.  Must be called with the
    196          * window manager lock held.
    197          *
    198          * @return Rect The left, top, right, and bottom insets, relative
    199          * to the window's frame, of the actual contents.
    200          */
    201         public Rect getGivenContentInsetsLw();
    202 
    203         /**
    204          * Retrieve the insets given by this window's client for the visible
    205          * area of windows behind it.  Must be called with the
    206          * window manager lock held.
    207          *
    208          * @return Rect The left, top, right, and bottom insets, relative
    209          * to the window's frame, of the actual visible area.
    210          */
    211         public Rect getGivenVisibleInsetsLw();
    212 
    213         /**
    214          * Retrieve the current LayoutParams of the window.
    215          *
    216          * @return WindowManager.LayoutParams The window's internal LayoutParams
    217          *         instance.
    218          */
    219         public WindowManager.LayoutParams getAttrs();
    220 
    221         /**
    222          * Get the layer at which this window's surface will be Z-ordered.
    223          */
    224         public int getSurfaceLayer();
    225 
    226         /**
    227          * Return the token for the application (actually activity) that owns
    228          * this window.  May return null for system windows.
    229          *
    230          * @return An IApplicationToken identifying the owning activity.
    231          */
    232         public IApplicationToken getAppToken();
    233 
    234         /**
    235          * Return true if, at any point, the application token associated with
    236          * this window has actually displayed any windows.  This is most useful
    237          * with the "starting up" window to determine if any windows were
    238          * displayed when it is closed.
    239          *
    240          * @return Returns true if one or more windows have been displayed,
    241          *         else false.
    242          */
    243         public boolean hasAppShownWindows();
    244 
    245         /**
    246          * Is this window visible?  It is not visible if there is no
    247          * surface, or we are in the process of running an exit animation
    248          * that will remove the surface.
    249          */
    250         boolean isVisibleLw();
    251 
    252         /**
    253          * Like {@link #isVisibleLw}, but also counts a window that is currently
    254          * "hidden" behind the keyguard as visible.  This allows us to apply
    255          * things like window flags that impact the keyguard.
    256          */
    257         boolean isVisibleOrBehindKeyguardLw();
    258 
    259         /**
    260          * Is this window currently visible to the user on-screen?  It is
    261          * displayed either if it is visible or it is currently running an
    262          * animation before no longer being visible.  Must be called with the
    263          * window manager lock held.
    264          */
    265         boolean isDisplayedLw();
    266 
    267         /**
    268          * Returns true if this window has been shown on screen at some time in
    269          * the past.  Must be called with the window manager lock held.
    270          *
    271          * @return boolean
    272          */
    273         public boolean hasDrawnLw();
    274 
    275         /**
    276          * Can be called by the policy to force a window to be hidden,
    277          * regardless of whether the client or window manager would like
    278          * it shown.  Must be called with the window manager lock held.
    279          * Returns true if {@link #showLw} was last called for the window.
    280          */
    281         public boolean hideLw(boolean doAnimation);
    282 
    283         /**
    284          * Can be called to undo the effect of {@link #hideLw}, allowing a
    285          * window to be shown as long as the window manager and client would
    286          * also like it to be shown.  Must be called with the window manager
    287          * lock held.
    288          * Returns true if {@link #hideLw} was last called for the window.
    289          */
    290         public boolean showLw(boolean doAnimation);
    291     }
    292 
    293     /**
    294      * Bit mask that is set for all enter transition.
    295      */
    296     public final int TRANSIT_ENTER_MASK = 0x1000;
    297 
    298     /**
    299      * Bit mask that is set for all exit transitions.
    300      */
    301     public final int TRANSIT_EXIT_MASK = 0x2000;
    302 
    303     /** Not set up for a transition. */
    304     public final int TRANSIT_UNSET = -1;
    305     /** No animation for transition. */
    306     public final int TRANSIT_NONE = 0;
    307     /** Window has been added to the screen. */
    308     public final int TRANSIT_ENTER = 1 | TRANSIT_ENTER_MASK;
    309     /** Window has been removed from the screen. */
    310     public final int TRANSIT_EXIT = 2 | TRANSIT_EXIT_MASK;
    311     /** Window has been made visible. */
    312     public final int TRANSIT_SHOW = 3 | TRANSIT_ENTER_MASK;
    313     /** Window has been made invisible. */
    314     public final int TRANSIT_HIDE = 4 | TRANSIT_EXIT_MASK;
    315     /** The "application starting" preview window is no longer needed, and will
    316      * animate away to show the real window. */
    317     public final int TRANSIT_PREVIEW_DONE = 5;
    318     /** A window in a new activity is being opened on top of an existing one
    319      * in the same task. */
    320     public final int TRANSIT_ACTIVITY_OPEN = 6 | TRANSIT_ENTER_MASK;
    321     /** The window in the top-most activity is being closed to reveal the
    322      * previous activity in the same task. */
    323     public final int TRANSIT_ACTIVITY_CLOSE = 7 | TRANSIT_EXIT_MASK;
    324     /** A window in a new task is being opened on top of an existing one
    325      * in another activity's task. */
    326     public final int TRANSIT_TASK_OPEN = 8 | TRANSIT_ENTER_MASK;
    327     /** A window in the top-most activity is being closed to reveal the
    328      * previous activity in a different task. */
    329     public final int TRANSIT_TASK_CLOSE = 9 | TRANSIT_EXIT_MASK;
    330     /** A window in an existing task is being displayed on top of an existing one
    331      * in another activity's task. */
    332     public final int TRANSIT_TASK_TO_FRONT = 10 | TRANSIT_ENTER_MASK;
    333     /** A window in an existing task is being put below all other tasks. */
    334     public final int TRANSIT_TASK_TO_BACK = 11 | TRANSIT_EXIT_MASK;
    335     /** A window in a new activity that doesn't have a wallpaper is being
    336      * opened on top of one that does, effectively closing the wallpaper. */
    337     public final int TRANSIT_WALLPAPER_CLOSE = 12 | TRANSIT_EXIT_MASK;
    338     /** A window in a new activity that does have a wallpaper is being
    339      * opened on one that didn't, effectively opening the wallpaper. */
    340     public final int TRANSIT_WALLPAPER_OPEN = 13 | TRANSIT_ENTER_MASK;
    341     /** A window in a new activity is being opened on top of an existing one,
    342      * and both are on top of the wallpaper. */
    343     public final int TRANSIT_WALLPAPER_INTRA_OPEN = 14 | TRANSIT_ENTER_MASK;
    344     /** The window in the top-most activity is being closed to reveal the
    345      * previous activity, and both are on top of he wallpaper. */
    346     public final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15 | TRANSIT_EXIT_MASK;
    347 
    348     // NOTE: screen off reasons are in order of significance, with more
    349     // important ones lower than less important ones.
    350 
    351     /** Screen turned off because of a device admin */
    352     public final int OFF_BECAUSE_OF_ADMIN = 1;
    353     /** Screen turned off because of power button */
    354     public final int OFF_BECAUSE_OF_USER = 2;
    355     /** Screen turned off because of timeout */
    356     public final int OFF_BECAUSE_OF_TIMEOUT = 3;
    357     /** Screen turned off because of proximity sensor */
    358     public final int OFF_BECAUSE_OF_PROX_SENSOR = 4;
    359 
    360     /**
    361      * Magic constant to {@link IWindowManager#setRotation} to not actually
    362      * modify the rotation.
    363      */
    364     public final int USE_LAST_ROTATION = -1000;
    365 
    366     /**
    367      * Perform initialization of the policy.
    368      *
    369      * @param context The system context we are running in.
    370      * @param powerManager
    371      */
    372     public void init(Context context, IWindowManager windowManager,
    373             LocalPowerManager powerManager);
    374 
    375     /**
    376      * Check permissions when adding a window.
    377      *
    378      * @param attrs The window's LayoutParams.
    379      *
    380      * @return {@link WindowManagerImpl#ADD_OKAY} if the add can proceed;
    381      *      else an error code, usually
    382      *      {@link WindowManagerImpl#ADD_PERMISSION_DENIED}, to abort the add.
    383      */
    384     public int checkAddPermission(WindowManager.LayoutParams attrs);
    385 
    386     /**
    387      * Sanitize the layout parameters coming from a client.  Allows the policy
    388      * to do things like ensure that windows of a specific type can't take
    389      * input focus.
    390      *
    391      * @param attrs The window layout parameters to be modified.  These values
    392      * are modified in-place.
    393      */
    394     public void adjustWindowParamsLw(WindowManager.LayoutParams attrs);
    395 
    396     /**
    397      * After the window manager has computed the current configuration based
    398      * on its knowledge of the display and input devices, it gives the policy
    399      * a chance to adjust the information contained in it.  If you want to
    400      * leave it as-is, simply do nothing.
    401      *
    402      * <p>This method may be called by any thread in the window manager, but
    403      * no internal locks in the window manager will be held.
    404      *
    405      * @param config The Configuration being computed, for you to change as
    406      * desired.
    407      */
    408     public void adjustConfigurationLw(Configuration config);
    409 
    410     /**
    411      * Assign a window type to a layer.  Allows you to control how different
    412      * kinds of windows are ordered on-screen.
    413      *
    414      * @param type The type of window being assigned.
    415      *
    416      * @return int An arbitrary integer used to order windows, with lower
    417      *         numbers below higher ones.
    418      */
    419     public int windowTypeToLayerLw(int type);
    420 
    421     /**
    422      * Return how to Z-order sub-windows in relation to the window they are
    423      * attached to.  Return positive to have them ordered in front, negative for
    424      * behind.
    425      *
    426      * @param type The sub-window type code.
    427      *
    428      * @return int Layer in relation to the attached window, where positive is
    429      *         above and negative is below.
    430      */
    431     public int subWindowTypeToLayerLw(int type);
    432 
    433     /**
    434      * Get the highest layer (actually one more than) that the wallpaper is
    435      * allowed to be in.
    436      */
    437     public int getMaxWallpaperLayer();
    438 
    439     /**
    440      * Return whether the given window should forcibly hide everything
    441      * behind it.  Typically returns true for the keyguard.
    442      */
    443     public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs);
    444 
    445     /**
    446      * Determine if a window that is behind one that is force hiding
    447      * (as determined by {@link #doesForceHide}) should actually be hidden.
    448      * For example, typically returns false for the status bar.  Be careful
    449      * to return false for any window that you may hide yourself, since this
    450      * will conflict with what you set.
    451      */
    452     public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs);
    453 
    454     /**
    455      * Called when the system would like to show a UI to indicate that an
    456      * application is starting.  You can use this to add a
    457      * APPLICATION_STARTING_TYPE window with the given appToken to the window
    458      * manager (using the normal window manager APIs) that will be shown until
    459      * the application displays its own window.  This is called without the
    460      * window manager locked so that you can call back into it.
    461      *
    462      * @param appToken Token of the application being started.
    463      * @param packageName The name of the application package being started.
    464      * @param theme Resource defining the application's overall visual theme.
    465      * @param nonLocalizedLabel The default title label of the application if
    466      *        no data is found in the resource.
    467      * @param labelRes The resource ID the application would like to use as its name.
    468      * @param icon The resource ID the application would like to use as its icon.
    469      *
    470      * @return Optionally you can return the View that was used to create the
    471      *         window, for easy removal in removeStartingWindow.
    472      *
    473      * @see #removeStartingWindow
    474      */
    475     public View addStartingWindow(IBinder appToken, String packageName,
    476             int theme, CharSequence nonLocalizedLabel,
    477             int labelRes, int icon);
    478 
    479     /**
    480      * Called when the first window of an application has been displayed, while
    481      * {@link #addStartingWindow} has created a temporary initial window for
    482      * that application.  You should at this point remove the window from the
    483      * window manager.  This is called without the window manager locked so
    484      * that you can call back into it.
    485      *
    486      * <p>Note: due to the nature of these functions not being called with the
    487      * window manager locked, you must be prepared for this function to be
    488      * called multiple times and/or an initial time with a null View window
    489      * even if you previously returned one.
    490      *
    491      * @param appToken Token of the application that has started.
    492      * @param window Window View that was returned by createStartingWindow.
    493      *
    494      * @see #addStartingWindow
    495      */
    496     public void removeStartingWindow(IBinder appToken, View window);
    497 
    498     /**
    499      * Prepare for a window being added to the window manager.  You can throw an
    500      * exception here to prevent the window being added, or do whatever setup
    501      * you need to keep track of the window.
    502      *
    503      * @param win The window being added.
    504      * @param attrs The window's LayoutParams.
    505      *
    506      * @return {@link WindowManagerImpl#ADD_OKAY} if the add can proceed, else an
    507      *         error code to abort the add.
    508      */
    509     public int prepareAddWindowLw(WindowState win,
    510             WindowManager.LayoutParams attrs);
    511 
    512     /**
    513      * Called when a window is being removed from a window manager.  Must not
    514      * throw an exception -- clean up as much as possible.
    515      *
    516      * @param win The window being removed.
    517      */
    518     public void removeWindowLw(WindowState win);
    519 
    520     /**
    521      * Control the animation to run when a window's state changes.  Return a
    522      * non-0 number to force the animation to a specific resource ID, or 0
    523      * to use the default animation.
    524      *
    525      * @param win The window that is changing.
    526      * @param transit What is happening to the window: {@link #TRANSIT_ENTER},
    527      *                {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or
    528      *                {@link #TRANSIT_HIDE}.
    529      *
    530      * @return Resource ID of the actual animation to use, or 0 for none.
    531      */
    532     public int selectAnimationLw(WindowState win, int transit);
    533 
    534     /**
    535      * Create and return an animation to re-display a force hidden window.
    536      */
    537     public Animation createForceHideEnterAnimation();
    538 
    539     /**
    540      * Called from the input reader thread before a key is enqueued.
    541      *
    542      * <p>There are some actions that need to be handled here because they
    543      * affect the power state of the device, for example, the power keys.
    544      * Generally, it's best to keep as little as possible in the queue thread
    545      * because it's the most fragile.
    546      * @param whenNanos The event time in uptime nanoseconds.
    547      * @param action The key event action.
    548      * @param flags The key event flags.
    549      * @param keyCode The key code.
    550      * @param scanCode The key's scan code.
    551      * @param policyFlags The policy flags associated with the key.
    552      * @param isScreenOn True if the screen is already on
    553      *
    554      * @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
    555      *          {@link #ACTION_POKE_USER_ACTIVITY} and {@link #ACTION_GO_TO_SLEEP} flags.
    556      */
    557     public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
    558             int keyCode, int scanCode, int policyFlags, boolean isScreenOn);
    559 
    560     /**
    561      * Called from the input dispatcher thread before a key is dispatched to a window.
    562      *
    563      * <p>Allows you to define
    564      * behavior for keys that can not be overridden by applications or redirect
    565      * key events to a different window.  This method is called from the
    566      * input thread, with no locks held.
    567      *
    568      * <p>Note that if you change the window a key is dispatched to, the new
    569      * target window will receive the key event without having input focus.
    570      *
    571      * @param win The window that currently has focus.  This is where the key
    572      *            event will normally go.
    573      * @param action The key event action.
    574      * @param flags The key event flags.
    575      * @param keyCode The key code.
    576      * @param scanCode The key's scan code.
    577      * @param metaState bit mask of meta keys that are held.
    578      * @param repeatCount Number of times a key down has repeated.
    579      * @param policyFlags The policy flags associated with the key.
    580      * @return Returns true if the policy consumed the event and it should
    581      * not be further dispatched.
    582      */
    583     public boolean interceptKeyBeforeDispatching(WindowState win, int action, int flags,
    584             int keyCode, int scanCode, int metaState, int repeatCount, int policyFlags);
    585 
    586     /**
    587      * Called when layout of the windows is about to start.
    588      *
    589      * @param displayWidth The current full width of the screen.
    590      * @param displayHeight The current full height of the screen.
    591      */
    592     public void beginLayoutLw(int displayWidth, int displayHeight);
    593 
    594     /**
    595      * Called for each window attached to the window manager as layout is
    596      * proceeding.  The implementation of this function must take care of
    597      * setting the window's frame, either here or in finishLayout().
    598      *
    599      * @param win The window being positioned.
    600      * @param attrs The LayoutParams of the window.
    601      * @param attached For sub-windows, the window it is attached to; this
    602      *                 window will already have had layoutWindow() called on it
    603      *                 so you can use its Rect.  Otherwise null.
    604      */
    605     public void layoutWindowLw(WindowState win,
    606             WindowManager.LayoutParams attrs, WindowState attached);
    607 
    608 
    609     /**
    610      * Return the insets for the areas covered by system windows. These values
    611      * are computed on the most recent layout, so they are not guaranteed to
    612      * be correct.
    613      *
    614      * @param attrs The LayoutParams of the window.
    615      * @param contentInset The areas covered by system windows, expressed as positive insets
    616      *
    617      */
    618     public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset);
    619 
    620     /**
    621      * Called when layout of the windows is finished.  After this function has
    622      * returned, all windows given to layoutWindow() <em>must</em> have had a
    623      * frame assigned.
    624      *
    625      * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT},
    626      * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER},
    627      * or {@link #FINISH_LAYOUT_REDO_ANIM}.
    628      */
    629     public int finishLayoutLw();
    630 
    631     /** Layout state may have changed (so another layout will be performed) */
    632     static final int FINISH_LAYOUT_REDO_LAYOUT = 0x0001;
    633     /** Configuration state may have changed */
    634     static final int FINISH_LAYOUT_REDO_CONFIG = 0x0002;
    635     /** Wallpaper may need to move */
    636     static final int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004;
    637     /** Need to recompute animations */
    638     static final int FINISH_LAYOUT_REDO_ANIM = 0x0008;
    639 
    640     /**
    641      * Called when animation of the windows is about to start.
    642      *
    643      * @param displayWidth The current full width of the screen.
    644      * @param displayHeight The current full height of the screen.
    645      */
    646     public void beginAnimationLw(int displayWidth, int displayHeight);
    647 
    648     /**
    649      * Called each time a window is animating.
    650      *
    651      * @param win The window being positioned.
    652      * @param attrs The LayoutParams of the window.
    653      */
    654     public void animatingWindowLw(WindowState win,
    655             WindowManager.LayoutParams attrs);
    656 
    657     /**
    658      * Called when animation of the windows is finished.  If in this function you do
    659      * something that may have modified the animation state of another window,
    660      * be sure to return true in order to perform another animation frame.
    661      *
    662      * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT},
    663      * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER},
    664      * or {@link #FINISH_LAYOUT_REDO_ANIM}.
    665      */
    666     public int finishAnimationLw();
    667 
    668     /**
    669      * Return true if it is okay to perform animations for an app transition
    670      * that is about to occur.  You may return false for this if, for example,
    671      * the lock screen is currently displayed so the switch should happen
    672      * immediately.
    673      */
    674     public boolean allowAppAnimationsLw();
    675 
    676     /**
    677      * Called after the screen turns off.
    678      *
    679      * @param why {@link #OFF_BECAUSE_OF_USER} or
    680      * {@link #OFF_BECAUSE_OF_TIMEOUT}.
    681      */
    682     public void screenTurnedOff(int why);
    683 
    684     /**
    685      * Called after the screen turns on.
    686      */
    687     public void screenTurnedOn();
    688 
    689     /**
    690      * Return whether the screen is currently on.
    691      */
    692     public boolean isScreenOn();
    693 
    694     /**
    695      * Tell the policy that the lid switch has changed state.
    696      * @param whenNanos The time when the change occurred in uptime nanoseconds.
    697      * @param lidOpen True if the lid is now open.
    698      */
    699     public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
    700 
    701     /**
    702      * Tell the policy if anyone is requesting that keyguard not come on.
    703      *
    704      * @param enabled Whether keyguard can be on or not.  does not actually
    705      * turn it on, unless it was previously disabled with this function.
    706      *
    707      * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard()
    708      * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard()
    709      */
    710     public void enableKeyguard(boolean enabled);
    711 
    712     /**
    713      * Callback used by {@link WindowManagerPolicy#exitKeyguardSecurely}
    714      */
    715     interface OnKeyguardExitResult {
    716         void onKeyguardExitResult(boolean success);
    717     }
    718 
    719     /**
    720      * Tell the policy if anyone is requesting the keyguard to exit securely
    721      * (this would be called after the keyguard was disabled)
    722      * @param callback Callback to send the result back.
    723      * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)
    724      */
    725     void exitKeyguardSecurely(OnKeyguardExitResult callback);
    726 
    727     /**
    728      * inKeyguardRestrictedKeyInputMode
    729      *
    730      * if keyguard screen is showing or in restricted key input mode (i.e. in
    731      * keyguard password emergency screen). When in such mode, certain keys,
    732      * such as the Home key and the right soft keys, don't work.
    733      *
    734      * @return true if in keyguard restricted input mode.
    735      */
    736     public boolean inKeyguardRestrictedKeyInputMode();
    737 
    738     /**
    739      * Given an orientation constant
    740      * ({@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE
    741      * ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE} or
    742      * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_PORTRAIT
    743      * ActivityInfo.SCREEN_ORIENTATION_PORTRAIT}), return a surface
    744      * rotation.
    745      */
    746     public int rotationForOrientationLw(int orientation, int lastRotation,
    747             boolean displayEnabled);
    748 
    749     /**
    750      * Called when the system is mostly done booting to determine whether
    751      * the system should go into safe mode.
    752      */
    753     public boolean detectSafeMode();
    754 
    755     /**
    756      * Called when the system is mostly done booting.
    757      */
    758     public void systemReady();
    759 
    760     /**
    761      * Called when userActivity is signalled in the power manager.
    762      * This is safe to call from any thread, with any window manager locks held or not.
    763      */
    764     public void userActivity();
    765 
    766     /**
    767      * Called when we have finished booting and can now display the home
    768      * screen to the user.  This wilWl happen after systemReady(), and at
    769      * this point the display is active.
    770      */
    771     public void enableScreenAfterBoot();
    772 
    773     public void setCurrentOrientationLw(int newOrientation);
    774 
    775     /**
    776      * Call from application to perform haptic feedback on its window.
    777      */
    778     public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always);
    779 
    780     /**
    781      * Called when we have stopped keeping the screen on because a window
    782      * requesting this is no longer visible.
    783      */
    784     public void screenOnStoppedLw();
    785 
    786     /**
    787      * Return false to disable key repeat events from being generated.
    788      */
    789     public boolean allowKeyRepeat();
    790 }
    791