/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.view; import android.content.Context; import android.content.res.Configuration; import android.graphics.Rect; import android.os.IBinder; import android.os.LocalPowerManager; import android.view.animation.Animation; /** * 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: * *
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 void adjustConfigurationLw(Configuration config); /** * 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. */ public int windowTypeToLayerLw(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 int subWindowTypeToLayerLw(int type); /** * Get the highest layer (actually one more than) that the wallpaper is * allowed to be in. */ public int getMaxWallpaperLayer(); /** * Return whether the given window should forcibly hide everything * behind it. Typically returns true for the keyguard. */ public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs); /** * Determine if a window that is behind one that is force hiding * (as determined by {@link #doesForceHide}) should actually be hidden. * For example, typically returns false for the status bar. Be careful * to return false for any window that you may hide yourself, since this * will conflict with what you set. */ public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs); /** * 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 View addStartingWindow(IBinder appToken, String packageName, int theme, CharSequence nonLocalizedLabel, int labelRes, int icon); /** * 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 void removeStartingWindow(IBinder appToken, View window); /** * 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 int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs); /** * 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 void removeWindowLw(WindowState win); /** * 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 int selectAnimationLw(WindowState win, int transit); /** * Create and return an animation to re-display a force hidden window. */ public Animation createForceHideEnterAnimation(); /** * Called from the input reader thread before a key is enqueued. * *
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 whenNanos The event time in uptime nanoseconds. * @param action The key event action. * @param flags The key event flags. * @param keyCode The key code. * @param scanCode The key's scan code. * @param policyFlags The policy flags associated with the key. * @param isScreenOn 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 int interceptKeyBeforeQueueing(long whenNanos, int action, int flags, int keyCode, int scanCode, int policyFlags, boolean isScreenOn); /** * Called from the input dispatcher 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 action The key event action. * @param flags The key event flags. * @param keyCode The key code. * @param scanCode The key's scan code. * @param metaState bit mask of meta keys that are held. * @param repeatCount Number of times a key down has repeated. * @param policyFlags The policy flags associated with the key. * @return Returns true if the policy consumed the event and it should * not be further dispatched. */ public boolean interceptKeyBeforeDispatching(WindowState win, int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount, int policyFlags); /** * 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 void beginLayoutLw(int displayWidth, int displayHeight); /** * 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 void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, WindowState attached); /** * 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 void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset); /** * 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 any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT}, * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER}, * or {@link #FINISH_LAYOUT_REDO_ANIM}. */ public int finishLayoutLw(); /** Layout state may have changed (so another layout will be performed) */ static final int FINISH_LAYOUT_REDO_LAYOUT = 0x0001; /** Configuration state may have changed */ static final int FINISH_LAYOUT_REDO_CONFIG = 0x0002; /** Wallpaper may need to move */ static final int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004; /** Need to recompute animations */ static final int FINISH_LAYOUT_REDO_ANIM = 0x0008; /** * 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 void beginAnimationLw(int displayWidth, int displayHeight); /** * Called each time a window is animating. * * @param win The window being positioned. * @param attrs The LayoutParams of the window. */ public void animatingWindowLw(WindowState win, WindowManager.LayoutParams attrs); /** * 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 any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT}, * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER}, * or {@link #FINISH_LAYOUT_REDO_ANIM}. */ public int finishAnimationLw(); /** * Return true if it is okay to perform animations for an app transition * that is about to occur. You may return false for this if, for example, * the lock screen is currently displayed so the switch should happen * immediately. */ public boolean allowAppAnimationsLw(); /** * Called after the screen turns off. * * @param why {@link #OFF_BECAUSE_OF_USER} or * {@link #OFF_BECAUSE_OF_TIMEOUT}. */ public void screenTurnedOff(int why); /** * Called after the screen turns on. */ public void screenTurnedOn(); /** * Return whether the screen is currently on. */ public boolean isScreenOn(); /** * Tell the policy that the lid switch has changed state. * @param whenNanos The time when the change occurred in uptime nanoseconds. * @param lidOpen True if the lid is now open. */ public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); /** * Tell the policy that the jack switch has changed state. * @param whenNanos The time when the change occurred in uptime nanoseconds.. * @param switchCode Explains the Jack types * @param jackOpen True if the jacktype is now inserted. */ public void notifyJackSwitchChanged(long whenNanos, int switchCode, boolean jackOpen); /** * 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 void enableKeyguard(boolean enabled); /** * Callback used by {@link WindowManagerPolicy#exitKeyguardSecurely} */ interface OnKeyguardExitResult { void onKeyguardExitResult(boolean success); } /** * 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) */ void exitKeyguardSecurely(OnKeyguardExitResult callback); /** * 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 boolean inKeyguardRestrictedKeyInputMode(); /** * 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 int rotationForOrientationLw(int orientation, int lastRotation, boolean displayEnabled); /** * Called when the system is mostly done booting to determine whether * the system should go into safe mode. */ public boolean detectSafeMode(); /** * Called when the system is mostly done booting. */ public void systemReady(); /** * Called when userActivity is signalled in the power manager. * This is safe to call from any thread, with any window manager locks held or not. */ public void userActivity(); /** * 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 void enableScreenAfterBoot(); public void setCurrentOrientationLw(int newOrientation); /** * Call from application to perform haptic feedback on its window. */ public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always); /** * Called when we have stopped keeping the screen on because a window * requesting this is no longer visible. */ public void screenOnStoppedLw(); /** * Return false to disable key repeat events from being generated. */ public boolean allowKeyRepeat(); }