FileDocCategorySizeDatePackage
WindowManagerPolicy.javaAPI DocAndroid 1.5 API33063Wed May 06 22:41:56 BST 2009android.view

WindowManagerPolicy

public interface WindowManagerPolicy
This interface supplies all UI-specific behavior of the window manager. An instance of it is created by the window manager when it starts up, and allows customization of window layering, special window types, key dispatching, and layout.

Because this provides deep interaction with the system window manager, specific methods on this interface can be called from a variety of contexts with various restrictions on what they can do. These are encoded through a suffixes at the end of a method encoding the thread the method is called from and any locks that are held when it is being called; if no suffix is attached to a method, then it is not called with any locks and may be called from the main window manager thread or another thread calling into the window manager.

The current suffixes are:

Ti
Called from the input thread. This is the thread that collects pending input events and dispatches them to the appropriate window. It may block waiting for events to be processed, so that the input stream is properly serialized.
Tq
Called from the low-level input queue thread. This is the thread that reads events out of the raw input devices and places them into the global input queue that is read by the Ti thread. This thread should not block for a long period of time on anything but the key driver.
Lw
Called with the main window manager lock held. Because the window manager is a very low-level system service, there are few other system services you can call with this lock held. It is explicitly okay to make calls into the package manager and power manager; it is explicitly not okay to make calls into the activity manager or most other services. Note that {@link android.content.Context#checkPermission(String, int, int)} and variations require calling into the activity manager.
Li
Called with the input thread lock held. This lock can be acquired by the window manager while it holds the window lock, so this is even more restrictive than Lw.
hide

Fields Summary
public static final int
FLAG_WAKE
public static final int
FLAG_WAKE_DROPPED
public static final int
FLAG_SHIFT
public static final int
FLAG_CAPS_LOCK
public static final int
FLAG_ALT
public static final int
FLAG_ALT_GR
public static final int
FLAG_MENU
public static final int
FLAG_LAUNCHER
public static final int
FLAG_WOKE_HERE
public static final int
FLAG_BRIGHT_HERE
public static final boolean
WATCH_POINTER
public static final int
ACTION_PASS_TO_USER
Pass this event to the user / app. To be returned from {@link #interceptKeyTq}.
public static final int
ACTION_POKE_USER_ACTIVITY
This key event should extend the user activity timeout and turn the lights on. To be returned from {@link #interceptKeyTq}. Do not return this and {@link #ACTION_GO_TO_SLEEP} or {@link #ACTION_PASS_TO_USER}.
public static final int
ACTION_GO_TO_SLEEP
This key event should put the device to sleep (and engage keyguard if necessary) To be returned from {@link #interceptKeyTq}. Do not return this and {@link #ACTION_POKE_USER_ACTIVITY} or {@link #ACTION_PASS_TO_USER}.
public final int
TRANSIT_NONE
No transition happening.
public final int
TRANSIT_ENTER
Window has been added to the screen.
public final int
TRANSIT_EXIT
Window has been removed from the screen.
public final int
TRANSIT_SHOW
Window has been made visible.
public final int
TRANSIT_HIDE
Window has been made invisible.
public final int
TRANSIT_PREVIEW_DONE
The "application starting" preview window is no longer needed, and will animate away to show the real window.
public final int
TRANSIT_ACTIVITY_OPEN
A window in a new activity is being opened on top of an existing one in the same task.
public final int
TRANSIT_ACTIVITY_CLOSE
The window in the top-most activity is being closed to reveal the previous activity in the same task.
public final int
TRANSIT_TASK_OPEN
A window in a new task is being opened on top of an existing one in another activity's task.
public final int
TRANSIT_TASK_CLOSE
A window in the top-most activity is being closed to reveal the previous activity in a different task.
public final int
TRANSIT_TASK_TO_FRONT
A window in an existing task is being displayed on top of an existing one in another activity's task.
public final int
TRANSIT_TASK_TO_BACK
A window in an existing task is being put below all other tasks.
public final int
OFF_BECAUSE_OF_USER
Screen turned off because of power button
public final int
OFF_BECAUSE_OF_TIMEOUT
Screen turned off because of timeout
public final int
USE_LAST_ROTATION
Magic constant to {@link IWindowManager#setRotation} to not actually modify the rotation.
Constructors Summary
Methods Summary
public ViewaddStartingWindow(android.os.IBinder appToken, java.lang.String packageName, int theme, java.lang.CharSequence nonLocalizedLabel, int labelRes, int icon)
Called when the system would like to show a UI to indicate that an application is starting. You can use this to add a APPLICATION_STARTING_TYPE window with the given appToken to the window manager (using the normal window manager APIs) that will be shown until the application displays its own window. This is called without the window manager locked so that you can call back into it.

param
appToken Token of the application being started.
param
packageName The name of the application package being started.
param
theme Resource defining the application's overall visual theme.
param
nonLocalizedLabel The default title label of the application if no data is found in the resource.
param
labelRes The resource ID the application would like to use as its name.
param
icon The resource ID the application would like to use as its icon.
return
Optionally you can return the View that was used to create the window, for easy removal in removeStartingWindow.
see
#removeStartingWindow

public voidadjustConfigurationLw(android.content.res.Configuration config)
After the window manager has computed the current configuration based on its knowledge of the display and input devices, it gives the policy a chance to adjust the information contained in it. If you want to leave it as-is, simply do nothing.

This method may be called by any thread in the window manager, but no internal locks in the window manager will be held.

param
config The Configuration being computed, for you to change as desired.

public voidadjustWindowParamsLw(WindowManager.LayoutParams attrs)
Sanitize the layout parameters coming from a client. Allows the policy to do things like ensure that windows of a specific type can't take input focus.

param
attrs The window layout parameters to be modified. These values are modified in-place.

public voidanimatingWindowLw(android.view.WindowManagerPolicy$WindowState win, WindowManager.LayoutParams attrs)
Called each time a window is animating.

param
win The window being positioned.
param
attrs The LayoutParams of the window.

public voidbeginAnimationLw(int displayWidth, int displayHeight)
Called when animation of the windows is about to start.

param
displayWidth The current full width of the screen.
param
displayHeight The current full height of the screen.

public voidbeginLayoutLw(int displayWidth, int displayHeight)
Called when layout of the windows is about to start.

param
displayWidth The current full width of the screen.
param
displayHeight The current full height of the screen.

public intcheckAddPermission(WindowManager.LayoutParams attrs)
Check permissions when adding a window.

param
attrs The window's LayoutParams.
return
{@link WindowManagerImpl#ADD_OKAY} if the add can proceed; else an error code, usually {@link WindowManagerImpl#ADD_PERMISSION_DENIED}, to abort the add.

public booleandetectSafeMode()
Called when the system is mostly done booting to dentermine whether the system should go into safe mode.

public voidenableKeyguard(boolean enabled)
Tell the policy if anyone is requesting that keyguard not come on.

param
enabled Whether keyguard can be on or not. does not actually turn it on, unless it was previously disabled with this function.
see
android.app.KeyguardManager.KeyguardLock#disableKeyguard()
see
android.app.KeyguardManager.KeyguardLock#reenableKeyguard()

public voidenableScreenAfterBoot()
Called when we have finished booting and can now display the home screen to the user. This wilWl happen after systemReady(), and at this point the display is active.

public voidexitKeyguardSecurely(android.view.WindowManagerPolicy$OnKeyguardExitResult callback)
Tell the policy if anyone is requesting the keyguard to exit securely (this would be called after the keyguard was disabled)

param
callback Callback to send the result back.
see
android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)

public booleanfinishAnimationLw()
Called when animation of the windows is finished. If in this function you do something that may have modified the animation state of another window, be sure to return true in order to perform another animation frame.

return
Return true if animation state may have changed (so that another frame of animation will be run).

public booleanfinishLayoutLw()
Called when layout of the windows is finished. After this function has returned, all windows given to layoutWindow() must have had a frame assigned.

return
Return true if layout state may have changed (so that another layout will be performed).

public voidgetContentInsetHintLw(WindowManager.LayoutParams attrs, android.graphics.Rect contentInset)
Return the insets for the areas covered by system windows. These values are computed on the most recent layout, so they are not guaranteed to be correct.

param
attrs The LayoutParams of the window.
param
contentInset The areas covered by system windows, expressed as positive insets

public booleaninKeyguardRestrictedKeyInputMode()
inKeyguardRestrictedKeyInputMode if keyguard screen is showing or in restricted key input mode (i.e. in keyguard password emergency screen). When in such mode, certain keys, such as the Home key and the right soft keys, don't work.

return
true if in keyguard restricted input mode.

public voidinit(android.content.Context context, IWindowManager windowManager, android.os.LocalPowerManager powerManager)
Perform initialization of the policy.

param
context The system context we are running in.
param
powerManager

public booleaninterceptKeyTi(android.view.WindowManagerPolicy$WindowState win, int code, int metaKeys, boolean down, int repeatCount)
Called from the input thread before a key is dispatched to a window.

Allows you to define behavior for keys that can not be overridden by applications or redirect key events to a different window. This method is called from the input thread, with no locks held.

Note that if you change the window a key is dispatched to, the new target window will receive the key event without having input focus.

param
win The window that currently has focus. This is where the key event will normally go.
param
code Key code.
param
metaKeys TODO
param
down Is this a key press (true) or release (false)?
param
repeatCount Number of times a key down has repeated.
return
Returns true if the policy consumed the event and it should not be further dispatched.

public intinterceptKeyTq(RawInputEvent event, boolean screenIsOn)
Called from the key queue thread before a key is dispatched to the input thread.

There are some actions that need to be handled here because they affect the power state of the device, for example, the power keys. Generally, it's best to keep as little as possible in the queue thread because it's the most fragile.

param
event the raw input event as read from the driver
param
screenIsOn true if the screen is already on
return
The bitwise or of the {@link #ACTION_PASS_TO_USER}, {@link #ACTION_POKE_USER_ACTIVITY} and {@link #ACTION_GO_TO_SLEEP} flags.

public booleanisAppSwitchKeyTqTiLwLi(int keycode)
Determine whether a given key code is used to cause an app switch to occur (most often the HOME key, also often ENDCALL). If you return true, then the system will go into a special key processing state where it drops any pending events that it cans and adjusts timeouts to try to get to this key as quickly as possible.

Note that this function is called from the low-level input queue thread, with either/or the window or input lock held; be very careful about what you do here. You absolutely should never acquire a lock that you would ever hold elsewhere while calling out into the window manager or view hierarchy.

param
keycode The key that should be checked for performing an app switch before delivering to the application.
return
Return true if this is an app switch key and special processing should happen; return false for normal processing.

public booleanisCheekPressedAgainstScreen(MotionEvent ev)
Returns true if the user's cheek has been pressed against the phone. This is determined by comparing the event's size attribute with a threshold value. For example for a motion event like down or up or move, if the size exceeds the threshold, it is considered as cheek press.

param
ev the motion event generated when the cheek is pressed against the phone
return
Returns true if the user's cheek has been pressed against the phone screen resulting in an invalid motion event

public booleanisMovementKeyTi(int keycode)
Determine whether a given key code is used for movement within a UI, and does not generally cause actions to be performed (normally the DPAD movement keys, NOT the DPAD center press key). This is called when {@link #isAppSwitchKeyTiLi} returns true to remove any pending events in the key queue that are not needed to switch applications.

Note that this function is called from the low-level input queue thread; be very careful about what you do here.

param
keycode The key that is waiting to be delivered to the application.
return
Return true if this is a purely navigation key and can be dropped without negative consequences; return false to keep it.

public booleanisWakeAbsMovementTq(int device, int classes, RawInputEvent event)
Given the current state of the world, should this absolute movement wake up the device?

param
device The device the movement came from.
param
classes The input classes associated with the device.
param
event The input event that occurred.
return

public booleanisWakeRelMovementTq(int device, int classes, RawInputEvent event)
Given the current state of the world, should this relative movement wake up the device?

param
device The device the movement came from.
param
classes The input classes associated with the device.
param
event The input event that occurred.
return

public booleankeyguardIsShowingTq()
Return if keyguard is currently showing.

public voidlayoutWindowLw(android.view.WindowManagerPolicy$WindowState win, WindowManager.LayoutParams attrs, android.view.WindowManagerPolicy$WindowState attached)
Called for each window attached to the window manager as layout is proceeding. The implementation of this function must take care of setting the window's frame, either here or in finishLayout().

param
win The window being positioned.
param
attrs The LayoutParams of the window.
param
attached For sub-windows, the window it is attached to; this window will already have had layoutWindow() called on it so you can use its Rect. Otherwise null.

public booleanperformHapticFeedbackLw(android.view.WindowManagerPolicy$WindowState win, int effectId, boolean always)
Call from application to perform haptic feedback on its window.

public intprepareAddWindowLw(android.view.WindowManagerPolicy$WindowState win, WindowManager.LayoutParams attrs)
Prepare for a window being added to the window manager. You can throw an exception here to prevent the window being added, or do whatever setup you need to keep track of the window.

param
win The window being added.
param
attrs The window's LayoutParams.
return
{@link WindowManagerImpl#ADD_OKAY} if the add can proceed, else an error code to abort the add.

public booleanpreprocessInputEventTq(RawInputEvent event)
Perform any initial processing of a low-level input event before the window manager handles special keys and generates a high-level event that is dispatched to the application.

param
event The input event that has occurred.
return
Return true if you have consumed the event and do not want further processing to occur; return false for normal processing.

public voidremoveStartingWindow(android.os.IBinder appToken, View window)
Called when the first window of an application has been displayed, while {@link #addStartingWindow} has created a temporary initial window for that application. You should at this point remove the window from the window manager. This is called without the window manager locked so that you can call back into it.

Note: due to the nature of these functions not being called with the window manager locked, you must be prepared for this function to be called multiple times and/or an initial time with a null View window even if you previously returned one.

param
appToken Token of the application that has started.
param
window Window View that was returned by createStartingWindow.
see
#addStartingWindow

public voidremoveWindowLw(android.view.WindowManagerPolicy$WindowState win)
Called when a window is being removed from a window manager. Must not throw an exception -- clean up as much as possible.

param
win The window being removed.

public introtationForOrientationLw(int orientation, int lastRotation, boolean displayEnabled)
Given an orientation constant ({@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE} or {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_PORTRAIT ActivityInfo.SCREEN_ORIENTATION_PORTRAIT}), return a surface rotation.

public voidscreenOnStoppedLw()
Called when we have stopped keeping the screen on because a window requesting this is no longer visible.

public voidscreenTurnedOff(int why)
Called after the screen turns off.

param
why {@link #OFF_BECAUSE_OF_USER} or {@link #OFF_BECAUSE_OF_TIMEOUT}.

public voidscreenTurnedOn()
Called after the screen turns on.

public intselectAnimationLw(android.view.WindowManagerPolicy$WindowState win, int transit)
Control the animation to run when a window's state changes. Return a non-0 number to force the animation to a specific resource ID, or 0 to use the default animation.

param
win The window that is changing.
param
transit What is happening to the window: {@link #TRANSIT_ENTER}, {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or {@link #TRANSIT_HIDE}.
return
Resource ID of the actual animation to use, or 0 for none.

public voidsetCurrentOrientationLw(int newOrientation)

public intsubWindowTypeToLayerLw(int type)
Return how to Z-order sub-windows in relation to the window they are attached to. Return positive to have them ordered in front, negative for behind.

param
type The sub-window type code.
return
int Layer in relation to the attached window, where positive is above and negative is below.

public voidsystemReady()
Called when the system is mostly done booting.

public intwindowTypeToLayerLw(int type)
Assign a window type to a layer. Allows you to control how different kinds of windows are ordered on-screen.

param
type The type of window being assigned.
return
int An arbitrary integer used to order windows, with lower numbers below higher ones.