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.CompatibilityInfo;
     21 import android.content.res.Configuration;
     22 import android.graphics.Rect;
     23 import android.graphics.RectF;
     24 import android.os.IBinder;
     25 import android.os.LocalPowerManager;
     26 import android.os.Looper;
     27 import android.view.animation.Animation;
     28 
     29 import java.io.FileDescriptor;
     30 import java.io.PrintWriter;
     31 
     32 /**
     33  * This interface supplies all UI-specific behavior of the window manager.  An
     34  * instance of it is created by the window manager when it starts up, and allows
     35  * customization of window layering, special window types, key dispatching, and
     36  * layout.
     37  *
     38  * <p>Because this provides deep interaction with the system window manager,
     39  * specific methods on this interface can be called from a variety of contexts
     40  * with various restrictions on what they can do.  These are encoded through
     41  * a suffixes at the end of a method encoding the thread the method is called
     42  * from and any locks that are held when it is being called; if no suffix
     43  * is attached to a method, then it is not called with any locks and may be
     44  * called from the main window manager thread or another thread calling into
     45  * the window manager.
     46  *
     47  * <p>The current suffixes are:
     48  *
     49  * <dl>
     50  * <dt> Ti <dd> Called from the input thread.  This is the thread that
     51  * collects pending input events and dispatches them to the appropriate window.
     52  * It may block waiting for events to be processed, so that the input stream is
     53  * properly serialized.
     54  * <dt> Tq <dd> Called from the low-level input queue thread.  This is the
     55  * thread that reads events out of the raw input devices and places them
     56  * into the global input queue that is read by the <var>Ti</var> thread.
     57  * This thread should not block for a long period of time on anything but the
     58  * key driver.
     59  * <dt> Lw <dd> Called with the main window manager lock held.  Because the
     60  * window manager is a very low-level system service, there are few other
     61  * system services you can call with this lock held.  It is explicitly okay to
     62  * make calls into the package manager and power manager; it is explicitly not
     63  * okay to make calls into the activity manager or most other services.  Note that
     64  * {@link android.content.Context#checkPermission(String, int, int)} and
     65  * variations require calling into the activity manager.
     66  * <dt> Li <dd> Called with the input thread lock held.  This lock can be
     67  * acquired by the window manager while it holds the window lock, so this is
     68  * even more restrictive than <var>Lw</var>.
     69  * </dl>
     70  *
     71  * @hide
     72  */
     73 public interface WindowManagerPolicy {
     74     // Policy flags.  These flags are also defined in frameworks/base/include/ui/Input.h.
     75     public final static int FLAG_WAKE = 0x00000001;
     76     public final static int FLAG_WAKE_DROPPED = 0x00000002;
     77     public final static int FLAG_SHIFT = 0x00000004;
     78     public final static int FLAG_CAPS_LOCK = 0x00000008;
     79     public final static int FLAG_ALT = 0x00000010;
     80     public final static int FLAG_ALT_GR = 0x00000020;
     81     public final static int FLAG_MENU = 0x00000040;
     82     public final static int FLAG_LAUNCHER = 0x00000080;
     83     public final static int FLAG_VIRTUAL = 0x00000100;
     84 
     85     public final static int FLAG_INJECTED = 0x01000000;
     86     public final static int FLAG_TRUSTED = 0x02000000;
     87     public final static int FLAG_FILTERED = 0x04000000;
     88     public final static int FLAG_DISABLE_KEY_REPEAT = 0x08000000;
     89 
     90     public final static int FLAG_WOKE_HERE = 0x10000000;
     91     public final static int FLAG_BRIGHT_HERE = 0x20000000;
     92     public final static int FLAG_PASS_TO_USER = 0x40000000;
     93 
     94     public final static boolean WATCH_POINTER = false;
     95 
     96     /**
     97      * Sticky broadcast of the current HDMI plugged state.
     98      */
     99     public final static String ACTION_HDMI_PLUGGED = "android.intent.action.HDMI_PLUGGED";
    100 
    101     /**
    102      * Extra in {@link #ACTION_HDMI_PLUGGED} indicating the state: true if
    103      * plugged in to HDMI, false if not.
    104      */
    105     public final static String EXTRA_HDMI_PLUGGED_STATE = "state";
    106 
    107     /**
    108      * Pass this event to the user / app.  To be returned from
    109      * {@link #interceptKeyBeforeQueueing}.
    110      */
    111     public final static int ACTION_PASS_TO_USER = 0x00000001;
    112 
    113     /**
    114      * This key event should extend the user activity timeout and turn the lights on.
    115      * To be returned from {@link #interceptKeyBeforeQueueing}.
    116      * Do not return this and {@link #ACTION_GO_TO_SLEEP} or {@link #ACTION_PASS_TO_USER}.
    117      */
    118     public final static int ACTION_POKE_USER_ACTIVITY = 0x00000002;
    119 
    120     /**
    121      * This key event should put the device to sleep (and engage keyguard if necessary)
    122      * To be returned from {@link #interceptKeyBeforeQueueing}.
    123      * Do not return this and {@link #ACTION_POKE_USER_ACTIVITY} or {@link #ACTION_PASS_TO_USER}.
    124      */
    125     public final static int ACTION_GO_TO_SLEEP = 0x00000004;
    126 
    127     /**
    128      * Interface to the Window Manager state associated with a particular
    129      * window.  You can hold on to an instance of this interface from the call
    130      * to prepareAddWindow() until removeWindow().
    131      */
    132     public interface WindowState {
    133         /**
    134          * Perform standard frame computation.  The result can be obtained with
    135          * getFrame() if so desired.  Must be called with the window manager
    136          * lock held.
    137          *
    138          * @param parentFrame The frame of the parent container this window
    139          * is in, used for computing its basic position.
    140          * @param displayFrame The frame of the overall display in which this
    141          * window can appear, used for constraining the overall dimensions
    142          * of the window.
    143          * @param contentFrame The frame within the display in which we would
    144          * like active content to appear.  This will cause windows behind to
    145          * be resized to match the given content frame.
    146          * @param visibleFrame The frame within the display that the window
    147          * is actually visible, used for computing its visible insets to be
    148          * given to windows behind.
    149          * This can be used as a hint for scrolling (avoiding resizing)
    150          * the window to make certain that parts of its content
    151          * are visible.
    152          */
    153         public void computeFrameLw(Rect parentFrame, Rect displayFrame,
    154                 Rect contentFrame, Rect visibleFrame);
    155 
    156         /**
    157          * Retrieve the current frame of the window that has been assigned by
    158          * the window manager.  Must be called with the window manager lock held.
    159          *
    160          * @return Rect The rectangle holding the window frame.
    161          */
    162         public Rect getFrameLw();
    163 
    164         /**
    165          * Retrieve the current frame of the window that is actually shown.
    166          * Must be called with the window manager lock held.
    167          *
    168          * @return Rect The rectangle holding the shown window frame.
    169          */
    170         public RectF getShownFrameLw();
    171 
    172         /**
    173          * Retrieve the frame of the display that this window was last
    174          * laid out in.  Must be called with the
    175          * window manager lock held.
    176          *
    177          * @return Rect The rectangle holding the display frame.
    178          */
    179         public Rect getDisplayFrameLw();
    180 
    181         /**
    182          * Retrieve the frame of the content area that this window was last
    183          * laid out in.  This is the area in which the content of the window
    184          * should be placed.  It will be smaller than the display frame to
    185          * account for screen decorations such as a status bar or soft
    186          * keyboard.  Must be called with the
    187          * window manager lock held.
    188          *
    189          * @return Rect The rectangle holding the content frame.
    190          */
    191         public Rect getContentFrameLw();
    192 
    193         /**
    194          * Retrieve the frame of the visible area that this window was last
    195          * laid out in.  This is the area of the screen in which the window
    196          * will actually be fully visible.  It will be smaller than the
    197          * content frame to account for transient UI elements blocking it
    198          * such as an input method's candidates UI.  Must be called with the
    199          * window manager lock held.
    200          *
    201          * @return Rect The rectangle holding the visible frame.
    202          */
    203         public Rect getVisibleFrameLw();
    204 
    205         /**
    206          * Returns true if this window is waiting to receive its given
    207          * internal insets from the client app, and so should not impact the
    208          * layout of other windows.
    209          */
    210         public boolean getGivenInsetsPendingLw();
    211 
    212         /**
    213          * Retrieve the insets given by this window's client for the content
    214          * area of windows behind it.  Must be called with the
    215          * window manager lock held.
    216          *
    217          * @return Rect The left, top, right, and bottom insets, relative
    218          * to the window's frame, of the actual contents.
    219          */
    220         public Rect getGivenContentInsetsLw();
    221 
    222         /**
    223          * Retrieve the insets given by this window's client for the visible
    224          * area of windows behind it.  Must be called with the
    225          * window manager lock held.
    226          *
    227          * @return Rect The left, top, right, and bottom insets, relative
    228          * to the window's frame, of the actual visible area.
    229          */
    230         public Rect getGivenVisibleInsetsLw();
    231 
    232         /**
    233          * Retrieve the current LayoutParams of the window.
    234          *
    235          * @return WindowManager.LayoutParams The window's internal LayoutParams
    236          *         instance.
    237          */
    238         public WindowManager.LayoutParams getAttrs();
    239 
    240         /**
    241          * Return whether this window needs the menu key shown.  Must be called
    242          * with window lock held, because it may need to traverse down through
    243          * window list to determine the result.
    244          * @param bottom The bottom-most window to consider when determining this.
    245          */
    246         public boolean getNeedsMenuLw(WindowState bottom);
    247 
    248         /**
    249          * Retrieve the current system UI visibility flags associated with
    250          * this window.
    251          */
    252         public int getSystemUiVisibility();
    253 
    254         /**
    255          * Get the layer at which this window's surface will be Z-ordered.
    256          */
    257         public int getSurfaceLayer();
    258 
    259         /**
    260          * Return the token for the application (actually activity) that owns
    261          * this window.  May return null for system windows.
    262          *
    263          * @return An IApplicationToken identifying the owning activity.
    264          */
    265         public IApplicationToken getAppToken();
    266 
    267         /**
    268          * Return true if, at any point, the application token associated with
    269          * this window has actually displayed any windows.  This is most useful
    270          * with the "starting up" window to determine if any windows were
    271          * displayed when it is closed.
    272          *
    273          * @return Returns true if one or more windows have been displayed,
    274          *         else false.
    275          */
    276         public boolean hasAppShownWindows();
    277 
    278         /**
    279          * Is this window visible?  It is not visible if there is no
    280          * surface, or we are in the process of running an exit animation
    281          * that will remove the surface.
    282          */
    283         boolean isVisibleLw();
    284 
    285         /**
    286          * Like {@link #isVisibleLw}, but also counts a window that is currently
    287          * "hidden" behind the keyguard as visible.  This allows us to apply
    288          * things like window flags that impact the keyguard.
    289          */
    290         boolean isVisibleOrBehindKeyguardLw();
    291 
    292         /**
    293          * Is this window currently visible to the user on-screen?  It is
    294          * displayed either if it is visible or it is currently running an
    295          * animation before no longer being visible.  Must be called with the
    296          * window manager lock held.
    297          */
    298         boolean isDisplayedLw();
    299 
    300         /**
    301          * Returns true if this window has been shown on screen at some time in
    302          * the past.  Must be called with the window manager lock held.
    303          *
    304          * @return boolean
    305          */
    306         public boolean hasDrawnLw();
    307 
    308         /**
    309          * Can be called by the policy to force a window to be hidden,
    310          * regardless of whether the client or window manager would like
    311          * it shown.  Must be called with the window manager lock held.
    312          * Returns true if {@link #showLw} was last called for the window.
    313          */
    314         public boolean hideLw(boolean doAnimation);
    315 
    316         /**
    317          * Can be called to undo the effect of {@link #hideLw}, allowing a
    318          * window to be shown as long as the window manager and client would
    319          * also like it to be shown.  Must be called with the window manager
    320          * lock held.
    321          * Returns true if {@link #hideLw} was last called for the window.
    322          */
    323         public boolean showLw(boolean doAnimation);
    324     }
    325 
    326     /**
    327      * Representation of a "fake window" that the policy has added to the
    328      * window manager to consume events.
    329      */
    330     public interface FakeWindow {
    331         /**
    332          * Remove the fake window from the window manager.
    333          */
    334         void dismiss();
    335     }
    336 
    337     /**
    338      * Interface for calling back in to the window manager that is private
    339      * between it and the policy.
    340      */
    341     public interface WindowManagerFuncs {
    342         /**
    343          * Ask the window manager to re-evaluate the system UI flags.
    344          */
    345         public void reevaluateStatusBarVisibility();
    346 
    347         /**
    348          * Add a fake window to the window manager.  This window sits
    349          * at the top of the other windows and consumes events.
    350          */
    351         public FakeWindow addFakeWindow(Looper looper, InputHandler inputHandler,
    352                 String name, int windowType, int layoutParamsFlags, boolean canReceiveKeys,
    353                 boolean hasFocus, boolean touchFullscreen);
    354     }
    355 
    356     /**
    357      * Bit mask that is set for all enter transition.
    358      */
    359     public final int TRANSIT_ENTER_MASK = 0x1000;
    360 
    361     /**
    362      * Bit mask that is set for all exit transitions.
    363      */
    364     public final int TRANSIT_EXIT_MASK = 0x2000;
    365 
    366     /** Not set up for a transition. */
    367     public final int TRANSIT_UNSET = -1;
    368     /** No animation for transition. */
    369     public final int TRANSIT_NONE = 0;
    370     /** Window has been added to the screen. */
    371     public final int TRANSIT_ENTER = 1 | TRANSIT_ENTER_MASK;
    372     /** Window has been removed from the screen. */
    373     public final int TRANSIT_EXIT = 2 | TRANSIT_EXIT_MASK;
    374     /** Window has been made visible. */
    375     public final int TRANSIT_SHOW = 3 | TRANSIT_ENTER_MASK;
    376     /** Window has been made invisible. */
    377     public final int TRANSIT_HIDE = 4 | TRANSIT_EXIT_MASK;
    378     /** The "application starting" preview window is no longer needed, and will
    379      * animate away to show the real window. */
    380     public final int TRANSIT_PREVIEW_DONE = 5;
    381     /** A window in a new activity is being opened on top of an existing one
    382      * in the same task. */
    383     public final int TRANSIT_ACTIVITY_OPEN = 6 | TRANSIT_ENTER_MASK;
    384     /** The window in the top-most activity is being closed to reveal the
    385      * previous activity in the same task. */
    386     public final int TRANSIT_ACTIVITY_CLOSE = 7 | TRANSIT_EXIT_MASK;
    387     /** A window in a new task is being opened on top of an existing one
    388      * in another activity's task. */
    389     public final int TRANSIT_TASK_OPEN = 8 | TRANSIT_ENTER_MASK;
    390     /** A window in the top-most activity is being closed to reveal the
    391      * previous activity in a different task. */
    392     public final int TRANSIT_TASK_CLOSE = 9 | TRANSIT_EXIT_MASK;
    393     /** A window in an existing task is being displayed on top of an existing one
    394      * in another activity's task. */
    395     public final int TRANSIT_TASK_TO_FRONT = 10 | TRANSIT_ENTER_MASK;
    396     /** A window in an existing task is being put below all other tasks. */
    397     public final int TRANSIT_TASK_TO_BACK = 11 | TRANSIT_EXIT_MASK;
    398     /** A window in a new activity that doesn't have a wallpaper is being
    399      * opened on top of one that does, effectively closing the wallpaper. */
    400     public final int TRANSIT_WALLPAPER_CLOSE = 12 | TRANSIT_EXIT_MASK;
    401     /** A window in a new activity that does have a wallpaper is being
    402      * opened on one that didn't, effectively opening the wallpaper. */
    403     public final int TRANSIT_WALLPAPER_OPEN = 13 | TRANSIT_ENTER_MASK;
    404     /** A window in a new activity is being opened on top of an existing one,
    405      * and both are on top of the wallpaper. */
    406     public final int TRANSIT_WALLPAPER_INTRA_OPEN = 14 | TRANSIT_ENTER_MASK;
    407     /** The window in the top-most activity is being closed to reveal the
    408      * previous activity, and both are on top of he wallpaper. */
    409     public final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15 | TRANSIT_EXIT_MASK;
    410 
    411     // NOTE: screen off reasons are in order of significance, with more
    412     // important ones lower than less important ones.
    413 
    414     /** Screen turned off because of a device admin */
    415     public final int OFF_BECAUSE_OF_ADMIN = 1;
    416     /** Screen turned off because of power button */
    417     public final int OFF_BECAUSE_OF_USER = 2;
    418     /** Screen turned off because of timeout */
    419     public final int OFF_BECAUSE_OF_TIMEOUT = 3;
    420     /** Screen turned off because of proximity sensor */
    421     public final int OFF_BECAUSE_OF_PROX_SENSOR = 4;
    422 
    423     /** When not otherwise specified by the activity's screenOrientation, rotation should be
    424      * determined by the system (that is, using sensors). */
    425     public final int USER_ROTATION_FREE = 0;
    426     /** When not otherwise specified by the activity's screenOrientation, rotation is set by
    427      * the user. */
    428     public final int USER_ROTATION_LOCKED = 1;
    429 
    430     /**
    431      * Perform initialization of the policy.
    432      *
    433      * @param context The system context we are running in.
    434      * @param powerManager
    435      */
    436     public void init(Context context, IWindowManager windowManager,
    437             WindowManagerFuncs windowManagerFuncs,
    438             LocalPowerManager powerManager);
    439 
    440     /**
    441      * Called by window manager once it has the initial, default native
    442      * display dimensions.
    443      */
    444     public void setInitialDisplaySize(int width, int height);
    445 
    446     /**
    447      * Check permissions when adding a window.
    448      *
    449      * @param attrs The window's LayoutParams.
    450      *
    451      * @return {@link WindowManagerImpl#ADD_OKAY} if the add can proceed;
    452      *      else an error code, usually
    453      *      {@link WindowManagerImpl#ADD_PERMISSION_DENIED}, to abort the add.
    454      */
    455     public int checkAddPermission(WindowManager.LayoutParams attrs);
    456 
    457     /**
    458      * Sanitize the layout parameters coming from a client.  Allows the policy
    459      * to do things like ensure that windows of a specific type can't take
    460      * input focus.
    461      *
    462      * @param attrs The window layout parameters to be modified.  These values
    463      * are modified in-place.
    464      */
    465     public void adjustWindowParamsLw(WindowManager.LayoutParams attrs);
    466 
    467     /**
    468      * After the window manager has computed the current configuration based
    469      * on its knowledge of the display and input devices, it gives the policy
    470      * a chance to adjust the information contained in it.  If you want to
    471      * leave it as-is, simply do nothing.
    472      *
    473      * <p>This method may be called by any thread in the window manager, but
    474      * no internal locks in the window manager will be held.
    475      *
    476      * @param config The Configuration being computed, for you to change as
    477      * desired.
    478      */
    479     public void adjustConfigurationLw(Configuration config);
    480 
    481     /**
    482      * Assign a window type to a layer.  Allows you to control how different
    483      * kinds of windows are ordered on-screen.
    484      *
    485      * @param type The type of window being assigned.
    486      *
    487      * @return int An arbitrary integer used to order windows, with lower
    488      *         numbers below higher ones.
    489      */
    490     public int windowTypeToLayerLw(int type);
    491 
    492     /**
    493      * Return how to Z-order sub-windows in relation to the window they are
    494      * attached to.  Return positive to have them ordered in front, negative for
    495      * behind.
    496      *
    497      * @param type The sub-window type code.
    498      *
    499      * @return int Layer in relation to the attached window, where positive is
    500      *         above and negative is below.
    501      */
    502     public int subWindowTypeToLayerLw(int type);
    503 
    504     /**
    505      * Get the highest layer (actually one more than) that the wallpaper is
    506      * allowed to be in.
    507      */
    508     public int getMaxWallpaperLayer();
    509 
    510     /**
    511      * Return true if the policy allows the status bar to hide.  Otherwise,
    512      * it is a tablet-style system bar.
    513      */
    514     public boolean canStatusBarHide();
    515 
    516     /**
    517      * Return the display width available after excluding any screen
    518      * decorations that can never be removed.  That is, system bar or
    519      * button bar.
    520      */
    521     public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation);
    522 
    523     /**
    524      * Return the display height available after excluding any screen
    525      * decorations that can never be removed.  That is, system bar or
    526      * button bar.
    527      */
    528     public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation);
    529 
    530     /**
    531      * Return the available screen width that we should report for the
    532      * configuration.  This must be no larger than
    533      * {@link #getNonDecorDisplayWidth(int, int)}; it may be smaller than
    534      * that to account for more transient decoration like a status bar.
    535      */
    536     public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation);
    537 
    538     /**
    539      * Return the available screen height that we should report for the
    540      * configuration.  This must be no larger than
    541      * {@link #getNonDecorDisplayHeight(int, int)}; it may be smaller than
    542      * that to account for more transient decoration like a status bar.
    543      */
    544     public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation);
    545 
    546     /**
    547      * Return whether the given window should forcibly hide everything
    548      * behind it.  Typically returns true for the keyguard.
    549      */
    550     public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs);
    551 
    552     /**
    553      * Determine if a window that is behind one that is force hiding
    554      * (as determined by {@link #doesForceHide}) should actually be hidden.
    555      * For example, typically returns false for the status bar.  Be careful
    556      * to return false for any window that you may hide yourself, since this
    557      * will conflict with what you set.
    558      */
    559     public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs);
    560 
    561     /**
    562      * Called when the system would like to show a UI to indicate that an
    563      * application is starting.  You can use this to add a
    564      * APPLICATION_STARTING_TYPE window with the given appToken to the window
    565      * manager (using the normal window manager APIs) that will be shown until
    566      * the application displays its own window.  This is called without the
    567      * window manager locked so that you can call back into it.
    568      *
    569      * @param appToken Token of the application being started.
    570      * @param packageName The name of the application package being started.
    571      * @param theme Resource defining the application's overall visual theme.
    572      * @param nonLocalizedLabel The default title label of the application if
    573      *        no data is found in the resource.
    574      * @param labelRes The resource ID the application would like to use as its name.
    575      * @param icon The resource ID the application would like to use as its icon.
    576      * @param windowFlags Window layout flags.
    577      *
    578      * @return Optionally you can return the View that was used to create the
    579      *         window, for easy removal in removeStartingWindow.
    580      *
    581      * @see #removeStartingWindow
    582      */
    583     public View addStartingWindow(IBinder appToken, String packageName,
    584             int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel,
    585             int labelRes, int icon, int windowFlags);
    586 
    587     /**
    588      * Called when the first window of an application has been displayed, while
    589      * {@link #addStartingWindow} has created a temporary initial window for
    590      * that application.  You should at this point remove the window from the
    591      * window manager.  This is called without the window manager locked so
    592      * that you can call back into it.
    593      *
    594      * <p>Note: due to the nature of these functions not being called with the
    595      * window manager locked, you must be prepared for this function to be
    596      * called multiple times and/or an initial time with a null View window
    597      * even if you previously returned one.
    598      *
    599      * @param appToken Token of the application that has started.
    600      * @param window Window View that was returned by createStartingWindow.
    601      *
    602      * @see #addStartingWindow
    603      */
    604     public void removeStartingWindow(IBinder appToken, View window);
    605 
    606     /**
    607      * Prepare for a window being added to the window manager.  You can throw an
    608      * exception here to prevent the window being added, or do whatever setup
    609      * you need to keep track of the window.
    610      *
    611      * @param win The window being added.
    612      * @param attrs The window's LayoutParams.
    613      *
    614      * @return {@link WindowManagerImpl#ADD_OKAY} if the add can proceed, else an
    615      *         error code to abort the add.
    616      */
    617     public int prepareAddWindowLw(WindowState win,
    618             WindowManager.LayoutParams attrs);
    619 
    620     /**
    621      * Called when a window is being removed from a window manager.  Must not
    622      * throw an exception -- clean up as much as possible.
    623      *
    624      * @param win The window being removed.
    625      */
    626     public void removeWindowLw(WindowState win);
    627 
    628     /**
    629      * Control the animation to run when a window's state changes.  Return a
    630      * non-0 number to force the animation to a specific resource ID, or 0
    631      * to use the default animation.
    632      *
    633      * @param win The window that is changing.
    634      * @param transit What is happening to the window: {@link #TRANSIT_ENTER},
    635      *                {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or
    636      *                {@link #TRANSIT_HIDE}.
    637      *
    638      * @return Resource ID of the actual animation to use, or 0 for none.
    639      */
    640     public int selectAnimationLw(WindowState win, int transit);
    641 
    642     /**
    643      * Create and return an animation to re-display a force hidden window.
    644      */
    645     public Animation createForceHideEnterAnimation();
    646 
    647     /**
    648      * Called from the input reader thread before a key is enqueued.
    649      *
    650      * <p>There are some actions that need to be handled here because they
    651      * affect the power state of the device, for example, the power keys.
    652      * Generally, it's best to keep as little as possible in the queue thread
    653      * because it's the most fragile.
    654      * @param event The key event.
    655      * @param policyFlags The policy flags associated with the key.
    656      * @param isScreenOn True if the screen is already on
    657      *
    658      * @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
    659      *          {@link #ACTION_POKE_USER_ACTIVITY} and {@link #ACTION_GO_TO_SLEEP} flags.
    660      */
    661     public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn);
    662 
    663     /**
    664      * Called from the input reader thread before a motion is enqueued when the screen is off.
    665      *
    666      * <p>There are some actions that need to be handled here because they
    667      * affect the power state of the device, for example, waking on motions.
    668      * Generally, it's best to keep as little as possible in the queue thread
    669      * because it's the most fragile.
    670      * @param policyFlags The policy flags associated with the motion.
    671      *
    672      * @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
    673      *          {@link #ACTION_POKE_USER_ACTIVITY} and {@link #ACTION_GO_TO_SLEEP} flags.
    674      */
    675     public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags);
    676 
    677     /**
    678      * Called from the input dispatcher thread before a key is dispatched to a window.
    679      *
    680      * <p>Allows you to define
    681      * behavior for keys that can not be overridden by applications.
    682      * This method is called from the input thread, with no locks held.
    683      *
    684      * @param win The window that currently has focus.  This is where the key
    685      *            event will normally go.
    686      * @param event The key event.
    687      * @param policyFlags The policy flags associated with the key.
    688      * @return 0 if the key should be dispatched immediately, -1 if the key should
    689      * not be dispatched ever, or a positive value indicating the number of
    690      * milliseconds by which the key dispatch should be delayed before trying
    691      * again.
    692      */
    693     public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags);
    694 
    695     /**
    696      * Called from the input dispatcher thread when an application did not handle
    697      * a key that was dispatched to it.
    698      *
    699      * <p>Allows you to define default global behavior for keys that were not handled
    700      * by applications.  This method is called from the input thread, with no locks held.
    701      *
    702      * @param win The window that currently has focus.  This is where the key
    703      *            event will normally go.
    704      * @param event The key event.
    705      * @param policyFlags The policy flags associated with the key.
    706      * @return Returns an alternate key event to redispatch as a fallback, or null to give up.
    707      * The caller is responsible for recycling the key event.
    708      */
    709     public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags);
    710 
    711     /**
    712      * Called when layout of the windows is about to start.
    713      *
    714      * @param displayWidth The current full width of the screen.
    715      * @param displayHeight The current full height of the screen.
    716      * @param displayRotation The current rotation being applied to the base
    717      * window.
    718      */
    719     public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotation);
    720 
    721     /**
    722      * Called for each window attached to the window manager as layout is
    723      * proceeding.  The implementation of this function must take care of
    724      * setting the window's frame, either here or in finishLayout().
    725      *
    726      * @param win The window being positioned.
    727      * @param attrs The LayoutParams of the window.
    728      * @param attached For sub-windows, the window it is attached to; this
    729      *                 window will already have had layoutWindow() called on it
    730      *                 so you can use its Rect.  Otherwise null.
    731      */
    732     public void layoutWindowLw(WindowState win,
    733             WindowManager.LayoutParams attrs, WindowState attached);
    734 
    735 
    736     /**
    737      * Return the insets for the areas covered by system windows. These values
    738      * are computed on the most recent layout, so they are not guaranteed to
    739      * be correct.
    740      *
    741      * @param attrs The LayoutParams of the window.
    742      * @param contentInset The areas covered by system windows, expressed as positive insets
    743      *
    744      */
    745     public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset);
    746 
    747     /**
    748      * Called when layout of the windows is finished.  After this function has
    749      * returned, all windows given to layoutWindow() <em>must</em> have had a
    750      * frame assigned.
    751      *
    752      * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT},
    753      * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER},
    754      * or {@link #FINISH_LAYOUT_REDO_ANIM}.
    755      */
    756     public int finishLayoutLw();
    757 
    758     /** Layout state may have changed (so another layout will be performed) */
    759     static final int FINISH_LAYOUT_REDO_LAYOUT = 0x0001;
    760     /** Configuration state may have changed */
    761     static final int FINISH_LAYOUT_REDO_CONFIG = 0x0002;
    762     /** Wallpaper may need to move */
    763     static final int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004;
    764     /** Need to recompute animations */
    765     static final int FINISH_LAYOUT_REDO_ANIM = 0x0008;
    766 
    767     /**
    768      * Called when animation of the windows is about to start.
    769      *
    770      * @param displayWidth The current full width of the screen.
    771      * @param displayHeight The current full height of the screen.
    772      */
    773     public void beginAnimationLw(int displayWidth, int displayHeight);
    774 
    775     /**
    776      * Called each time a window is animating.
    777      *
    778      * @param win The window being positioned.
    779      * @param attrs The LayoutParams of the window.
    780      */
    781     public void animatingWindowLw(WindowState win,
    782             WindowManager.LayoutParams attrs);
    783 
    784     /**
    785      * Called when animation of the windows is finished.  If in this function you do
    786      * something that may have modified the animation state of another window,
    787      * be sure to return true in order to perform another animation frame.
    788      *
    789      * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT},
    790      * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER},
    791      * or {@link #FINISH_LAYOUT_REDO_ANIM}.
    792      */
    793     public int finishAnimationLw();
    794 
    795     /**
    796      * Return true if it is okay to perform animations for an app transition
    797      * that is about to occur.  You may return false for this if, for example,
    798      * the lock screen is currently displayed so the switch should happen
    799      * immediately.
    800      */
    801     public boolean allowAppAnimationsLw();
    802 
    803 
    804     /**
    805      * A new window has been focused.
    806      */
    807     public int focusChangedLw(WindowState lastFocus, WindowState newFocus);
    808 
    809     /**
    810      * Called after the screen turns off.
    811      *
    812      * @param why {@link #OFF_BECAUSE_OF_USER} or
    813      * {@link #OFF_BECAUSE_OF_TIMEOUT}.
    814      */
    815     public void screenTurnedOff(int why);
    816 
    817     public interface ScreenOnListener {
    818         void onScreenOn();
    819     };
    820 
    821     /**
    822      * Called when the power manager would like to turn the screen on.
    823      * Must call back on the listener to tell it when the higher-level system
    824      * is ready for the screen to go on (i.e. the lock screen is shown).
    825      */
    826     public void screenTurningOn(ScreenOnListener screenOnListener);
    827 
    828     /**
    829      * Return whether the screen is about to turn on or is currently on.
    830      */
    831     public boolean isScreenOnEarly();
    832 
    833     /**
    834      * Return whether the screen is fully turned on.
    835      */
    836     public boolean isScreenOnFully();
    837 
    838     /**
    839      * Tell the policy that the lid switch has changed state.
    840      * @param whenNanos The time when the change occurred in uptime nanoseconds.
    841      * @param lidOpen True if the lid is now open.
    842      */
    843     public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
    844 
    845     /**
    846      * Tell the policy if anyone is requesting that keyguard not come on.
    847      *
    848      * @param enabled Whether keyguard can be on or not.  does not actually
    849      * turn it on, unless it was previously disabled with this function.
    850      *
    851      * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard()
    852      * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard()
    853      */
    854     public void enableKeyguard(boolean enabled);
    855 
    856     /**
    857      * Callback used by {@link WindowManagerPolicy#exitKeyguardSecurely}
    858      */
    859     interface OnKeyguardExitResult {
    860         void onKeyguardExitResult(boolean success);
    861     }
    862 
    863     /**
    864      * Tell the policy if anyone is requesting the keyguard to exit securely
    865      * (this would be called after the keyguard was disabled)
    866      * @param callback Callback to send the result back.
    867      * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)
    868      */
    869     void exitKeyguardSecurely(OnKeyguardExitResult callback);
    870 
    871     /**
    872      * isKeyguardLocked
    873      *
    874      * Return whether the keyguard is currently locked.
    875      *
    876      * @return true if in keyguard is locked.
    877      */
    878     public boolean isKeyguardLocked();
    879 
    880     /**
    881      * isKeyguardSecure
    882      *
    883      * Return whether the keyguard requires a password to unlock.
    884      *
    885      * @return true if in keyguard is secure.
    886      */
    887     public boolean isKeyguardSecure();
    888 
    889     /**
    890      * inKeyguardRestrictedKeyInputMode
    891      *
    892      * if keyguard screen is showing or in restricted key input mode (i.e. in
    893      * keyguard password emergency screen). When in such mode, certain keys,
    894      * such as the Home key and the right soft keys, don't work.
    895      *
    896      * @return true if in keyguard restricted input mode.
    897      */
    898     public boolean inKeyguardRestrictedKeyInputMode();
    899 
    900     /**
    901      * Ask the policy to dismiss the keyguard, if it is currently shown.
    902      */
    903     public void dismissKeyguardLw();
    904 
    905     /**
    906      * Given an orientation constant, returns the appropriate surface rotation,
    907      * taking into account sensors, docking mode, rotation lock, and other factors.
    908      *
    909      * @param orientation An orientation constant, such as
    910      * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
    911      * @param lastRotation The most recently used rotation.
    912      * @return The surface rotation to use.
    913      */
    914     public int rotationForOrientationLw(int orientation, int lastRotation);
    915 
    916     /**
    917      * Given an orientation constant and a rotation, returns true if the rotation
    918      * has compatible metrics to the requested orientation.  For example, if
    919      * the application requested landscape and got seascape, then the rotation
    920      * has compatible metrics; if the application requested portrait and got landscape,
    921      * then the rotation has incompatible metrics; if the application did not specify
    922      * a preference, then anything goes.
    923      *
    924      * @param orientation An orientation constant, such as
    925      * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
    926      * @param rotation The rotation to check.
    927      * @return True if the rotation is compatible with the requested orientation.
    928      */
    929     public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation);
    930 
    931     /**
    932      * Called by the window manager when the rotation changes.
    933      *
    934      * @param rotation The new rotation.
    935      */
    936     public void setRotationLw(int rotation);
    937 
    938     /**
    939      * Called when the system is mostly done booting to determine whether
    940      * the system should go into safe mode.
    941      */
    942     public boolean detectSafeMode();
    943 
    944     /**
    945      * Called when the system is mostly done booting.
    946      */
    947     public void systemReady();
    948 
    949     /**
    950      * Called when the system is done booting to the point where the
    951      * user can start interacting with it.
    952      */
    953     public void systemBooted();
    954 
    955     /**
    956      * Show boot time message to the user.
    957      */
    958     public void showBootMessage(final CharSequence msg, final boolean always);
    959 
    960     /**
    961      * Hide the UI for showing boot messages, never to be displayed again.
    962      */
    963     public void hideBootMessages();
    964 
    965     /**
    966      * Called when userActivity is signalled in the power manager.
    967      * This is safe to call from any thread, with any window manager locks held or not.
    968      */
    969     public void userActivity();
    970 
    971     /**
    972      * Called when we have finished booting and can now display the home
    973      * screen to the user.  This wilWl happen after systemReady(), and at
    974      * this point the display is active.
    975      */
    976     public void enableScreenAfterBoot();
    977 
    978     public void setCurrentOrientationLw(int newOrientation);
    979 
    980     /**
    981      * Call from application to perform haptic feedback on its window.
    982      */
    983     public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always);
    984 
    985     /**
    986      * Called when we have started keeping the screen on because a window
    987      * requesting this has become visible.
    988      */
    989     public void screenOnStartedLw();
    990 
    991     /**
    992      * Called when we have stopped keeping the screen on because the last window
    993      * requesting this is no longer visible.
    994      */
    995     public void screenOnStoppedLw();
    996 
    997     /**
    998      * Return false to disable key repeat events from being generated.
    999      */
   1000     public boolean allowKeyRepeat();
   1001 
   1002     /**
   1003      * Inform the policy that the user has chosen a preferred orientation ("rotation lock").
   1004      *
   1005      * @param mode One of {@link WindowManagerPolicy#USER_ROTATION_LOCKED} or
   1006      *             {@link * WindowManagerPolicy#USER_ROTATION_FREE}.
   1007      * @param rotation One of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90},
   1008      *                 {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270}.
   1009      */
   1010     public void setUserRotationMode(int mode, int rotation);
   1011 
   1012     /**
   1013      * Called when a new system UI visibility is being reported, allowing
   1014      * the policy to adjust what is actually reported.
   1015      * @param visibility The raw visiblity reported by the status bar.
   1016      * @return The new desired visibility.
   1017      */
   1018     public int adjustSystemUiVisibilityLw(int visibility);
   1019 
   1020     /**
   1021      * Specifies whether there is an on-screen navigation bar separate from the status bar.
   1022      */
   1023     public boolean hasNavigationBar();
   1024 
   1025     /**
   1026      * Print the WindowManagerPolicy's state into the given stream.
   1027      *
   1028      * @param prefix Text to print at the front of each line.
   1029      * @param fd The raw file descriptor that the dump is being sent to.
   1030      * @param writer The PrintWriter to which you should dump your state.  This will be
   1031      * closed for you after you return.
   1032      * @param args additional arguments to the dump request.
   1033      */
   1034     public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args);
   1035 }
   1036