WindowManagerPolicy.java revision e30e02f5d9a9141c9ee70c712d4f9d52c88ea969
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.annotation.IntDef; 20import android.content.Context; 21import android.content.pm.ActivityInfo; 22import android.content.res.CompatibilityInfo; 23import android.content.res.Configuration; 24import android.graphics.Rect; 25import android.graphics.RectF; 26import android.os.Bundle; 27import android.os.IBinder; 28import android.os.Looper; 29import android.view.animation.Animation; 30 31import java.io.PrintWriter; 32import java.lang.annotation.Retention; 33import java.lang.annotation.RetentionPolicy; 34 35/** 36 * This interface supplies all UI-specific behavior of the window manager. An 37 * instance of it is created by the window manager when it starts up, and allows 38 * customization of window layering, special window types, key dispatching, and 39 * layout. 40 * 41 * <p>Because this provides deep interaction with the system window manager, 42 * specific methods on this interface can be called from a variety of contexts 43 * with various restrictions on what they can do. These are encoded through 44 * a suffixes at the end of a method encoding the thread the method is called 45 * from and any locks that are held when it is being called; if no suffix 46 * is attached to a method, then it is not called with any locks and may be 47 * called from the main window manager thread or another thread calling into 48 * the window manager. 49 * 50 * <p>The current suffixes are: 51 * 52 * <dl> 53 * <dt> Ti <dd> Called from the input thread. This is the thread that 54 * collects pending input events and dispatches them to the appropriate window. 55 * It may block waiting for events to be processed, so that the input stream is 56 * properly serialized. 57 * <dt> Tq <dd> Called from the low-level input queue thread. This is the 58 * thread that reads events out of the raw input devices and places them 59 * into the global input queue that is read by the <var>Ti</var> thread. 60 * This thread should not block for a long period of time on anything but the 61 * key driver. 62 * <dt> Lw <dd> Called with the main window manager lock held. Because the 63 * window manager is a very low-level system service, there are few other 64 * system services you can call with this lock held. It is explicitly okay to 65 * make calls into the package manager and power manager; it is explicitly not 66 * okay to make calls into the activity manager or most other services. Note that 67 * {@link android.content.Context#checkPermission(String, int, int)} and 68 * variations require calling into the activity manager. 69 * <dt> Li <dd> Called with the input thread lock held. This lock can be 70 * acquired by the window manager while it holds the window lock, so this is 71 * even more restrictive than <var>Lw</var>. 72 * </dl> 73 * 74 * @hide 75 */ 76public interface WindowManagerPolicy { 77 // Policy flags. These flags are also defined in frameworks/base/include/ui/Input.h. 78 public final static int FLAG_WAKE = 0x00000001; 79 public final static int FLAG_VIRTUAL = 0x00000002; 80 81 public final static int FLAG_INJECTED = 0x01000000; 82 public final static int FLAG_TRUSTED = 0x02000000; 83 public final static int FLAG_FILTERED = 0x04000000; 84 public final static int FLAG_DISABLE_KEY_REPEAT = 0x08000000; 85 86 public final static int FLAG_INTERACTIVE = 0x20000000; 87 public final static int FLAG_PASS_TO_USER = 0x40000000; 88 89 // Flags used for indicating whether the internal and/or external input devices 90 // of some type are available. 91 public final static int PRESENCE_INTERNAL = 1 << 0; 92 public final static int PRESENCE_EXTERNAL = 1 << 1; 93 94 public final static boolean WATCH_POINTER = false; 95 96 /** 97 * Sticky broadcast of the current HDMI plugged state. 98 */ 99 public final static String ACTION_HDMI_PLUGGED = "android.intent.action.HDMI_PLUGGED"; 100 101 /** 102 * Extra in {@link #ACTION_HDMI_PLUGGED} indicating the state: true if 103 * plugged in to HDMI, false if not. 104 */ 105 public final static String EXTRA_HDMI_PLUGGED_STATE = "state"; 106 107 /** 108 * Pass this event to the user / app. To be returned from 109 * {@link #interceptKeyBeforeQueueing}. 110 */ 111 public final static int ACTION_PASS_TO_USER = 0x00000001; 112 113 /** 114 * Interface to the Window Manager state associated with a particular 115 * window. You can hold on to an instance of this interface from the call 116 * to prepareAddWindow() until removeWindow(). 117 */ 118 public interface WindowState { 119 /** 120 * Return the uid of the app that owns this window. 121 */ 122 int getOwningUid(); 123 124 /** 125 * Return the package name of the app that owns this window. 126 */ 127 String getOwningPackage(); 128 129 /** 130 * Perform standard frame computation. The result can be obtained with 131 * getFrame() if so desired. Must be called with the window manager 132 * lock held. 133 * 134 * @param parentFrame The frame of the parent container this window 135 * is in, used for computing its basic position. 136 * @param displayFrame The frame of the overall display in which this 137 * window can appear, used for constraining the overall dimensions 138 * of the window. 139 * @param overlayFrame The frame within the display that is inside 140 * of the overlay region. 141 * @param contentFrame The frame within the display in which we would 142 * like active content to appear. This will cause windows behind to 143 * be resized to match the given content frame. 144 * @param visibleFrame The frame within the display that the window 145 * is actually visible, used for computing its visible insets to be 146 * given to windows behind. 147 * This can be used as a hint for scrolling (avoiding resizing) 148 * the window to make certain that parts of its content 149 * are visible. 150 * @param decorFrame The decor frame specified by policy specific to this window, 151 * to use for proper cropping during animation. 152 */ 153 public void computeFrameLw(Rect parentFrame, Rect displayFrame, 154 Rect overlayFrame, Rect contentFrame, Rect visibleFrame, Rect decorFrame); 155 156 /** 157 * Retrieve the current frame of the window that has been assigned by 158 * the window manager. Must be called with the window manager lock held. 159 * 160 * @return Rect The rectangle holding the window frame. 161 */ 162 public Rect getFrameLw(); 163 164 /** 165 * Retrieve the current frame of the window that is actually shown. 166 * Must be called with the window manager lock held. 167 * 168 * @return Rect The rectangle holding the shown window frame. 169 */ 170 public RectF getShownFrameLw(); 171 172 /** 173 * Retrieve the frame of the display that this window was last 174 * laid out in. Must be called with the 175 * window manager lock held. 176 * 177 * @return Rect The rectangle holding the display frame. 178 */ 179 public Rect getDisplayFrameLw(); 180 181 /** 182 * Retrieve the frame of the area inside the overscan region of the 183 * display that this window was last laid out in. Must be called with the 184 * window manager lock held. 185 * 186 * @return Rect The rectangle holding the display overscan frame. 187 */ 188 public Rect getOverscanFrameLw(); 189 190 /** 191 * Retrieve the frame of the content area that this window was last 192 * laid out in. This is the area in which the content of the window 193 * should be placed. It will be smaller than the display frame to 194 * account for screen decorations such as a status bar or soft 195 * keyboard. Must be called with the 196 * window manager lock held. 197 * 198 * @return Rect The rectangle holding the content frame. 199 */ 200 public Rect getContentFrameLw(); 201 202 /** 203 * Retrieve the frame of the visible area that this window was last 204 * laid out in. This is the area of the screen in which the window 205 * will actually be fully visible. It will be smaller than the 206 * content frame to account for transient UI elements blocking it 207 * such as an input method's candidates UI. Must be called with the 208 * window manager lock held. 209 * 210 * @return Rect The rectangle holding the visible frame. 211 */ 212 public Rect getVisibleFrameLw(); 213 214 /** 215 * Returns true if this window is waiting to receive its given 216 * internal insets from the client app, and so should not impact the 217 * layout of other windows. 218 */ 219 public boolean getGivenInsetsPendingLw(); 220 221 /** 222 * Retrieve the insets given by this window's client for the content 223 * area of windows behind it. Must be called with the 224 * window manager lock held. 225 * 226 * @return Rect The left, top, right, and bottom insets, relative 227 * to the window's frame, of the actual contents. 228 */ 229 public Rect getGivenContentInsetsLw(); 230 231 /** 232 * Retrieve the insets given by this window's client for the visible 233 * area of windows behind it. Must be called with the 234 * window manager lock held. 235 * 236 * @return Rect The left, top, right, and bottom insets, relative 237 * to the window's frame, of the actual visible area. 238 */ 239 public Rect getGivenVisibleInsetsLw(); 240 241 /** 242 * Retrieve the current LayoutParams of the window. 243 * 244 * @return WindowManager.LayoutParams The window's internal LayoutParams 245 * instance. 246 */ 247 public WindowManager.LayoutParams getAttrs(); 248 249 /** 250 * Return whether this window needs the menu key shown. Must be called 251 * with window lock held, because it may need to traverse down through 252 * window list to determine the result. 253 * @param bottom The bottom-most window to consider when determining this. 254 */ 255 public boolean getNeedsMenuLw(WindowState bottom); 256 257 /** 258 * Retrieve the current system UI visibility flags associated with 259 * this window. 260 */ 261 public int getSystemUiVisibility(); 262 263 /** 264 * Get the layer at which this window's surface will be Z-ordered. 265 */ 266 public int getSurfaceLayer(); 267 268 /** 269 * Return the token for the application (actually activity) that owns 270 * this window. May return null for system windows. 271 * 272 * @return An IApplicationToken identifying the owning activity. 273 */ 274 public IApplicationToken getAppToken(); 275 276 /** 277 * Return true if this window is participating in voice interaction. 278 */ 279 public boolean isVoiceInteraction(); 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, int layoutParamsPrivateFlags, 392 boolean canReceiveKeys, 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 * Switch the keyboard layout for the given device. 401 * Direction should be +1 or -1 to go to the next or previous keyboard layout. 402 */ 403 public void switchKeyboardLayout(int deviceId, int direction); 404 405 public void shutdown(boolean confirm); 406 public void rebootSafeMode(boolean confirm); 407 408 /** 409 * Return the window manager lock needed to correctly call "Lw" methods. 410 */ 411 public Object getWindowManagerLock(); 412 413 /** Register a system listener for touch events */ 414 void registerPointerEventListener(PointerEventListener listener); 415 416 /** Unregister a system listener for touch events */ 417 void unregisterPointerEventListener(PointerEventListener listener); 418 } 419 420 public interface PointerEventListener { 421 /** 422 * 1. onPointerEvent will be called on the service.UiThread. 423 * 2. motionEvent will be recycled after onPointerEvent returns so if it is needed later a 424 * copy() must be made and the copy must be recycled. 425 **/ 426 public void onPointerEvent(MotionEvent motionEvent); 427 } 428 429 /** Window has been added to the screen. */ 430 public static final int TRANSIT_ENTER = 1; 431 /** Window has been removed from the screen. */ 432 public static final int TRANSIT_EXIT = 2; 433 /** Window has been made visible. */ 434 public static final int TRANSIT_SHOW = 3; 435 /** Window has been made invisible. 436 * TODO: Consider removal as this is unused. */ 437 public static final int TRANSIT_HIDE = 4; 438 /** The "application starting" preview window is no longer needed, and will 439 * animate away to show the real window. */ 440 public static final int TRANSIT_PREVIEW_DONE = 5; 441 442 // NOTE: screen off reasons are in order of significance, with more 443 // important ones lower than less important ones. 444 445 /** Screen turned off because of a device admin */ 446 public final int OFF_BECAUSE_OF_ADMIN = 1; 447 /** Screen turned off because of power button */ 448 public final int OFF_BECAUSE_OF_USER = 2; 449 /** Screen turned off because of timeout */ 450 public final int OFF_BECAUSE_OF_TIMEOUT = 3; 451 452 /** @hide */ 453 @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED}) 454 @Retention(RetentionPolicy.SOURCE) 455 public @interface UserRotationMode {} 456 457 /** When not otherwise specified by the activity's screenOrientation, rotation should be 458 * determined by the system (that is, using sensors). */ 459 public final int USER_ROTATION_FREE = 0; 460 /** When not otherwise specified by the activity's screenOrientation, rotation is set by 461 * the user. */ 462 public final int USER_ROTATION_LOCKED = 1; 463 464 /** 465 * Perform initialization of the policy. 466 * 467 * @param context The system context we are running in. 468 */ 469 public void init(Context context, IWindowManager windowManager, 470 WindowManagerFuncs windowManagerFuncs); 471 472 /** 473 * @return true if com.android.internal.R.bool#config_forceDefaultOrientation is true. 474 */ 475 public boolean isDefaultOrientationForced(); 476 477 /** 478 * Called by window manager once it has the initial, default native 479 * display dimensions. 480 */ 481 public void setInitialDisplaySize(Display display, int width, int height, int density); 482 483 /** 484 * Called by window manager to set the overscan region that should be used for the 485 * given display. 486 */ 487 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom); 488 489 /** 490 * Check permissions when adding a window. 491 * 492 * @param attrs The window's LayoutParams. 493 * @param outAppOp First element will be filled with the app op corresponding to 494 * this window, or OP_NONE. 495 * 496 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed; 497 * else an error code, usually 498 * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add. 499 */ 500 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp); 501 502 /** 503 * Check permissions when adding a window. 504 * 505 * @param attrs The window's LayoutParams. 506 * 507 * @return True if the window may only be shown to the current user, false if the window can 508 * be shown on all users' windows. 509 */ 510 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs); 511 512 /** 513 * Sanitize the layout parameters coming from a client. Allows the policy 514 * to do things like ensure that windows of a specific type can't take 515 * input focus. 516 * 517 * @param attrs The window layout parameters to be modified. These values 518 * are modified in-place. 519 */ 520 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs); 521 522 /** 523 * After the window manager has computed the current configuration based 524 * on its knowledge of the display and input devices, it gives the policy 525 * a chance to adjust the information contained in it. If you want to 526 * leave it as-is, simply do nothing. 527 * 528 * <p>This method may be called by any thread in the window manager, but 529 * no internal locks in the window manager will be held. 530 * 531 * @param config The Configuration being computed, for you to change as 532 * desired. 533 * @param keyboardPresence Flags that indicate whether internal or external 534 * keyboards are present. 535 * @param navigationPresence Flags that indicate whether internal or external 536 * navigation devices are present. 537 */ 538 public void adjustConfigurationLw(Configuration config, int keyboardPresence, 539 int navigationPresence); 540 541 /** 542 * Assign a window type to a layer. Allows you to control how different 543 * kinds of windows are ordered on-screen. 544 * 545 * @param type The type of window being assigned. 546 * 547 * @return int An arbitrary integer used to order windows, with lower 548 * numbers below higher ones. 549 */ 550 public int windowTypeToLayerLw(int type); 551 552 /** 553 * Return how to Z-order sub-windows in relation to the window they are 554 * attached to. Return positive to have them ordered in front, negative for 555 * behind. 556 * 557 * @param type The sub-window type code. 558 * 559 * @return int Layer in relation to the attached window, where positive is 560 * above and negative is below. 561 */ 562 public int subWindowTypeToLayerLw(int type); 563 564 /** 565 * Get the highest layer (actually one more than) that the wallpaper is 566 * allowed to be in. 567 */ 568 public int getMaxWallpaperLayer(); 569 570 /** 571 * Return the window layer at which windows appear above the normal 572 * universe (that is no longer impacted by the universe background 573 * transform). 574 */ 575 public int getAboveUniverseLayer(); 576 577 /** 578 * Return the display width available after excluding any screen 579 * decorations that can never be removed. That is, system bar or 580 * button bar. 581 */ 582 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation); 583 584 /** 585 * Return the display height available after excluding any screen 586 * decorations that can never be removed. That is, system bar or 587 * button bar. 588 */ 589 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation); 590 591 /** 592 * Return the available screen width that we should report for the 593 * configuration. This must be no larger than 594 * {@link #getNonDecorDisplayWidth(int, int, int)}; it may be smaller than 595 * that to account for more transient decoration like a status bar. 596 */ 597 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation); 598 599 /** 600 * Return the available screen height that we should report for the 601 * configuration. This must be no larger than 602 * {@link #getNonDecorDisplayHeight(int, int, int)}; it may be smaller than 603 * that to account for more transient decoration like a status bar. 604 */ 605 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation); 606 607 /** 608 * Return whether the given window should forcibly hide everything 609 * behind it. Typically returns true for the keyguard. 610 */ 611 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs); 612 613 /** 614 * Determine if a window that is behind one that is force hiding 615 * (as determined by {@link #doesForceHide}) should actually be hidden. 616 * For example, typically returns false for the status bar. Be careful 617 * to return false for any window that you may hide yourself, since this 618 * will conflict with what you set. 619 */ 620 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs); 621 622 /** 623 * Called when the system would like to show a UI to indicate that an 624 * application is starting. You can use this to add a 625 * APPLICATION_STARTING_TYPE window with the given appToken to the window 626 * manager (using the normal window manager APIs) that will be shown until 627 * the application displays its own window. This is called without the 628 * window manager locked so that you can call back into it. 629 * 630 * @param appToken Token of the application being started. 631 * @param packageName The name of the application package being started. 632 * @param theme Resource defining the application's overall visual theme. 633 * @param nonLocalizedLabel The default title label of the application if 634 * no data is found in the resource. 635 * @param labelRes The resource ID the application would like to use as its name. 636 * @param icon The resource ID the application would like to use as its icon. 637 * @param windowFlags Window layout flags. 638 * 639 * @return Optionally you can return the View that was used to create the 640 * window, for easy removal in removeStartingWindow. 641 * 642 * @see #removeStartingWindow 643 */ 644 public View addStartingWindow(IBinder appToken, String packageName, 645 int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, 646 int labelRes, int icon, int logo, int windowFlags); 647 648 /** 649 * Called when the first window of an application has been displayed, while 650 * {@link #addStartingWindow} has created a temporary initial window for 651 * that application. You should at this point remove the window from the 652 * window manager. This is called without the window manager locked so 653 * that you can call back into it. 654 * 655 * <p>Note: due to the nature of these functions not being called with the 656 * window manager locked, you must be prepared for this function to be 657 * called multiple times and/or an initial time with a null View window 658 * even if you previously returned one. 659 * 660 * @param appToken Token of the application that has started. 661 * @param window Window View that was returned by createStartingWindow. 662 * 663 * @see #addStartingWindow 664 */ 665 public void removeStartingWindow(IBinder appToken, View window); 666 667 /** 668 * Prepare for a window being added to the window manager. You can throw an 669 * exception here to prevent the window being added, or do whatever setup 670 * you need to keep track of the window. 671 * 672 * @param win The window being added. 673 * @param attrs The window's LayoutParams. 674 * 675 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed, else an 676 * error code to abort the add. 677 */ 678 public int prepareAddWindowLw(WindowState win, 679 WindowManager.LayoutParams attrs); 680 681 /** 682 * Called when a window is being removed from a window manager. Must not 683 * throw an exception -- clean up as much as possible. 684 * 685 * @param win The window being removed. 686 */ 687 public void removeWindowLw(WindowState win); 688 689 /** 690 * Control the animation to run when a window's state changes. Return a 691 * non-0 number to force the animation to a specific resource ID, or 0 692 * to use the default animation. 693 * 694 * @param win The window that is changing. 695 * @param transit What is happening to the window: {@link #TRANSIT_ENTER}, 696 * {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or 697 * {@link #TRANSIT_HIDE}. 698 * 699 * @return Resource ID of the actual animation to use, or 0 for none. 700 */ 701 public int selectAnimationLw(WindowState win, int transit); 702 703 /** 704 * Determine the animation to run for a rotation transition based on the 705 * top fullscreen windows {@link WindowManager.LayoutParams#rotationAnimation} 706 * and whether it is currently fullscreen and frontmost. 707 * 708 * @param anim The exiting animation resource id is stored in anim[0], the 709 * entering animation resource id is stored in anim[1]. 710 */ 711 public void selectRotationAnimationLw(int anim[]); 712 713 /** 714 * Validate whether the current top fullscreen has specified the same 715 * {@link WindowManager.LayoutParams#rotationAnimation} value as that 716 * being passed in from the previous top fullscreen window. 717 * 718 * @param exitAnimId exiting resource id from the previous window. 719 * @param enterAnimId entering resource id from the previous window. 720 * @param forceDefault For rotation animations only, if true ignore the 721 * animation values and just return false. 722 * @return true if the previous values are still valid, false if they 723 * should be replaced with the default. 724 */ 725 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, 726 boolean forceDefault); 727 728 /** 729 * Create and return an animation to re-display a force hidden window. 730 */ 731 public Animation createForceHideEnterAnimation(boolean onWallpaper); 732 733 /** 734 * Called from the input reader thread before a key is enqueued. 735 * 736 * <p>There are some actions that need to be handled here because they 737 * affect the power state of the device, for example, the power keys. 738 * Generally, it's best to keep as little as possible in the queue thread 739 * because it's the most fragile. 740 * @param event The key event. 741 * @param policyFlags The policy flags associated with the key. 742 * 743 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 744 */ 745 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags); 746 747 /** 748 * Called from the input reader thread before a motion is enqueued when the screen is off. 749 * 750 * <p>There are some actions that need to be handled here because they 751 * affect the power state of the device, for example, waking on motions. 752 * Generally, it's best to keep as little as possible in the queue thread 753 * because it's the most fragile. 754 * @param policyFlags The policy flags associated with the motion. 755 * 756 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 757 */ 758 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags); 759 760 /** 761 * Called from the input dispatcher thread before a key is dispatched to a window. 762 * 763 * <p>Allows you to define 764 * behavior for keys that can not be overridden by applications. 765 * This method is called from the input thread, with no locks held. 766 * 767 * @param win The window that currently has focus. This is where the key 768 * event will normally go. 769 * @param event The key event. 770 * @param policyFlags The policy flags associated with the key. 771 * @return 0 if the key should be dispatched immediately, -1 if the key should 772 * not be dispatched ever, or a positive value indicating the number of 773 * milliseconds by which the key dispatch should be delayed before trying 774 * again. 775 */ 776 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags); 777 778 /** 779 * Called from the input dispatcher thread when an application did not handle 780 * a key that was dispatched to it. 781 * 782 * <p>Allows you to define default global behavior for keys that were not handled 783 * by applications. This method is called from the input thread, with no locks held. 784 * 785 * @param win The window that currently has focus. This is where the key 786 * event will normally go. 787 * @param event The key event. 788 * @param policyFlags The policy flags associated with the key. 789 * @return Returns an alternate key event to redispatch as a fallback, or null to give up. 790 * The caller is responsible for recycling the key event. 791 */ 792 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags); 793 794 /** 795 * Called when layout of the windows is about to start. 796 * 797 * @param isDefaultDisplay true if window is on {@link Display#DEFAULT_DISPLAY}. 798 * @param displayWidth The current full width of the screen. 799 * @param displayHeight The current full height of the screen. 800 * @param displayRotation The current rotation being applied to the base 801 * window. 802 */ 803 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, 804 int displayRotation); 805 806 /** 807 * Returns the bottom-most layer of the system decor, above which no policy decor should 808 * be applied. 809 */ 810 public int getSystemDecorLayerLw(); 811 812 /** 813 * Return the rectangle of the screen that is available for applications to run in. 814 * This will be called immediately after {@link #beginLayoutLw}. 815 * 816 * @param r The rectangle to be filled with the boundaries available to applications. 817 */ 818 public void getContentRectLw(Rect r); 819 820 /** 821 * Called for each window attached to the window manager as layout is 822 * proceeding. The implementation of this function must take care of 823 * setting the window's frame, either here or in finishLayout(). 824 * 825 * @param win The window being positioned. 826 * @param attrs The LayoutParams of the window. 827 * @param attached For sub-windows, the window it is attached to; this 828 * window will already have had layoutWindow() called on it 829 * so you can use its Rect. Otherwise null. 830 */ 831 public void layoutWindowLw(WindowState win, 832 WindowManager.LayoutParams attrs, WindowState attached); 833 834 835 /** 836 * Return the insets for the areas covered by system windows. These values 837 * are computed on the most recent layout, so they are not guaranteed to 838 * be correct. 839 * 840 * @param attrs The LayoutParams of the window. 841 * @param contentInset The areas covered by system windows, expressed as positive insets 842 * 843 */ 844 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset); 845 846 /** 847 * Called when layout of the windows is finished. After this function has 848 * returned, all windows given to layoutWindow() <em>must</em> have had a 849 * frame assigned. 850 */ 851 public void finishLayoutLw(); 852 853 /** Layout state may have changed (so another layout will be performed) */ 854 static final int FINISH_LAYOUT_REDO_LAYOUT = 0x0001; 855 /** Configuration state may have changed */ 856 static final int FINISH_LAYOUT_REDO_CONFIG = 0x0002; 857 /** Wallpaper may need to move */ 858 static final int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004; 859 /** Need to recompute animations */ 860 static final int FINISH_LAYOUT_REDO_ANIM = 0x0008; 861 862 /** 863 * Called following layout of all windows before each window has policy applied. 864 * 865 * @param displayWidth The current full width of the screen. 866 * @param displayHeight The current full height of the screen. 867 */ 868 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight); 869 870 /** 871 * Called following layout of all window to apply policy to each window. 872 * 873 * @param win The window being positioned. 874 * @param attrs The LayoutParams of the window. 875 */ 876 public void applyPostLayoutPolicyLw(WindowState win, 877 WindowManager.LayoutParams attrs); 878 879 /** 880 * Called following layout of all windows and after policy has been applied 881 * to each window. If in this function you do 882 * something that may have modified the animation state of another window, 883 * be sure to return non-zero in order to perform another pass through layout. 884 * 885 * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT}, 886 * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER}, 887 * or {@link #FINISH_LAYOUT_REDO_ANIM}. 888 */ 889 public int finishPostLayoutPolicyLw(); 890 891 /** 892 * Return true if it is okay to perform animations for an app transition 893 * that is about to occur. You may return false for this if, for example, 894 * the lock screen is currently displayed so the switch should happen 895 * immediately. 896 */ 897 public boolean allowAppAnimationsLw(); 898 899 900 /** 901 * A new window has been focused. 902 */ 903 public int focusChangedLw(WindowState lastFocus, WindowState newFocus); 904 905 /** 906 * Called when the device is going to sleep. 907 * 908 * @param why {@link #OFF_BECAUSE_OF_USER} or 909 * {@link #OFF_BECAUSE_OF_TIMEOUT}. 910 */ 911 public void goingToSleep(int why); 912 913 public interface ScreenOnListener { 914 void onScreenOn(); 915 } 916 917 /** 918 * Called when the device is waking up. 919 * Must call back on the listener to tell it when the higher-level system 920 * is ready for the screen to go on (i.e. the lock screen is shown). 921 */ 922 public void wakingUp(ScreenOnListener screenOnListener); 923 924 /** 925 * Return whether the screen is about to turn on or is currently on. 926 */ 927 public boolean isScreenOnEarly(); 928 929 /** 930 * Return whether the screen is fully turned on. 931 */ 932 public boolean isScreenOnFully(); 933 934 /** 935 * Tell the policy that the lid switch has changed state. 936 * @param whenNanos The time when the change occurred in uptime nanoseconds. 937 * @param lidOpen True if the lid is now open. 938 */ 939 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); 940 941 /** 942 * Tell the policy if anyone is requesting that keyguard not come on. 943 * 944 * @param enabled Whether keyguard can be on or not. does not actually 945 * turn it on, unless it was previously disabled with this function. 946 * 947 * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard() 948 * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard() 949 */ 950 @SuppressWarnings("javadoc") 951 public void enableKeyguard(boolean enabled); 952 953 /** 954 * Callback used by {@link WindowManagerPolicy#exitKeyguardSecurely} 955 */ 956 interface OnKeyguardExitResult { 957 void onKeyguardExitResult(boolean success); 958 } 959 960 /** 961 * Tell the policy if anyone is requesting the keyguard to exit securely 962 * (this would be called after the keyguard was disabled) 963 * @param callback Callback to send the result back. 964 * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult) 965 */ 966 @SuppressWarnings("javadoc") 967 void exitKeyguardSecurely(OnKeyguardExitResult callback); 968 969 /** 970 * isKeyguardLocked 971 * 972 * Return whether the keyguard is currently locked. 973 * 974 * @return true if in keyguard is locked. 975 */ 976 public boolean isKeyguardLocked(); 977 978 /** 979 * isKeyguardSecure 980 * 981 * Return whether the keyguard requires a password to unlock. 982 * 983 * @return true if in keyguard is secure. 984 */ 985 public boolean isKeyguardSecure(); 986 987 /** 988 * inKeyguardRestrictedKeyInputMode 989 * 990 * if keyguard screen is showing or in restricted key input mode (i.e. in 991 * keyguard password emergency screen). When in such mode, certain keys, 992 * such as the Home key and the right soft keys, don't work. 993 * 994 * @return true if in keyguard restricted input mode. 995 */ 996 public boolean inKeyguardRestrictedKeyInputMode(); 997 998 /** 999 * Ask the policy to dismiss the keyguard, if it is currently shown. 1000 */ 1001 public void dismissKeyguardLw(); 1002 1003 /** 1004 * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method 1005 * returns true as soon as we know that Keyguard is disabled. 1006 * 1007 * @return true if the keyguard has drawn. 1008 */ 1009 public boolean isKeyguardDrawnLw(); 1010 1011 /** 1012 * Given an orientation constant, returns the appropriate surface rotation, 1013 * taking into account sensors, docking mode, rotation lock, and other factors. 1014 * 1015 * @param orientation An orientation constant, such as 1016 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}. 1017 * @param lastRotation The most recently used rotation. 1018 * @return The surface rotation to use. 1019 */ 1020 public int rotationForOrientationLw(@ActivityInfo.ScreenOrientation int orientation, 1021 int lastRotation); 1022 1023 /** 1024 * Given an orientation constant and a rotation, returns true if the rotation 1025 * has compatible metrics to the requested orientation. For example, if 1026 * the application requested landscape and got seascape, then the rotation 1027 * has compatible metrics; if the application requested portrait and got landscape, 1028 * then the rotation has incompatible metrics; if the application did not specify 1029 * a preference, then anything goes. 1030 * 1031 * @param orientation An orientation constant, such as 1032 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}. 1033 * @param rotation The rotation to check. 1034 * @return True if the rotation is compatible with the requested orientation. 1035 */ 1036 public boolean rotationHasCompatibleMetricsLw(@ActivityInfo.ScreenOrientation int orientation, 1037 int rotation); 1038 1039 /** 1040 * Called by the window manager when the rotation changes. 1041 * 1042 * @param rotation The new rotation. 1043 */ 1044 public void setRotationLw(int rotation); 1045 1046 /** 1047 * Called when the system is mostly done booting to set whether 1048 * the system should go into safe mode. 1049 */ 1050 public void setSafeMode(boolean safeMode); 1051 1052 /** 1053 * Called when the system is mostly done booting. 1054 */ 1055 public void systemReady(); 1056 1057 /** 1058 * Called when the system is done booting to the point where the 1059 * user can start interacting with it. 1060 */ 1061 public void systemBooted(); 1062 1063 /** 1064 * Show boot time message to the user. 1065 */ 1066 public void showBootMessage(final CharSequence msg, final boolean always); 1067 1068 /** 1069 * Hide the UI for showing boot messages, never to be displayed again. 1070 */ 1071 public void hideBootMessages(); 1072 1073 /** 1074 * Called when userActivity is signalled in the power manager. 1075 * This is safe to call from any thread, with any window manager locks held or not. 1076 */ 1077 public void userActivity(); 1078 1079 /** 1080 * Called when we have finished booting and can now display the home 1081 * screen to the user. This will happen after systemReady(), and at 1082 * this point the display is active. 1083 */ 1084 public void enableScreenAfterBoot(); 1085 1086 public void setCurrentOrientationLw(@ActivityInfo.ScreenOrientation int newOrientation); 1087 1088 /** 1089 * Call from application to perform haptic feedback on its window. 1090 */ 1091 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always); 1092 1093 /** 1094 * Called when we have started keeping the screen on because a window 1095 * requesting this has become visible. 1096 */ 1097 public void keepScreenOnStartedLw(); 1098 1099 /** 1100 * Called when we have stopped keeping the screen on because the last window 1101 * requesting this is no longer visible. 1102 */ 1103 public void keepScreenOnStoppedLw(); 1104 1105 /** 1106 * Gets the current user rotation mode. 1107 * 1108 * @return The rotation mode. 1109 * 1110 * @see WindowManagerPolicy#USER_ROTATION_LOCKED 1111 * @see WindowManagerPolicy#USER_ROTATION_FREE 1112 */ 1113 @UserRotationMode 1114 public int getUserRotationMode(); 1115 1116 /** 1117 * Inform the policy that the user has chosen a preferred orientation ("rotation lock"). 1118 * 1119 * @param mode One of {@link WindowManagerPolicy#USER_ROTATION_LOCKED} or 1120 * {@link WindowManagerPolicy#USER_ROTATION_FREE}. 1121 * @param rotation One of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90}, 1122 * {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270}. 1123 */ 1124 public void setUserRotationMode(@UserRotationMode int mode, @Surface.Rotation int rotation); 1125 1126 /** 1127 * Called when a new system UI visibility is being reported, allowing 1128 * the policy to adjust what is actually reported. 1129 * @param visibility The raw visibility reported by the status bar. 1130 * @return The new desired visibility. 1131 */ 1132 public int adjustSystemUiVisibilityLw(int visibility); 1133 1134 /** 1135 * Specifies whether there is an on-screen navigation bar separate from the status bar. 1136 */ 1137 public boolean hasNavigationBar(); 1138 1139 /** 1140 * Lock the device now. 1141 */ 1142 public void lockNow(Bundle options); 1143 1144 /** 1145 * Set the last used input method window state. This state is used to make IME transition 1146 * smooth. 1147 * @hide 1148 */ 1149 public void setLastInputMethodWindowLw(WindowState ime, WindowState target); 1150 1151 /** 1152 * Show the recents task list app. 1153 * @hide 1154 */ 1155 public void showRecentApps(); 1156 1157 /** 1158 * @return The current height of the input method window. 1159 */ 1160 public int getInputMethodWindowVisibleHeightLw(); 1161 1162 /** 1163 * Called when the current user changes. Guaranteed to be called before the broadcast 1164 * of the new user id is made to all listeners. 1165 * 1166 * @param newUserId The id of the incoming user. 1167 */ 1168 public void setCurrentUserLw(int newUserId); 1169 1170 /** 1171 * Print the WindowManagerPolicy's state into the given stream. 1172 * 1173 * @param prefix Text to print at the front of each line. 1174 * @param writer The PrintWriter to which you should dump your state. This will be 1175 * closed for you after you return. 1176 * @param args additional arguments to the dump request. 1177 */ 1178 public void dump(String prefix, PrintWriter writer, String[] args); 1179 1180 /** 1181 * Returns whether a given window type can be magnified. 1182 * 1183 * @param windowType The window type. 1184 * @return True if the window can be magnified. 1185 */ 1186 public boolean canMagnifyWindow(int windowType); 1187 1188 /** 1189 * Returns whether a given window type is considered a top level one. 1190 * A top level window does not have a container, i.e. attached window, 1191 * or if it has a container it is laid out as a top-level window, not 1192 * as a child of its container. 1193 * 1194 * @param windowType The window type. 1195 * @return True if the window is a top level one. 1196 */ 1197 public boolean isTopLevelWindow(int windowType); 1198} 1199