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