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