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