2 * Copyright (C) 2006 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import android.annotation.IntDef;
20 import android.annotation.SystemApi;
21 import android.app.ActivityManager.StackId;
22 import android.content.Context;
23 import android.content.pm.ActivityInfo;
24 import android.content.res.CompatibilityInfo;
25 import android.content.res.Configuration;
26 import android.graphics.Point;
27 import android.graphics.Rect;
28 import android.graphics.RectF;
29 import android.os.Bundle;
30 import android.os.IBinder;
31 import android.os.Looper;
32 import android.os.RemoteException;
33 import android.view.animation.Animation;
34 import com.android.internal.policy.IShortcutService;
36 import java.io.PrintWriter;
37 import java.lang.annotation.Retention;
38 import java.lang.annotation.RetentionPolicy;
41 * This interface supplies all UI-specific behavior of the window manager. An
42 * instance of it is created by the window manager when it starts up, and allows
43 * customization of window layering, special window types, key dispatching, and
46 * <p>Because this provides deep interaction with the system window manager,
47 * specific methods on this interface can be called from a variety of contexts
48 * with various restrictions on what they can do. These are encoded through
49 * a suffixes at the end of a method encoding the thread the method is called
50 * from and any locks that are held when it is being called; if no suffix
51 * is attached to a method, then it is not called with any locks and may be
52 * called from the main window manager thread or another thread calling into
55 * <p>The current suffixes are:
58 * <dt> Ti <dd> Called from the input thread. This is the thread that
59 * collects pending input events and dispatches them to the appropriate window.
60 * It may block waiting for events to be processed, so that the input stream is
61 * properly serialized.
62 * <dt> Tq <dd> Called from the low-level input queue thread. This is the
63 * thread that reads events out of the raw input devices and places them
64 * into the global input queue that is read by the <var>Ti</var> thread.
65 * This thread should not block for a long period of time on anything but the
67 * <dt> Lw <dd> Called with the main window manager lock held. Because the
68 * window manager is a very low-level system service, there are few other
69 * system services you can call with this lock held. It is explicitly okay to
70 * make calls into the package manager and power manager; it is explicitly not
71 * okay to make calls into the activity manager or most other services. Note that
72 * {@link android.content.Context#checkPermission(String, int, int)} and
73 * variations require calling into the activity manager.
74 * <dt> Li <dd> Called with the input thread lock held. This lock can be
75 * acquired by the window manager while it holds the window lock, so this is
76 * even more restrictive than <var>Lw</var>.
81 public interface WindowManagerPolicy {
82 // Policy flags. These flags are also defined in frameworks/base/include/ui/Input.h.
83 public final static int FLAG_WAKE = 0x00000001;
84 public final static int FLAG_VIRTUAL = 0x00000002;
86 public final static int FLAG_INJECTED = 0x01000000;
87 public final static int FLAG_TRUSTED = 0x02000000;
88 public final static int FLAG_FILTERED = 0x04000000;
89 public final static int FLAG_DISABLE_KEY_REPEAT = 0x08000000;
91 public final static int FLAG_INTERACTIVE = 0x20000000;
92 public final static int FLAG_PASS_TO_USER = 0x40000000;
94 // Flags for IActivityManager.keyguardGoingAway()
95 public final static int KEYGUARD_GOING_AWAY_FLAG_TO_SHADE = 1 << 0;
96 public final static int KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS = 1 << 1;
97 public final static int KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER = 1 << 2;
99 // Flags used for indicating whether the internal and/or external input devices
100 // of some type are available.
101 public final static int PRESENCE_INTERNAL = 1 << 0;
102 public final static int PRESENCE_EXTERNAL = 1 << 1;
104 public final static boolean WATCH_POINTER = false;
107 * Sticky broadcast of the current HDMI plugged state.
109 public final static String ACTION_HDMI_PLUGGED = "android.intent.action.HDMI_PLUGGED";
112 * Extra in {@link #ACTION_HDMI_PLUGGED} indicating the state: true if
113 * plugged in to HDMI, false if not.
115 public final static String EXTRA_HDMI_PLUGGED_STATE = "state";
118 * Set to {@code true} when intent was invoked from pressing the home key.
122 public static final String EXTRA_FROM_HOME_KEY = "android.intent.extra.FROM_HOME_KEY";
125 * Pass this event to the user / app. To be returned from
126 * {@link #interceptKeyBeforeQueueing}.
128 public final static int ACTION_PASS_TO_USER = 0x00000001;
131 * Register shortcuts for window manager to dispatch.
132 * Shortcut code is packed as (metaState << Integer.SIZE) | keyCode
135 void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)
136 throws RemoteException;
139 * Interface to the Window Manager state associated with a particular
140 * window. You can hold on to an instance of this interface from the call
141 * to prepareAddWindow() until removeWindow().
143 public interface WindowState {
145 * Return the uid of the app that owns this window.
150 * Return the package name of the app that owns this window.
152 String getOwningPackage();
155 * Perform standard frame computation. The result can be obtained with
156 * getFrame() if so desired. Must be called with the window manager
159 * @param parentFrame The frame of the parent container this window
160 * is in, used for computing its basic position.
161 * @param displayFrame The frame of the overall display in which this
162 * window can appear, used for constraining the overall dimensions
164 * @param overlayFrame The frame within the display that is inside
165 * of the overlay region.
166 * @param contentFrame The frame within the display in which we would
167 * like active content to appear. This will cause windows behind to
168 * be resized to match the given content frame.
169 * @param visibleFrame The frame within the display that the window
170 * is actually visible, used for computing its visible insets to be
171 * given to windows behind.
172 * This can be used as a hint for scrolling (avoiding resizing)
173 * the window to make certain that parts of its content
175 * @param decorFrame The decor frame specified by policy specific to this window,
176 * to use for proper cropping during animation.
177 * @param stableFrame The frame around which stable system decoration is positioned.
178 * @param outsetFrame The frame that includes areas that aren't part of the surface but we
179 * want to treat them as such.
181 public void computeFrameLw(Rect parentFrame, Rect displayFrame,
182 Rect overlayFrame, Rect contentFrame, Rect visibleFrame, Rect decorFrame,
183 Rect stableFrame, Rect outsetFrame);
186 * Retrieve the current frame of the window that has been assigned by
187 * the window manager. Must be called with the window manager lock held.
189 * @return Rect The rectangle holding the window frame.
191 public Rect getFrameLw();
194 * Retrieve the current position of the window that is actually shown.
195 * Must be called with the window manager lock held.
197 * @return Point The point holding the shown window position.
199 public Point getShownPositionLw();
202 * Retrieve the frame of the display that this window was last
203 * laid out in. Must be called with the
204 * window manager lock held.
206 * @return Rect The rectangle holding the display frame.
208 public Rect getDisplayFrameLw();
211 * Retrieve the frame of the area inside the overscan region of the
212 * display that this window was last laid out in. Must be called with the
213 * window manager lock held.
215 * @return Rect The rectangle holding the display overscan frame.
217 public Rect getOverscanFrameLw();
220 * Retrieve the frame of the content area that this window was last
221 * laid out in. This is the area in which the content of the window
222 * should be placed. It will be smaller than the display frame to
223 * account for screen decorations such as a status bar or soft
224 * keyboard. Must be called with the
225 * window manager lock held.
227 * @return Rect The rectangle holding the content frame.
229 public Rect getContentFrameLw();
232 * Retrieve the frame of the visible area that this window was last
233 * laid out in. This is the area of the screen in which the window
234 * will actually be fully visible. It will be smaller than the
235 * content frame to account for transient UI elements blocking it
236 * such as an input method's candidates UI. Must be called with the
237 * window manager lock held.
239 * @return Rect The rectangle holding the visible frame.
241 public Rect getVisibleFrameLw();
244 * Returns true if this window is waiting to receive its given
245 * internal insets from the client app, and so should not impact the
246 * layout of other windows.
248 public boolean getGivenInsetsPendingLw();
251 * Retrieve the insets given by this window's client for the content
252 * area of windows behind it. Must be called with the
253 * window manager lock held.
255 * @return Rect The left, top, right, and bottom insets, relative
256 * to the window's frame, of the actual contents.
258 public Rect getGivenContentInsetsLw();
261 * Retrieve the insets given by this window's client for the visible
262 * area of windows behind it. Must be called with the
263 * window manager lock held.
265 * @return Rect The left, top, right, and bottom insets, relative
266 * to the window's frame, of the actual visible area.
268 public Rect getGivenVisibleInsetsLw();
271 * Retrieve the current LayoutParams of the window.
273 * @return WindowManager.LayoutParams The window's internal LayoutParams
276 public WindowManager.LayoutParams getAttrs();
279 * Return whether this window needs the menu key shown. Must be called
280 * with window lock held, because it may need to traverse down through
281 * window list to determine the result.
282 * @param bottom The bottom-most window to consider when determining this.
284 public boolean getNeedsMenuLw(WindowState bottom);
287 * Retrieve the current system UI visibility flags associated with
290 public int getSystemUiVisibility();
293 * Get the layer at which this window's surface will be Z-ordered.
295 public int getSurfaceLayer();
298 * Retrieve the type of the top-level window.
300 * @return the base type of the parent window if attached or its own type otherwise
302 public int getBaseType();
305 * Return the token for the application (actually activity) that owns
306 * this window. May return null for system windows.
308 * @return An IApplicationToken identifying the owning activity.
310 public IApplicationToken getAppToken();
313 * Return true if this window is participating in voice interaction.
315 public boolean isVoiceInteraction();
318 * Return true if, at any point, the application token associated with
319 * this window has actually displayed any windows. This is most useful
320 * with the "starting up" window to determine if any windows were
321 * displayed when it is closed.
323 * @return Returns true if one or more windows have been displayed,
326 public boolean hasAppShownWindows();
329 * Is this window visible? It is not visible if there is no
330 * surface, or we are in the process of running an exit animation
331 * that will remove the surface.
333 boolean isVisibleLw();
336 * Like {@link #isVisibleLw}, but also counts a window that is currently
337 * "hidden" behind the keyguard as visible. This allows us to apply
338 * things like window flags that impact the keyguard.
340 boolean isVisibleOrBehindKeyguardLw();
343 * Is this window currently visible to the user on-screen? It is
344 * displayed either if it is visible or it is currently running an
345 * animation before no longer being visible. Must be called with the
346 * window manager lock held.
348 boolean isDisplayedLw();
351 * Return true if this window (or a window it is attached to, but not
352 * considering its app token) is currently animating.
354 boolean isAnimatingLw();
357 * Is this window considered to be gone for purposes of layout?
359 boolean isGoneForLayoutLw();
362 * Returns true if the window has a surface that it has drawn a
363 * complete UI in to. Note that this is different from {@link #hasDrawnLw()}
364 * in that it also returns true if the window is READY_TO_SHOW, but was not yet
365 * promoted to HAS_DRAWN.
370 * Returns true if this window has been shown on screen at some time in
371 * the past. Must be called with the window manager lock held.
373 public boolean hasDrawnLw();
376 * Can be called by the policy to force a window to be hidden,
377 * regardless of whether the client or window manager would like
378 * it shown. Must be called with the window manager lock held.
379 * Returns true if {@link #showLw} was last called for the window.
381 public boolean hideLw(boolean doAnimation);
384 * Can be called to undo the effect of {@link #hideLw}, allowing a
385 * window to be shown as long as the window manager and client would
386 * also like it to be shown. Must be called with the window manager
388 * Returns true if {@link #hideLw} was last called for the window.
390 public boolean showLw(boolean doAnimation);
393 * Check whether the process hosting this window is currently alive.
395 public boolean isAlive();
398 * Check if window is on {@link Display#DEFAULT_DISPLAY}.
399 * @return true if window is on default display.
401 public boolean isDefaultDisplay();
404 * Check whether the window is currently dimming.
406 public boolean isDimming();
409 * @return the stack id this windows belongs to, or {@link StackId#INVALID_STACK_ID} if
410 * not attached to any stack.
415 * Returns true if the window is current in multi-windowing mode. i.e. it shares the
416 * screen with other application windows.
418 public boolean isInMultiWindowMode();
422 * Representation of a input consumer that the policy has added to the
423 * window manager to consume input events going to windows below it.
425 public interface InputConsumer {
427 * Remove the input consumer from the window manager.
433 * Interface for calling back in to the window manager that is private
434 * between it and the policy.
436 public interface WindowManagerFuncs {
437 public static final int LID_ABSENT = -1;
438 public static final int LID_CLOSED = 0;
439 public static final int LID_OPEN = 1;
441 public static final int CAMERA_LENS_COVER_ABSENT = -1;
442 public static final int CAMERA_LENS_UNCOVERED = 0;
443 public static final int CAMERA_LENS_COVERED = 1;
446 * Ask the window manager to re-evaluate the system UI flags.
448 public void reevaluateStatusBarVisibility();
451 * Add a input consumer which will consume all input events going to any window below it.
453 public InputConsumer addInputConsumer(Looper looper,
454 InputEventReceiver.Factory inputEventReceiverFactory);
457 * Returns a code that describes the current state of the lid switch.
459 public int getLidState();
462 * Lock the device now.
464 public void lockDeviceNow();
467 * Returns a code that descripbes whether the camera lens is covered or not.
469 public int getCameraLensCoverState();
472 * Switch the input method, to be precise, input method subtype.
474 * @param forwardDirection {@code true} to rotate in a forward direction.
476 public void switchInputMethod(boolean forwardDirection);
478 public void shutdown(boolean confirm);
479 public void rebootSafeMode(boolean confirm);
482 * Return the window manager lock needed to correctly call "Lw" methods.
484 public Object getWindowManagerLock();
486 /** Register a system listener for touch events */
487 void registerPointerEventListener(PointerEventListener listener);
489 /** Unregister a system listener for touch events */
490 void unregisterPointerEventListener(PointerEventListener listener);
493 * @return The content insets of the docked divider window.
495 int getDockedDividerInsetsLw();
498 * Retrieves the {@param outBounds} from the stack with id {@param stackId}.
500 void getStackBounds(int stackId, Rect outBounds);
503 public interface PointerEventListener {
505 * 1. onPointerEvent will be called on the service.UiThread.
506 * 2. motionEvent will be recycled after onPointerEvent returns so if it is needed later a
507 * copy() must be made and the copy must be recycled.
509 public void onPointerEvent(MotionEvent motionEvent);
512 /** Window has been added to the screen. */
513 public static final int TRANSIT_ENTER = 1;
514 /** Window has been removed from the screen. */
515 public static final int TRANSIT_EXIT = 2;
516 /** Window has been made visible. */
517 public static final int TRANSIT_SHOW = 3;
518 /** Window has been made invisible.
519 * TODO: Consider removal as this is unused. */
520 public static final int TRANSIT_HIDE = 4;
521 /** The "application starting" preview window is no longer needed, and will
522 * animate away to show the real window. */
523 public static final int TRANSIT_PREVIEW_DONE = 5;
525 // NOTE: screen off reasons are in order of significance, with more
526 // important ones lower than less important ones.
528 /** Screen turned off because of a device admin */
529 public final int OFF_BECAUSE_OF_ADMIN = 1;
530 /** Screen turned off because of power button */
531 public final int OFF_BECAUSE_OF_USER = 2;
532 /** Screen turned off because of timeout */
533 public final int OFF_BECAUSE_OF_TIMEOUT = 3;
536 @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED})
537 @Retention(RetentionPolicy.SOURCE)
538 public @interface UserRotationMode {}
540 /** When not otherwise specified by the activity's screenOrientation, rotation should be
541 * determined by the system (that is, using sensors). */
542 public final int USER_ROTATION_FREE = 0;
543 /** When not otherwise specified by the activity's screenOrientation, rotation is set by
545 public final int USER_ROTATION_LOCKED = 1;
548 * Perform initialization of the policy.
550 * @param context The system context we are running in.
552 public void init(Context context, IWindowManager windowManager,
553 WindowManagerFuncs windowManagerFuncs);
556 * @return true if com.android.internal.R.bool#config_forceDefaultOrientation is true.
558 public boolean isDefaultOrientationForced();
561 * Called by window manager once it has the initial, default native
562 * display dimensions.
564 public void setInitialDisplaySize(Display display, int width, int height, int density);
567 * Called by window manager to set the overscan region that should be used for the
570 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom);
573 * Check permissions when adding a window.
575 * @param attrs The window's LayoutParams.
576 * @param outAppOp First element will be filled with the app op corresponding to
577 * this window, or OP_NONE.
579 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed;
580 * else an error code, usually
581 * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add.
583 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp);
586 * Check permissions when adding a window.
588 * @param attrs The window's LayoutParams.
590 * @return True if the window may only be shown to the current user, false if the window can
591 * be shown on all users' windows.
593 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs);
596 * Sanitize the layout parameters coming from a client. Allows the policy
597 * to do things like ensure that windows of a specific type can't take
600 * @param attrs The window layout parameters to be modified. These values
601 * are modified in-place.
603 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs);
606 * After the window manager has computed the current configuration based
607 * on its knowledge of the display and input devices, it gives the policy
608 * a chance to adjust the information contained in it. If you want to
609 * leave it as-is, simply do nothing.
611 * <p>This method may be called by any thread in the window manager, but
612 * no internal locks in the window manager will be held.
614 * @param config The Configuration being computed, for you to change as
616 * @param keyboardPresence Flags that indicate whether internal or external
617 * keyboards are present.
618 * @param navigationPresence Flags that indicate whether internal or external
619 * navigation devices are present.
621 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
622 int navigationPresence);
625 * Assign a window type to a layer. Allows you to control how different
626 * kinds of windows are ordered on-screen.
628 * @param type The type of window being assigned.
630 * @return int An arbitrary integer used to order windows, with lower
631 * numbers below higher ones.
633 public int windowTypeToLayerLw(int type);
636 * Return how to Z-order sub-windows in relation to the window they are
637 * attached to. Return positive to have them ordered in front, negative for
640 * @param type The sub-window type code.
642 * @return int Layer in relation to the attached window, where positive is
643 * above and negative is below.
645 public int subWindowTypeToLayerLw(int type);
648 * Get the highest layer (actually one more than) that the wallpaper is
651 public int getMaxWallpaperLayer();
654 * Return the display width available after excluding any screen
655 * decorations that could never be removed in Honeycomb. That is, system bar or
658 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
662 * Return the display height available after excluding any screen
663 * decorations that could never be removed in Honeycomb. That is, system bar or
666 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
670 * Return the available screen width that we should report for the
671 * configuration. This must be no larger than
672 * {@link #getNonDecorDisplayWidth(int, int, int)}; it may be smaller than
673 * that to account for more transient decoration like a status bar.
675 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation,
679 * Return the available screen height that we should report for the
680 * configuration. This must be no larger than
681 * {@link #getNonDecorDisplayHeight(int, int, int)}; it may be smaller than
682 * that to account for more transient decoration like a status bar.
684 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation,
688 * Return whether the given window is forcibly hiding all windows except windows with
689 * FLAG_SHOW_WHEN_LOCKED set. Typically returns true for the keyguard.
691 public boolean isForceHiding(WindowManager.LayoutParams attrs);
695 * Return whether the given window can become one that passes isForceHiding() test.
696 * Typically returns true for the StatusBar.
698 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs);
701 * Determine if a window that is behind one that is force hiding
702 * (as determined by {@link #isForceHiding}) should actually be hidden.
703 * For example, typically returns false for the status bar. Be careful
704 * to return false for any window that you may hide yourself, since this
705 * will conflict with what you set.
707 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs);
710 * Return the window that is hiding the keyguard, if such a thing exists.
712 public WindowState getWinShowWhenLockedLw();
715 * Called when the system would like to show a UI to indicate that an
716 * application is starting. You can use this to add a
717 * APPLICATION_STARTING_TYPE window with the given appToken to the window
718 * manager (using the normal window manager APIs) that will be shown until
719 * the application displays its own window. This is called without the
720 * window manager locked so that you can call back into it.
722 * @param appToken Token of the application being started.
723 * @param packageName The name of the application package being started.
724 * @param theme Resource defining the application's overall visual theme.
725 * @param nonLocalizedLabel The default title label of the application if
726 * no data is found in the resource.
727 * @param labelRes The resource ID the application would like to use as its name.
728 * @param icon The resource ID the application would like to use as its icon.
729 * @param windowFlags Window layout flags.
730 * @param overrideConfig override configuration to consider when generating
731 * context to for resources.
733 * @return Optionally you can return the View that was used to create the
734 * window, for easy removal in removeStartingWindow.
736 * @see #removeStartingWindow
738 public View addStartingWindow(IBinder appToken, String packageName,
739 int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel,
740 int labelRes, int icon, int logo, int windowFlags, Configuration overrideConfig);
743 * Called when the first window of an application has been displayed, while
744 * {@link #addStartingWindow} has created a temporary initial window for
745 * that application. You should at this point remove the window from the
746 * window manager. This is called without the window manager locked so
747 * that you can call back into it.
749 * <p>Note: due to the nature of these functions not being called with the
750 * window manager locked, you must be prepared for this function to be
751 * called multiple times and/or an initial time with a null View window
752 * even if you previously returned one.
754 * @param appToken Token of the application that has started.
755 * @param window Window View that was returned by createStartingWindow.
757 * @see #addStartingWindow
759 public void removeStartingWindow(IBinder appToken, View window);
762 * Prepare for a window being added to the window manager. You can throw an
763 * exception here to prevent the window being added, or do whatever setup
764 * you need to keep track of the window.
766 * @param win The window being added.
767 * @param attrs The window's LayoutParams.
769 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed, else an
770 * error code to abort the add.
772 public int prepareAddWindowLw(WindowState win,
773 WindowManager.LayoutParams attrs);
776 * Called when a window is being removed from a window manager. Must not
777 * throw an exception -- clean up as much as possible.
779 * @param win The window being removed.
781 public void removeWindowLw(WindowState win);
784 * Control the animation to run when a window's state changes. Return a
785 * non-0 number to force the animation to a specific resource ID, or 0
786 * to use the default animation.
788 * @param win The window that is changing.
789 * @param transit What is happening to the window: {@link #TRANSIT_ENTER},
790 * {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or
791 * {@link #TRANSIT_HIDE}.
793 * @return Resource ID of the actual animation to use, or 0 for none.
795 public int selectAnimationLw(WindowState win, int transit);
798 * Determine the animation to run for a rotation transition based on the
799 * top fullscreen windows {@link WindowManager.LayoutParams#rotationAnimation}
800 * and whether it is currently fullscreen and frontmost.
802 * @param anim The exiting animation resource id is stored in anim[0], the
803 * entering animation resource id is stored in anim[1].
805 public void selectRotationAnimationLw(int anim[]);
808 * Validate whether the current top fullscreen has specified the same
809 * {@link WindowManager.LayoutParams#rotationAnimation} value as that
810 * being passed in from the previous top fullscreen window.
812 * @param exitAnimId exiting resource id from the previous window.
813 * @param enterAnimId entering resource id from the previous window.
814 * @param forceDefault For rotation animations only, if true ignore the
815 * animation values and just return false.
816 * @return true if the previous values are still valid, false if they
817 * should be replaced with the default.
819 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
820 boolean forceDefault);
823 * Create and return an animation to re-display a force hidden window.
825 public Animation createForceHideEnterAnimation(boolean onWallpaper,
826 boolean goingToNotificationShade);
829 * Create and return an animation to let the wallpaper disappear after being shown on a force
832 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade);
835 * Called from the input reader thread before a key is enqueued.
837 * <p>There are some actions that need to be handled here because they
838 * affect the power state of the device, for example, the power keys.
839 * Generally, it's best to keep as little as possible in the queue thread
840 * because it's the most fragile.
841 * @param event The key event.
842 * @param policyFlags The policy flags associated with the key.
844 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
846 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
849 * Called from the input reader thread before a motion is enqueued when the device is in a
850 * non-interactive state.
852 * <p>There are some actions that need to be handled here because they
853 * affect the power state of the device, for example, waking on motions.
854 * Generally, it's best to keep as little as possible in the queue thread
855 * because it's the most fragile.
856 * @param policyFlags The policy flags associated with the motion.
858 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
860 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags);
863 * Called from the input dispatcher thread before a key is dispatched to a window.
865 * <p>Allows you to define
866 * behavior for keys that can not be overridden by applications.
867 * This method is called from the input thread, with no locks held.
869 * @param win The window that currently has focus. This is where the key
870 * event will normally go.
871 * @param event The key event.
872 * @param policyFlags The policy flags associated with the key.
873 * @return 0 if the key should be dispatched immediately, -1 if the key should
874 * not be dispatched ever, or a positive value indicating the number of
875 * milliseconds by which the key dispatch should be delayed before trying
878 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags);
881 * Called from the input dispatcher thread when an application did not handle
882 * a key that was dispatched to it.
884 * <p>Allows you to define default global behavior for keys that were not handled
885 * by applications. This method is called from the input thread, with no locks held.
887 * @param win The window that currently has focus. This is where the key
888 * event will normally go.
889 * @param event The key event.
890 * @param policyFlags The policy flags associated with the key.
891 * @return Returns an alternate key event to redispatch as a fallback, or null to give up.
892 * The caller is responsible for recycling the key event.
894 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags);
897 * Called when layout of the windows is about to start.
899 * @param isDefaultDisplay true if window is on {@link Display#DEFAULT_DISPLAY}.
900 * @param displayWidth The current full width of the screen.
901 * @param displayHeight The current full height of the screen.
902 * @param displayRotation The current rotation being applied to the base window.
903 * @param uiMode The current uiMode in configuration.
905 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
906 int displayRotation, int uiMode);
909 * Returns the bottom-most layer of the system decor, above which no policy decor should
912 public int getSystemDecorLayerLw();
915 * Return the rectangle of the screen that is available for applications to run in.
916 * This will be called immediately after {@link #beginLayoutLw}.
918 * @param r The rectangle to be filled with the boundaries available to applications.
920 public void getContentRectLw(Rect r);
923 * Called for each window attached to the window manager as layout is
924 * proceeding. The implementation of this function must take care of
925 * setting the window's frame, either here or in finishLayout().
927 * @param win The window being positioned.
928 * @param attached For sub-windows, the window it is attached to; this
929 * window will already have had layoutWindow() called on it
930 * so you can use its Rect. Otherwise null.
932 public void layoutWindowLw(WindowState win, WindowState attached);
936 * Return the insets for the areas covered by system windows. These values
937 * are computed on the most recent layout, so they are not guaranteed to
940 * @param attrs The LayoutParams of the window.
941 * @param taskBounds The bounds of the task this window is on or {@code null} if no task is
942 * associated with the window.
943 * @param displayRotation Rotation of the display.
944 * @param displayWidth The width of the display.
945 * @param displayHeight The height of the display.
946 * @param outContentInsets The areas covered by system windows, expressed as positive insets.
947 * @param outStableInsets The areas covered by stable system windows irrespective of their
948 * current visibility. Expressed as positive insets.
949 * @param outOutsets The areas that are not real display, but we would like to treat as such.
950 * @return Whether to always consume the navigation bar.
951 * See {@link #isNavBarForcedShownLw(WindowState)}.
953 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
954 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
955 Rect outStableInsets, Rect outOutsets);
958 * Called when layout of the windows is finished. After this function has
959 * returned, all windows given to layoutWindow() <em>must</em> have had a
962 public void finishLayoutLw();
964 /** Layout state may have changed (so another layout will be performed) */
965 static final int FINISH_LAYOUT_REDO_LAYOUT = 0x0001;
966 /** Configuration state may have changed */
967 static final int FINISH_LAYOUT_REDO_CONFIG = 0x0002;
968 /** Wallpaper may need to move */
969 static final int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004;
970 /** Need to recompute animations */
971 static final int FINISH_LAYOUT_REDO_ANIM = 0x0008;
974 * Called following layout of all windows before each window has policy applied.
976 * @param displayWidth The current full width of the screen.
977 * @param displayHeight The current full height of the screen.
979 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight);
982 * Called following layout of all window to apply policy to each window.
984 * @param win The window being positioned.
985 * @param attrs The LayoutParams of the window.
986 * @param attached For sub-windows, the window it is attached to. Otherwise null.
988 public void applyPostLayoutPolicyLw(WindowState win,
989 WindowManager.LayoutParams attrs, WindowState attached);
992 * Called following layout of all windows and after policy has been applied
993 * to each window. If in this function you do
994 * something that may have modified the animation state of another window,
995 * be sure to return non-zero in order to perform another pass through layout.
997 * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT},
998 * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER},
999 * or {@link #FINISH_LAYOUT_REDO_ANIM}.
1001 public int finishPostLayoutPolicyLw();
1004 * Return true if it is okay to perform animations for an app transition
1005 * that is about to occur. You may return false for this if, for example,
1006 * the lock screen is currently displayed so the switch should happen
1009 public boolean allowAppAnimationsLw();
1013 * A new window has been focused.
1015 public int focusChangedLw(WindowState lastFocus, WindowState newFocus);
1018 * Called when the device has started waking up.
1020 public void startedWakingUp();
1023 * Called when the device has finished waking up.
1025 public void finishedWakingUp();
1028 * Called when the device has started going to sleep.
1030 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
1031 * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
1033 public void startedGoingToSleep(int why);
1036 * Called when the device has finished going to sleep.
1038 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
1039 * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
1041 public void finishedGoingToSleep(int why);
1044 * Called when the device is about to turn on the screen to show content.
1045 * When waking up, this method will be called once after the call to wakingUp().
1046 * When dozing, the method will be called sometime after the call to goingToSleep() and
1047 * may be called repeatedly in the case where the screen is pulsing on and off.
1049 * Must call back on the listener to tell it when the higher-level system
1050 * is ready for the screen to go on (i.e. the lock screen is shown).
1052 public void screenTurningOn(ScreenOnListener screenOnListener);
1055 * Called when the device has actually turned on the screen, i.e. the display power state has
1056 * been set to ON and the screen is unblocked.
1058 public void screenTurnedOn();
1061 * Called when the device has turned the screen off.
1063 public void screenTurnedOff();
1065 public interface ScreenOnListener {
1070 * Return whether the default display is on and not blocked by a black surface.
1072 public boolean isScreenOn();
1075 * Tell the policy that the lid switch has changed state.
1076 * @param whenNanos The time when the change occurred in uptime nanoseconds.
1077 * @param lidOpen True if the lid is now open.
1079 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
1082 * Tell the policy that the camera lens has been covered or uncovered.
1083 * @param whenNanos The time when the change occurred in uptime nanoseconds.
1084 * @param lensCovered True if the lens is covered.
1086 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered);
1089 * Tell the policy if anyone is requesting that keyguard not come on.
1091 * @param enabled Whether keyguard can be on or not. does not actually
1092 * turn it on, unless it was previously disabled with this function.
1094 * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard()
1095 * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard()
1097 @SuppressWarnings("javadoc")
1098 public void enableKeyguard(boolean enabled);
1101 * Callback used by {@link WindowManagerPolicy#exitKeyguardSecurely}
1103 interface OnKeyguardExitResult {
1104 void onKeyguardExitResult(boolean success);
1108 * Tell the policy if anyone is requesting the keyguard to exit securely
1109 * (this would be called after the keyguard was disabled)
1110 * @param callback Callback to send the result back.
1111 * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)
1113 @SuppressWarnings("javadoc")
1114 void exitKeyguardSecurely(OnKeyguardExitResult callback);
1119 * Return whether the keyguard is currently locked.
1121 * @return true if in keyguard is locked.
1123 public boolean isKeyguardLocked();
1128 * Return whether the keyguard requires a password to unlock.
1131 * @return true if in keyguard is secure.
1133 public boolean isKeyguardSecure(int userId);
1136 * Return whether the keyguard is on.
1138 * @return true if in keyguard is on.
1140 public boolean isKeyguardShowingOrOccluded();
1143 * inKeyguardRestrictedKeyInputMode
1145 * if keyguard screen is showing or in restricted key input mode (i.e. in
1146 * keyguard password emergency screen). When in such mode, certain keys,
1147 * such as the Home key and the right soft keys, don't work.
1149 * @return true if in keyguard restricted input mode.
1151 public boolean inKeyguardRestrictedKeyInputMode();
1154 * Ask the policy to dismiss the keyguard, if it is currently shown.
1156 public void dismissKeyguardLw();
1159 * Notifies the keyguard that the activity has drawn it was waiting for.
1161 public void notifyActivityDrawnForKeyguardLw();
1164 * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method
1165 * returns true as soon as we know that Keyguard is disabled.
1167 * @return true if the keyguard has drawn.
1169 public boolean isKeyguardDrawnLw();
1172 * Given an orientation constant, returns the appropriate surface rotation,
1173 * taking into account sensors, docking mode, rotation lock, and other factors.
1175 * @param orientation An orientation constant, such as
1176 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
1177 * @param lastRotation The most recently used rotation.
1178 * @return The surface rotation to use.
1180 public int rotationForOrientationLw(@ActivityInfo.ScreenOrientation int orientation,
1184 * Given an orientation constant and a rotation, returns true if the rotation
1185 * has compatible metrics to the requested orientation. For example, if
1186 * the application requested landscape and got seascape, then the rotation
1187 * has compatible metrics; if the application requested portrait and got landscape,
1188 * then the rotation has incompatible metrics; if the application did not specify
1189 * a preference, then anything goes.
1191 * @param orientation An orientation constant, such as
1192 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
1193 * @param rotation The rotation to check.
1194 * @return True if the rotation is compatible with the requested orientation.
1196 public boolean rotationHasCompatibleMetricsLw(@ActivityInfo.ScreenOrientation int orientation,
1200 * Called by the window manager when the rotation changes.
1202 * @param rotation The new rotation.
1204 public void setRotationLw(int rotation);
1207 * Called when the system is mostly done booting to set whether
1208 * the system should go into safe mode.
1210 public void setSafeMode(boolean safeMode);
1213 * Called when the system is mostly done booting.
1215 public void systemReady();
1218 * Called when the system is done booting to the point where the
1219 * user can start interacting with it.
1221 public void systemBooted();
1224 * Show boot time message to the user.
1226 public void showBootMessage(final CharSequence msg, final boolean always);
1229 * Hide the UI for showing boot messages, never to be displayed again.
1231 public void hideBootMessages();
1234 * Called when userActivity is signalled in the power manager.
1235 * This is safe to call from any thread, with any window manager locks held or not.
1237 public void userActivity();
1240 * Called when we have finished booting and can now display the home
1241 * screen to the user. This will happen after systemReady(), and at
1242 * this point the display is active.
1244 public void enableScreenAfterBoot();
1246 public void setCurrentOrientationLw(@ActivityInfo.ScreenOrientation int newOrientation);
1249 * Call from application to perform haptic feedback on its window.
1251 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always);
1254 * Called when we have started keeping the screen on because a window
1255 * requesting this has become visible.
1257 public void keepScreenOnStartedLw();
1260 * Called when we have stopped keeping the screen on because the last window
1261 * requesting this is no longer visible.
1263 public void keepScreenOnStoppedLw();
1266 * Gets the current user rotation mode.
1268 * @return The rotation mode.
1270 * @see WindowManagerPolicy#USER_ROTATION_LOCKED
1271 * @see WindowManagerPolicy#USER_ROTATION_FREE
1274 public int getUserRotationMode();
1277 * Inform the policy that the user has chosen a preferred orientation ("rotation lock").
1279 * @param mode One of {@link WindowManagerPolicy#USER_ROTATION_LOCKED} or
1280 * {@link WindowManagerPolicy#USER_ROTATION_FREE}.
1281 * @param rotation One of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90},
1282 * {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270}.
1284 public void setUserRotationMode(@UserRotationMode int mode, @Surface.Rotation int rotation);
1287 * Called when a new system UI visibility is being reported, allowing
1288 * the policy to adjust what is actually reported.
1289 * @param visibility The raw visibility reported by the status bar.
1290 * @return The new desired visibility.
1292 public int adjustSystemUiVisibilityLw(int visibility);
1295 * Specifies whether there is an on-screen navigation bar separate from the status bar.
1297 public boolean hasNavigationBar();
1300 * Lock the device now.
1302 public void lockNow(Bundle options);
1305 * Set the last used input method window state. This state is used to make IME transition
1309 public void setLastInputMethodWindowLw(WindowState ime, WindowState target);
1312 * Show the recents task list app.
1315 public void showRecentApps(boolean fromHome);
1318 * Show the global actions dialog.
1321 public void showGlobalActions();
1324 * @return The current height of the input method window.
1326 public int getInputMethodWindowVisibleHeightLw();
1329 * Called when the current user changes. Guaranteed to be called before the broadcast
1330 * of the new user id is made to all listeners.
1332 * @param newUserId The id of the incoming user.
1334 public void setCurrentUserLw(int newUserId);
1337 * Print the WindowManagerPolicy's state into the given stream.
1339 * @param prefix Text to print at the front of each line.
1340 * @param writer The PrintWriter to which you should dump your state. This will be
1341 * closed for you after you return.
1342 * @param args additional arguments to the dump request.
1344 public void dump(String prefix, PrintWriter writer, String[] args);
1347 * Returns whether a given window type can be magnified.
1349 * @param windowType The window type.
1350 * @return True if the window can be magnified.
1352 public boolean canMagnifyWindow(int windowType);
1355 * Returns whether a given window type is considered a top level one.
1356 * A top level window does not have a container, i.e. attached window,
1357 * or if it has a container it is laid out as a top-level window, not
1358 * as a child of its container.
1360 * @param windowType The window type.
1361 * @return True if the window is a top level one.
1363 public boolean isTopLevelWindow(int windowType);
1366 * Notifies the keyguard to start fading out.
1368 * @param startTime the start time of the animation in uptime milliseconds
1369 * @param fadeoutDuration the duration of the exit animation, in milliseconds
1371 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration);
1374 * Calculates the stable insets without running a layout.
1376 * @param displayRotation the current display rotation
1377 * @param displayWidth the current display width
1378 * @param displayHeight the current display height
1379 * @param outInsets the insets to return
1381 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
1386 * @return true if the navigation bar is forced to stay visible
1388 public boolean isNavBarForcedShownLw(WindowState win);
1391 * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system
1392 * bar or button bar. See {@link #getNonDecorDisplayWidth}.
1394 * @param displayRotation the current display rotation
1395 * @param displayWidth the current display width
1396 * @param displayHeight the current display height
1397 * @param outInsets the insets to return
1399 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
1403 * @return True if a specified {@param dockSide} is allowed on the current device, or false
1404 * otherwise. It is guaranteed that at least one dock side for a particular orientation
1405 * is allowed, so for example, if DOCKED_RIGHT is not allowed, DOCKED_LEFT is allowed.
1407 public boolean isDockSideAllowed(int dockSide);
1410 * Called when the configuration has changed, and it's safe to load new values from resources.
1412 public void onConfigurationChanged();