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