1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view; 18 19 import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; 20 import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; 21 import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; 22 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL; 23 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; 24 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; 25 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; 26 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; 27 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; 28 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; 29 import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; 30 import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY; 31 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; 32 import static android.view.WindowManager.LayoutParams.TYPE_DRAG; 33 import static android.view.WindowManager.LayoutParams.TYPE_DREAM; 34 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; 35 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; 36 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; 37 import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; 38 import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; 39 import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; 40 import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; 41 import static android.view.WindowManager.LayoutParams.TYPE_PHONE; 42 import static android.view.WindowManager.LayoutParams.TYPE_POINTER; 43 import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; 44 import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; 45 import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION; 46 import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; 47 import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; 48 import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; 49 import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; 50 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; 51 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; 52 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; 53 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; 54 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; 55 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; 56 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; 57 import static android.view.WindowManager.LayoutParams.TYPE_TOAST; 58 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; 59 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; 60 import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; 61 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; 62 import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; 63 64 import android.annotation.IntDef; 65 import android.annotation.Nullable; 66 import android.annotation.SystemApi; 67 import android.app.ActivityManager.StackId; 68 import android.content.Context; 69 import android.content.pm.ActivityInfo; 70 import android.content.res.CompatibilityInfo; 71 import android.content.res.Configuration; 72 import android.graphics.Point; 73 import android.graphics.Rect; 74 import android.os.Bundle; 75 import android.os.IBinder; 76 import android.os.Looper; 77 import android.os.RemoteException; 78 import android.util.Slog; 79 import android.view.animation.Animation; 80 81 import com.android.internal.policy.IKeyguardDismissCallback; 82 import com.android.internal.policy.IShortcutService; 83 84 import java.io.PrintWriter; 85 import java.lang.annotation.Retention; 86 import java.lang.annotation.RetentionPolicy; 87 88 /** 89 * This interface supplies all UI-specific behavior of the window manager. An 90 * instance of it is created by the window manager when it starts up, and allows 91 * customization of window layering, special window types, key dispatching, and 92 * layout. 93 * 94 * <p>Because this provides deep interaction with the system window manager, 95 * specific methods on this interface can be called from a variety of contexts 96 * with various restrictions on what they can do. These are encoded through 97 * a suffixes at the end of a method encoding the thread the method is called 98 * from and any locks that are held when it is being called; if no suffix 99 * is attached to a method, then it is not called with any locks and may be 100 * called from the main window manager thread or another thread calling into 101 * the window manager. 102 * 103 * <p>The current suffixes are: 104 * 105 * <dl> 106 * <dt> Ti <dd> Called from the input thread. This is the thread that 107 * collects pending input events and dispatches them to the appropriate window. 108 * It may block waiting for events to be processed, so that the input stream is 109 * properly serialized. 110 * <dt> Tq <dd> Called from the low-level input queue thread. This is the 111 * thread that reads events out of the raw input devices and places them 112 * into the global input queue that is read by the <var>Ti</var> thread. 113 * This thread should not block for a long period of time on anything but the 114 * key driver. 115 * <dt> Lw <dd> Called with the main window manager lock held. Because the 116 * window manager is a very low-level system service, there are few other 117 * system services you can call with this lock held. It is explicitly okay to 118 * make calls into the package manager and power manager; it is explicitly not 119 * okay to make calls into the activity manager or most other services. Note that 120 * {@link android.content.Context#checkPermission(String, int, int)} and 121 * variations require calling into the activity manager. 122 * <dt> Li <dd> Called with the input thread lock held. This lock can be 123 * acquired by the window manager while it holds the window lock, so this is 124 * even more restrictive than <var>Lw</var>. 125 * </dl> 126 * 127 * @hide 128 */ 129 public interface WindowManagerPolicy { 130 // Policy flags. These flags are also defined in frameworks/base/include/ui/Input.h. 131 public final static int FLAG_WAKE = 0x00000001; 132 public final static int FLAG_VIRTUAL = 0x00000002; 133 134 public final static int FLAG_INJECTED = 0x01000000; 135 public final static int FLAG_TRUSTED = 0x02000000; 136 public final static int FLAG_FILTERED = 0x04000000; 137 public final static int FLAG_DISABLE_KEY_REPEAT = 0x08000000; 138 139 public final static int FLAG_INTERACTIVE = 0x20000000; 140 public final static int FLAG_PASS_TO_USER = 0x40000000; 141 142 // Flags for IActivityManager.keyguardGoingAway() 143 public final static int KEYGUARD_GOING_AWAY_FLAG_TO_SHADE = 1 << 0; 144 public final static int KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS = 1 << 1; 145 public final static int KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER = 1 << 2; 146 147 // Flags used for indicating whether the internal and/or external input devices 148 // of some type are available. 149 public final static int PRESENCE_INTERNAL = 1 << 0; 150 public final static int PRESENCE_EXTERNAL = 1 << 1; 151 152 public final static boolean WATCH_POINTER = false; 153 154 /** 155 * Sticky broadcast of the current HDMI plugged state. 156 */ 157 public final static String ACTION_HDMI_PLUGGED = "android.intent.action.HDMI_PLUGGED"; 158 159 /** 160 * Extra in {@link #ACTION_HDMI_PLUGGED} indicating the state: true if 161 * plugged in to HDMI, false if not. 162 */ 163 public final static String EXTRA_HDMI_PLUGGED_STATE = "state"; 164 165 /** 166 * Set to {@code true} when intent was invoked from pressing the home key. 167 * @hide 168 */ 169 @SystemApi 170 public static final String EXTRA_FROM_HOME_KEY = "android.intent.extra.FROM_HOME_KEY"; 171 172 /** 173 * Pass this event to the user / app. To be returned from 174 * {@link #interceptKeyBeforeQueueing}. 175 */ 176 public final static int ACTION_PASS_TO_USER = 0x00000001; 177 178 /** 179 * Register shortcuts for window manager to dispatch. 180 * Shortcut code is packed as (metaState << Integer.SIZE) | keyCode 181 * @hide 182 */ 183 void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver) 184 throws RemoteException; 185 186 /** 187 * Called when the Keyguard occluded state changed. 188 * @param occluded Whether Keyguard is currently occluded or not. 189 */ 190 void onKeyguardOccludedChangedLw(boolean occluded); 191 192 /** 193 * Interface to the Window Manager state associated with a particular 194 * window. You can hold on to an instance of this interface from the call 195 * to prepareAddWindow() until removeWindow(). 196 */ 197 public interface WindowState { 198 /** 199 * Return the uid of the app that owns this window. 200 */ 201 int getOwningUid(); 202 203 /** 204 * Return the package name of the app that owns this window. 205 */ 206 String getOwningPackage(); 207 208 /** 209 * Perform standard frame computation. The result can be obtained with 210 * getFrame() if so desired. Must be called with the window manager 211 * lock held. 212 * 213 * @param parentFrame The frame of the parent container this window 214 * is in, used for computing its basic position. 215 * @param displayFrame The frame of the overall display in which this 216 * window can appear, used for constraining the overall dimensions 217 * of the window. 218 * @param overlayFrame The frame within the display that is inside 219 * of the overlay region. 220 * @param contentFrame The frame within the display in which we would 221 * like active content to appear. This will cause windows behind to 222 * be resized to match the given content frame. 223 * @param visibleFrame The frame within the display that the window 224 * is actually visible, used for computing its visible insets to be 225 * given to windows behind. 226 * This can be used as a hint for scrolling (avoiding resizing) 227 * the window to make certain that parts of its content 228 * are visible. 229 * @param decorFrame The decor frame specified by policy specific to this window, 230 * to use for proper cropping during animation. 231 * @param stableFrame The frame around which stable system decoration is positioned. 232 * @param outsetFrame The frame that includes areas that aren't part of the surface but we 233 * want to treat them as such. 234 */ 235 public void computeFrameLw(Rect parentFrame, Rect displayFrame, 236 Rect overlayFrame, Rect contentFrame, Rect visibleFrame, Rect decorFrame, 237 Rect stableFrame, Rect outsetFrame); 238 239 /** 240 * Retrieve the current frame of the window that has been assigned by 241 * the window manager. Must be called with the window manager lock held. 242 * 243 * @return Rect The rectangle holding the window frame. 244 */ 245 public Rect getFrameLw(); 246 247 /** 248 * Retrieve the current position of the window that is actually shown. 249 * Must be called with the window manager lock held. 250 * 251 * @return Point The point holding the shown window position. 252 */ 253 public Point getShownPositionLw(); 254 255 /** 256 * Retrieve the frame of the display that this window was last 257 * laid out in. Must be called with the 258 * window manager lock held. 259 * 260 * @return Rect The rectangle holding the display frame. 261 */ 262 public Rect getDisplayFrameLw(); 263 264 /** 265 * Retrieve the frame of the area inside the overscan region of the 266 * display that this window was last laid out in. Must be called with the 267 * window manager lock held. 268 * 269 * @return Rect The rectangle holding the display overscan frame. 270 */ 271 public Rect getOverscanFrameLw(); 272 273 /** 274 * Retrieve the frame of the content area that this window was last 275 * laid out in. This is the area in which the content of the window 276 * should be placed. It will be smaller than the display frame to 277 * account for screen decorations such as a status bar or soft 278 * keyboard. Must be called with the 279 * window manager lock held. 280 * 281 * @return Rect The rectangle holding the content frame. 282 */ 283 public Rect getContentFrameLw(); 284 285 /** 286 * Retrieve the frame of the visible area that this window was last 287 * laid out in. This is the area of the screen in which the window 288 * will actually be fully visible. It will be smaller than the 289 * content frame to account for transient UI elements blocking it 290 * such as an input method's candidates UI. Must be called with the 291 * window manager lock held. 292 * 293 * @return Rect The rectangle holding the visible frame. 294 */ 295 public Rect getVisibleFrameLw(); 296 297 /** 298 * Returns true if this window is waiting to receive its given 299 * internal insets from the client app, and so should not impact the 300 * layout of other windows. 301 */ 302 public boolean getGivenInsetsPendingLw(); 303 304 /** 305 * Retrieve the insets given by this window's client for the content 306 * area of windows behind it. Must be called with the 307 * window manager lock held. 308 * 309 * @return Rect The left, top, right, and bottom insets, relative 310 * to the window's frame, of the actual contents. 311 */ 312 public Rect getGivenContentInsetsLw(); 313 314 /** 315 * Retrieve the insets given by this window's client for the visible 316 * area of windows behind it. Must be called with the 317 * window manager lock held. 318 * 319 * @return Rect The left, top, right, and bottom insets, relative 320 * to the window's frame, of the actual visible area. 321 */ 322 public Rect getGivenVisibleInsetsLw(); 323 324 /** 325 * Retrieve the current LayoutParams of the window. 326 * 327 * @return WindowManager.LayoutParams The window's internal LayoutParams 328 * instance. 329 */ 330 public WindowManager.LayoutParams getAttrs(); 331 332 /** 333 * Return whether this window needs the menu key shown. Must be called 334 * with window lock held, because it may need to traverse down through 335 * window list to determine the result. 336 * @param bottom The bottom-most window to consider when determining this. 337 */ 338 public boolean getNeedsMenuLw(WindowState bottom); 339 340 /** 341 * Retrieve the current system UI visibility flags associated with 342 * this window. 343 */ 344 public int getSystemUiVisibility(); 345 346 /** 347 * Get the layer at which this window's surface will be Z-ordered. 348 */ 349 public int getSurfaceLayer(); 350 351 /** 352 * Retrieve the type of the top-level window. 353 * 354 * @return the base type of the parent window if attached or its own type otherwise 355 */ 356 public int getBaseType(); 357 358 /** 359 * Return the token for the application (actually activity) that owns 360 * this window. May return null for system windows. 361 * 362 * @return An IApplicationToken identifying the owning activity. 363 */ 364 public IApplicationToken getAppToken(); 365 366 /** 367 * Return true if this window is participating in voice interaction. 368 */ 369 public boolean isVoiceInteraction(); 370 371 /** 372 * Return true if, at any point, the application token associated with 373 * this window has actually displayed any windows. This is most useful 374 * with the "starting up" window to determine if any windows were 375 * displayed when it is closed. 376 * 377 * @return Returns true if one or more windows have been displayed, 378 * else false. 379 */ 380 public boolean hasAppShownWindows(); 381 382 /** 383 * Is this window visible? It is not visible if there is no 384 * surface, or we are in the process of running an exit animation 385 * that will remove the surface. 386 */ 387 boolean isVisibleLw(); 388 389 /** 390 * Is this window currently visible to the user on-screen? It is 391 * displayed either if it is visible or it is currently running an 392 * animation before no longer being visible. Must be called with the 393 * window manager lock held. 394 */ 395 boolean isDisplayedLw(); 396 397 /** 398 * Return true if this window (or a window it is attached to, but not 399 * considering its app token) is currently animating. 400 */ 401 boolean isAnimatingLw(); 402 403 /** 404 * @return Whether the window can affect SystemUI flags, meaning that SystemUI (system bars, 405 * for example) will be affected by the flags specified in this window. This is the 406 * case when the surface is on screen but not exiting. 407 */ 408 boolean canAffectSystemUiFlags(); 409 410 /** 411 * Is this window considered to be gone for purposes of layout? 412 */ 413 boolean isGoneForLayoutLw(); 414 415 /** 416 * Returns true if the window has a surface that it has drawn a 417 * complete UI in to. Note that this is different from {@link #hasDrawnLw()} 418 * in that it also returns true if the window is READY_TO_SHOW, but was not yet 419 * promoted to HAS_DRAWN. 420 */ 421 boolean isDrawnLw(); 422 423 /** 424 * Returns true if this window has been shown on screen at some time in 425 * the past. Must be called with the window manager lock held. 426 */ 427 public boolean hasDrawnLw(); 428 429 /** 430 * Can be called by the policy to force a window to be hidden, 431 * regardless of whether the client or window manager would like 432 * it shown. Must be called with the window manager lock held. 433 * Returns true if {@link #showLw} was last called for the window. 434 */ 435 public boolean hideLw(boolean doAnimation); 436 437 /** 438 * Can be called to undo the effect of {@link #hideLw}, allowing a 439 * window to be shown as long as the window manager and client would 440 * also like it to be shown. Must be called with the window manager 441 * lock held. 442 * Returns true if {@link #hideLw} was last called for the window. 443 */ 444 public boolean showLw(boolean doAnimation); 445 446 /** 447 * Check whether the process hosting this window is currently alive. 448 */ 449 public boolean isAlive(); 450 451 /** 452 * Check if window is on {@link Display#DEFAULT_DISPLAY}. 453 * @return true if window is on default display. 454 */ 455 public boolean isDefaultDisplay(); 456 457 /** 458 * Check whether the window is currently dimming. 459 */ 460 public boolean isDimming(); 461 462 /** 463 * @return the stack id this windows belongs to, or {@link StackId#INVALID_STACK_ID} if 464 * not attached to any stack. 465 */ 466 int getStackId(); 467 468 /** 469 * Returns true if the window is current in multi-windowing mode. i.e. it shares the 470 * screen with other application windows. 471 */ 472 public boolean isInMultiWindowMode(); 473 474 public int getRotationAnimationHint(); 475 476 public boolean isInputMethodWindow(); 477 478 public int getDisplayId(); 479 480 /** 481 * Returns true if the window owner can add internal system windows. 482 * That is, they have {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW}. 483 */ 484 default boolean canAddInternalSystemWindow() { 485 return false; 486 } 487 } 488 489 /** 490 * Representation of a input consumer that the policy has added to the 491 * window manager to consume input events going to windows below it. 492 */ 493 public interface InputConsumer { 494 /** 495 * Remove the input consumer from the window manager. 496 */ 497 void dismiss(); 498 } 499 500 /** 501 * Holds the contents of a starting window. {@link #addSplashScreen} needs to wrap the 502 * contents of the starting window into an class implementing this interface, which then will be 503 * held by WM and released with {@link #remove} when no longer needed. 504 */ 505 interface StartingSurface { 506 507 /** 508 * Removes the starting window surface. Do not hold the window manager lock when calling 509 * this method! 510 */ 511 void remove(); 512 } 513 514 /** 515 * Interface for calling back in to the window manager that is private 516 * between it and the policy. 517 */ 518 public interface WindowManagerFuncs { 519 public static final int LID_ABSENT = -1; 520 public static final int LID_CLOSED = 0; 521 public static final int LID_OPEN = 1; 522 523 public static final int CAMERA_LENS_COVER_ABSENT = -1; 524 public static final int CAMERA_LENS_UNCOVERED = 0; 525 public static final int CAMERA_LENS_COVERED = 1; 526 527 /** 528 * Ask the window manager to re-evaluate the system UI flags. 529 */ 530 public void reevaluateStatusBarVisibility(); 531 532 /** 533 * Add a input consumer which will consume all input events going to any window below it. 534 */ 535 public InputConsumer createInputConsumer(Looper looper, String name, 536 InputEventReceiver.Factory inputEventReceiverFactory); 537 538 /** 539 * Returns a code that describes the current state of the lid switch. 540 */ 541 public int getLidState(); 542 543 /** 544 * Lock the device now. 545 */ 546 public void lockDeviceNow(); 547 548 /** 549 * Returns a code that descripbes whether the camera lens is covered or not. 550 */ 551 public int getCameraLensCoverState(); 552 553 /** 554 * Switch the input method, to be precise, input method subtype. 555 * 556 * @param forwardDirection {@code true} to rotate in a forward direction. 557 */ 558 public void switchInputMethod(boolean forwardDirection); 559 560 public void shutdown(boolean confirm); 561 public void reboot(boolean confirm); 562 public void rebootSafeMode(boolean confirm); 563 564 /** 565 * Return the window manager lock needed to correctly call "Lw" methods. 566 */ 567 public Object getWindowManagerLock(); 568 569 /** Register a system listener for touch events */ 570 void registerPointerEventListener(PointerEventListener listener); 571 572 /** Unregister a system listener for touch events */ 573 void unregisterPointerEventListener(PointerEventListener listener); 574 575 /** 576 * @return The content insets of the docked divider window. 577 */ 578 int getDockedDividerInsetsLw(); 579 580 /** 581 * Retrieves the {@param outBounds} from the stack with id {@param stackId}. 582 */ 583 void getStackBounds(int stackId, Rect outBounds); 584 585 /** 586 * Notifies window manager that {@link #isShowingDreamLw} has changed. 587 */ 588 void notifyShowingDreamChanged(); 589 590 /** 591 * @return The currently active input method window. 592 */ 593 WindowState getInputMethodWindowLw(); 594 595 /** 596 * Notifies window manager that {@link #isKeyguardTrustedLw} has changed. 597 */ 598 void notifyKeyguardTrustedChanged(); 599 600 /** 601 * Notifies the window manager that screen is being turned off. 602 * 603 * @param listener callback to call when display can be turned off 604 */ 605 void screenTurningOff(ScreenOffListener listener); 606 } 607 608 public interface PointerEventListener { 609 /** 610 * 1. onPointerEvent will be called on the service.UiThread. 611 * 2. motionEvent will be recycled after onPointerEvent returns so if it is needed later a 612 * copy() must be made and the copy must be recycled. 613 **/ 614 public void onPointerEvent(MotionEvent motionEvent); 615 } 616 617 /** Window has been added to the screen. */ 618 public static final int TRANSIT_ENTER = 1; 619 /** Window has been removed from the screen. */ 620 public static final int TRANSIT_EXIT = 2; 621 /** Window has been made visible. */ 622 public static final int TRANSIT_SHOW = 3; 623 /** Window has been made invisible. 624 * TODO: Consider removal as this is unused. */ 625 public static final int TRANSIT_HIDE = 4; 626 /** The "application starting" preview window is no longer needed, and will 627 * animate away to show the real window. */ 628 public static final int TRANSIT_PREVIEW_DONE = 5; 629 630 // NOTE: screen off reasons are in order of significance, with more 631 // important ones lower than less important ones. 632 633 /** Screen turned off because of a device admin */ 634 public final int OFF_BECAUSE_OF_ADMIN = 1; 635 /** Screen turned off because of power button */ 636 public final int OFF_BECAUSE_OF_USER = 2; 637 /** Screen turned off because of timeout */ 638 public final int OFF_BECAUSE_OF_TIMEOUT = 3; 639 640 /** @hide */ 641 @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED}) 642 @Retention(RetentionPolicy.SOURCE) 643 public @interface UserRotationMode {} 644 645 /** When not otherwise specified by the activity's screenOrientation, rotation should be 646 * determined by the system (that is, using sensors). */ 647 public final int USER_ROTATION_FREE = 0; 648 /** When not otherwise specified by the activity's screenOrientation, rotation is set by 649 * the user. */ 650 public final int USER_ROTATION_LOCKED = 1; 651 652 /** 653 * Perform initialization of the policy. 654 * 655 * @param context The system context we are running in. 656 */ 657 public void init(Context context, IWindowManager windowManager, 658 WindowManagerFuncs windowManagerFuncs); 659 660 /** 661 * @return true if com.android.internal.R.bool#config_forceDefaultOrientation is true. 662 */ 663 public boolean isDefaultOrientationForced(); 664 665 /** 666 * Called by window manager once it has the initial, default native 667 * display dimensions. 668 */ 669 public void setInitialDisplaySize(Display display, int width, int height, int density); 670 671 /** 672 * Called by window manager to set the overscan region that should be used for the 673 * given display. 674 */ 675 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom); 676 677 /** 678 * Check permissions when adding a window. 679 * 680 * @param attrs The window's LayoutParams. 681 * @param outAppOp First element will be filled with the app op corresponding to 682 * this window, or OP_NONE. 683 * 684 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed; 685 * else an error code, usually 686 * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add. 687 */ 688 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp); 689 690 /** 691 * Check permissions when adding a window. 692 * 693 * @param attrs The window's LayoutParams. 694 * 695 * @return True if the window may only be shown to the current user, false if the window can 696 * be shown on all users' windows. 697 */ 698 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs); 699 700 /** 701 * Sanitize the layout parameters coming from a client. Allows the policy 702 * to do things like ensure that windows of a specific type can't take 703 * input focus. 704 * 705 * @param attrs The window layout parameters to be modified. These values 706 * are modified in-place. 707 */ 708 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs); 709 710 /** 711 * After the window manager has computed the current configuration based 712 * on its knowledge of the display and input devices, it gives the policy 713 * a chance to adjust the information contained in it. If you want to 714 * leave it as-is, simply do nothing. 715 * 716 * <p>This method may be called by any thread in the window manager, but 717 * no internal locks in the window manager will be held. 718 * 719 * @param config The Configuration being computed, for you to change as 720 * desired. 721 * @param keyboardPresence Flags that indicate whether internal or external 722 * keyboards are present. 723 * @param navigationPresence Flags that indicate whether internal or external 724 * navigation devices are present. 725 */ 726 public void adjustConfigurationLw(Configuration config, int keyboardPresence, 727 int navigationPresence); 728 729 /** 730 * Returns the layer assignment for the window state. Allows you to control how different 731 * kinds of windows are ordered on-screen. 732 * 733 * @param win The window state 734 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 735 */ 736 default int getWindowLayerLw(WindowState win) { 737 return getWindowLayerFromTypeLw(win.getBaseType(), win.canAddInternalSystemWindow()); 738 } 739 740 /** 741 * Returns the layer assignment for the window type. Allows you to control how different 742 * kinds of windows are ordered on-screen. 743 * 744 * @param type The type of window being assigned. 745 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 746 */ 747 default int getWindowLayerFromTypeLw(int type) { 748 if (isSystemAlertWindowType(type)) { 749 throw new IllegalArgumentException("Use getWindowLayerFromTypeLw() or" 750 + " getWindowLayerLw() for alert window types"); 751 } 752 return getWindowLayerFromTypeLw(type, false /* canAddInternalSystemWindow */); 753 } 754 755 /** 756 * Returns the layer assignment for the window type. Allows you to control how different 757 * kinds of windows are ordered on-screen. 758 * 759 * @param type The type of window being assigned. 760 * @param canAddInternalSystemWindow If the owner window associated with the type we are 761 * evaluating can add internal system windows. I.e they have 762 * {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW}. If true, alert window 763 * types {@link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)} 764 * can be assigned layers greater than the layer for 765 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} Else, their 766 * layers would be lesser. 767 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 768 */ 769 default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow) { 770 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { 771 return APPLICATION_LAYER; 772 } 773 774 switch (type) { 775 case TYPE_WALLPAPER: 776 // wallpaper is at the bottom, though the window manager may move it. 777 return 1; 778 case TYPE_PRESENTATION: 779 case TYPE_PRIVATE_PRESENTATION: 780 return APPLICATION_LAYER; 781 case TYPE_DOCK_DIVIDER: 782 return APPLICATION_LAYER; 783 case TYPE_QS_DIALOG: 784 return APPLICATION_LAYER; 785 case TYPE_PHONE: 786 return 3; 787 case TYPE_SEARCH_BAR: 788 case TYPE_VOICE_INTERACTION_STARTING: 789 return 4; 790 case TYPE_VOICE_INTERACTION: 791 // voice interaction layer is almost immediately above apps. 792 return 5; 793 case TYPE_INPUT_CONSUMER: 794 return 6; 795 case TYPE_SYSTEM_DIALOG: 796 return 7; 797 case TYPE_TOAST: 798 // toasts and the plugged-in battery thing 799 return 8; 800 case TYPE_PRIORITY_PHONE: 801 // SIM errors and unlock. Not sure if this really should be in a high layer. 802 return 9; 803 case TYPE_SYSTEM_ALERT: 804 // like the ANR / app crashed dialogs 805 return canAddInternalSystemWindow ? 11 : 10; 806 case TYPE_APPLICATION_OVERLAY: 807 return 12; 808 case TYPE_DREAM: 809 // used for Dreams (screensavers with TYPE_DREAM windows) 810 return 13; 811 case TYPE_INPUT_METHOD: 812 // on-screen keyboards and other such input method user interfaces go here. 813 return 14; 814 case TYPE_INPUT_METHOD_DIALOG: 815 // on-screen keyboards and other such input method user interfaces go here. 816 return 15; 817 case TYPE_STATUS_BAR_SUB_PANEL: 818 return 17; 819 case TYPE_STATUS_BAR: 820 return 18; 821 case TYPE_STATUS_BAR_PANEL: 822 return 19; 823 case TYPE_KEYGUARD_DIALOG: 824 return 20; 825 case TYPE_VOLUME_OVERLAY: 826 // the on-screen volume indicator and controller shown when the user 827 // changes the device volume 828 return 21; 829 case TYPE_SYSTEM_OVERLAY: 830 // the on-screen volume indicator and controller shown when the user 831 // changes the device volume 832 return canAddInternalSystemWindow ? 22 : 11; 833 case TYPE_NAVIGATION_BAR: 834 // the navigation bar, if available, shows atop most things 835 return 23; 836 case TYPE_NAVIGATION_BAR_PANEL: 837 // some panels (e.g. search) need to show on top of the navigation bar 838 return 24; 839 case TYPE_SCREENSHOT: 840 // screenshot selection layer shouldn't go above system error, but it should cover 841 // navigation bars at the very least. 842 return 25; 843 case TYPE_SYSTEM_ERROR: 844 // system-level error dialogs 845 return canAddInternalSystemWindow ? 26 : 10; 846 case TYPE_MAGNIFICATION_OVERLAY: 847 // used to highlight the magnified portion of a display 848 return 27; 849 case TYPE_DISPLAY_OVERLAY: 850 // used to simulate secondary display devices 851 return 28; 852 case TYPE_DRAG: 853 // the drag layer: input for drag-and-drop is associated with this window, 854 // which sits above all other focusable windows 855 return 29; 856 case TYPE_ACCESSIBILITY_OVERLAY: 857 // overlay put by accessibility services to intercept user interaction 858 return 30; 859 case TYPE_SECURE_SYSTEM_OVERLAY: 860 return 31; 861 case TYPE_BOOT_PROGRESS: 862 return 32; 863 case TYPE_POINTER: 864 // the (mouse) pointer layer 865 return 33; 866 default: 867 Slog.e("WindowManager", "Unknown window type: " + type); 868 return APPLICATION_LAYER; 869 } 870 } 871 872 int APPLICATION_LAYER = 2; 873 int APPLICATION_MEDIA_SUBLAYER = -2; 874 int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; 875 int APPLICATION_PANEL_SUBLAYER = 1; 876 int APPLICATION_SUB_PANEL_SUBLAYER = 2; 877 int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; 878 879 /** 880 * Return how to Z-order sub-windows in relation to the window they are attached to. 881 * Return positive to have them ordered in front, negative for behind. 882 * 883 * @param type The sub-window type code. 884 * 885 * @return int Layer in relation to the attached window, where positive is 886 * above and negative is below. 887 */ 888 default int getSubWindowLayerFromTypeLw(int type) { 889 switch (type) { 890 case TYPE_APPLICATION_PANEL: 891 case TYPE_APPLICATION_ATTACHED_DIALOG: 892 return APPLICATION_PANEL_SUBLAYER; 893 case TYPE_APPLICATION_MEDIA: 894 return APPLICATION_MEDIA_SUBLAYER; 895 case TYPE_APPLICATION_MEDIA_OVERLAY: 896 return APPLICATION_MEDIA_OVERLAY_SUBLAYER; 897 case TYPE_APPLICATION_SUB_PANEL: 898 return APPLICATION_SUB_PANEL_SUBLAYER; 899 case TYPE_APPLICATION_ABOVE_SUB_PANEL: 900 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; 901 } 902 Slog.e("WindowManager", "Unknown sub-window type: " + type); 903 return 0; 904 } 905 906 /** 907 * Get the highest layer (actually one more than) that the wallpaper is 908 * allowed to be in. 909 */ 910 public int getMaxWallpaperLayer(); 911 912 /** 913 * Return the display width available after excluding any screen 914 * decorations that could never be removed in Honeycomb. That is, system bar or 915 * button bar. 916 */ 917 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, 918 int uiMode, int displayId); 919 920 /** 921 * Return the display height available after excluding any screen 922 * decorations that could never be removed in Honeycomb. That is, system bar or 923 * button bar. 924 */ 925 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, 926 int uiMode, int displayId); 927 928 /** 929 * Return the available screen width that we should report for the 930 * configuration. This must be no larger than 931 * {@link #getNonDecorDisplayWidth(int, int, int)}; it may be smaller than 932 * that to account for more transient decoration like a status bar. 933 */ 934 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, 935 int uiMode, int displayId); 936 937 /** 938 * Return the available screen height that we should report for the 939 * configuration. This must be no larger than 940 * {@link #getNonDecorDisplayHeight(int, int, int)}; it may be smaller than 941 * that to account for more transient decoration like a status bar. 942 */ 943 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, 944 int uiMode, int displayId); 945 946 /** 947 * Return whether the given window can become the Keyguard window. Typically returns true for 948 * the StatusBar. 949 */ 950 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs); 951 952 /** 953 * @return whether {@param win} can be hidden by Keyguard 954 */ 955 public boolean canBeHiddenByKeyguardLw(WindowState win); 956 957 /** 958 * Called when the system would like to show a UI to indicate that an 959 * application is starting. You can use this to add a 960 * APPLICATION_STARTING_TYPE window with the given appToken to the window 961 * manager (using the normal window manager APIs) that will be shown until 962 * the application displays its own window. This is called without the 963 * window manager locked so that you can call back into it. 964 * 965 * @param appToken Token of the application being started. 966 * @param packageName The name of the application package being started. 967 * @param theme Resource defining the application's overall visual theme. 968 * @param nonLocalizedLabel The default title label of the application if 969 * no data is found in the resource. 970 * @param labelRes The resource ID the application would like to use as its name. 971 * @param icon The resource ID the application would like to use as its icon. 972 * @param windowFlags Window layout flags. 973 * @param overrideConfig override configuration to consider when generating 974 * context to for resources. 975 * @param displayId Id of the display to show the splash screen at. 976 * 977 * @return The starting surface. 978 * 979 */ 980 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme, 981 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, 982 int logo, int windowFlags, Configuration overrideConfig, int displayId); 983 984 /** 985 * Prepare for a window being added to the window manager. You can throw an 986 * exception here to prevent the window being added, or do whatever setup 987 * you need to keep track of the window. 988 * 989 * @param win The window being added. 990 * @param attrs The window's LayoutParams. 991 * 992 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed, else an 993 * error code to abort the add. 994 */ 995 public int prepareAddWindowLw(WindowState win, 996 WindowManager.LayoutParams attrs); 997 998 /** 999 * Called when a window is being removed from a window manager. Must not 1000 * throw an exception -- clean up as much as possible. 1001 * 1002 * @param win The window being removed. 1003 */ 1004 public void removeWindowLw(WindowState win); 1005 1006 /** 1007 * Control the animation to run when a window's state changes. Return a 1008 * non-0 number to force the animation to a specific resource ID, or 0 1009 * to use the default animation. 1010 * 1011 * @param win The window that is changing. 1012 * @param transit What is happening to the window: {@link #TRANSIT_ENTER}, 1013 * {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or 1014 * {@link #TRANSIT_HIDE}. 1015 * 1016 * @return Resource ID of the actual animation to use, or 0 for none. 1017 */ 1018 public int selectAnimationLw(WindowState win, int transit); 1019 1020 /** 1021 * Determine the animation to run for a rotation transition based on the 1022 * top fullscreen windows {@link WindowManager.LayoutParams#rotationAnimation} 1023 * and whether it is currently fullscreen and frontmost. 1024 * 1025 * @param anim The exiting animation resource id is stored in anim[0], the 1026 * entering animation resource id is stored in anim[1]. 1027 */ 1028 public void selectRotationAnimationLw(int anim[]); 1029 1030 /** 1031 * Validate whether the current top fullscreen has specified the same 1032 * {@link WindowManager.LayoutParams#rotationAnimation} value as that 1033 * being passed in from the previous top fullscreen window. 1034 * 1035 * @param exitAnimId exiting resource id from the previous window. 1036 * @param enterAnimId entering resource id from the previous window. 1037 * @param forceDefault For rotation animations only, if true ignore the 1038 * animation values and just return false. 1039 * @return true if the previous values are still valid, false if they 1040 * should be replaced with the default. 1041 */ 1042 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, 1043 boolean forceDefault); 1044 1045 /** 1046 * Create and return an animation to re-display a window that was force hidden by Keyguard. 1047 */ 1048 public Animation createHiddenByKeyguardExit(boolean onWallpaper, 1049 boolean goingToNotificationShade); 1050 1051 /** 1052 * Create and return an animation to let the wallpaper disappear after being shown behind 1053 * Keyguard. 1054 */ 1055 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade); 1056 1057 /** 1058 * Called from the input reader thread before a key is enqueued. 1059 * 1060 * <p>There are some actions that need to be handled here because they 1061 * affect the power state of the device, for example, the power keys. 1062 * Generally, it's best to keep as little as possible in the queue thread 1063 * because it's the most fragile. 1064 * @param event The key event. 1065 * @param policyFlags The policy flags associated with the key. 1066 * 1067 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 1068 */ 1069 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags); 1070 1071 /** 1072 * Called from the input reader thread before a motion is enqueued when the device is in a 1073 * non-interactive state. 1074 * 1075 * <p>There are some actions that need to be handled here because they 1076 * affect the power state of the device, for example, waking on motions. 1077 * Generally, it's best to keep as little as possible in the queue thread 1078 * because it's the most fragile. 1079 * @param policyFlags The policy flags associated with the motion. 1080 * 1081 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 1082 */ 1083 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags); 1084 1085 /** 1086 * Called from the input dispatcher thread before a key is dispatched to a window. 1087 * 1088 * <p>Allows you to define 1089 * behavior for keys that can not be overridden by applications. 1090 * This method is called from the input thread, with no locks held. 1091 * 1092 * @param win The window that currently has focus. This is where the key 1093 * event will normally go. 1094 * @param event The key event. 1095 * @param policyFlags The policy flags associated with the key. 1096 * @return 0 if the key should be dispatched immediately, -1 if the key should 1097 * not be dispatched ever, or a positive value indicating the number of 1098 * milliseconds by which the key dispatch should be delayed before trying 1099 * again. 1100 */ 1101 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags); 1102 1103 /** 1104 * Called from the input dispatcher thread when an application did not handle 1105 * a key that was dispatched to it. 1106 * 1107 * <p>Allows you to define default global behavior for keys that were not handled 1108 * by applications. This method is called from the input thread, with no locks held. 1109 * 1110 * @param win The window that currently has focus. This is where the key 1111 * event will normally go. 1112 * @param event The key event. 1113 * @param policyFlags The policy flags associated with the key. 1114 * @return Returns an alternate key event to redispatch as a fallback, or null to give up. 1115 * The caller is responsible for recycling the key event. 1116 */ 1117 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags); 1118 1119 /** 1120 * Called when layout of the windows is about to start. 1121 * 1122 * @param isDefaultDisplay true if window is on {@link Display#DEFAULT_DISPLAY}. 1123 * @param displayWidth The current full width of the screen. 1124 * @param displayHeight The current full height of the screen. 1125 * @param displayRotation The current rotation being applied to the base window. 1126 * @param uiMode The current uiMode in configuration. 1127 */ 1128 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, 1129 int displayRotation, int uiMode); 1130 1131 /** 1132 * Returns the bottom-most layer of the system decor, above which no policy decor should 1133 * be applied. 1134 */ 1135 public int getSystemDecorLayerLw(); 1136 1137 /** 1138 * Return the rectangle of the screen that is available for applications to run in. 1139 * This will be called immediately after {@link #beginLayoutLw}. 1140 * 1141 * @param r The rectangle to be filled with the boundaries available to applications. 1142 */ 1143 public void getContentRectLw(Rect r); 1144 1145 /** 1146 * Called for each window attached to the window manager as layout is 1147 * proceeding. The implementation of this function must take care of 1148 * setting the window's frame, either here or in finishLayout(). 1149 * 1150 * @param win The window being positioned. 1151 * @param attached For sub-windows, the window it is attached to; this 1152 * window will already have had layoutWindow() called on it 1153 * so you can use its Rect. Otherwise null. 1154 */ 1155 public void layoutWindowLw(WindowState win, WindowState attached); 1156 1157 1158 /** 1159 * Return the insets for the areas covered by system windows. These values 1160 * are computed on the most recent layout, so they are not guaranteed to 1161 * be correct. 1162 * 1163 * @param attrs The LayoutParams of the window. 1164 * @param taskBounds The bounds of the task this window is on or {@code null} if no task is 1165 * associated with the window. 1166 * @param displayRotation Rotation of the display. 1167 * @param displayWidth The width of the display. 1168 * @param displayHeight The height of the display. 1169 * @param outContentInsets The areas covered by system windows, expressed as positive insets. 1170 * @param outStableInsets The areas covered by stable system windows irrespective of their 1171 * current visibility. Expressed as positive insets. 1172 * @param outOutsets The areas that are not real display, but we would like to treat as such. 1173 * @return Whether to always consume the navigation bar. 1174 * See {@link #isNavBarForcedShownLw(WindowState)}. 1175 */ 1176 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, 1177 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, 1178 Rect outStableInsets, Rect outOutsets); 1179 1180 /** 1181 * Called when layout of the windows is finished. After this function has 1182 * returned, all windows given to layoutWindow() <em>must</em> have had a 1183 * frame assigned. 1184 */ 1185 public void finishLayoutLw(); 1186 1187 /** Layout state may have changed (so another layout will be performed) */ 1188 static final int FINISH_LAYOUT_REDO_LAYOUT = 0x0001; 1189 /** Configuration state may have changed */ 1190 static final int FINISH_LAYOUT_REDO_CONFIG = 0x0002; 1191 /** Wallpaper may need to move */ 1192 static final int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004; 1193 /** Need to recompute animations */ 1194 static final int FINISH_LAYOUT_REDO_ANIM = 0x0008; 1195 1196 /** 1197 * Called following layout of all windows before each window has policy applied. 1198 * 1199 * @param displayWidth The current full width of the screen. 1200 * @param displayHeight The current full height of the screen. 1201 */ 1202 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight); 1203 1204 /** 1205 * Called following layout of all window to apply policy to each window. 1206 * 1207 * @param win The window being positioned. 1208 * @param attrs The LayoutParams of the window. 1209 * @param attached For sub-windows, the window it is attached to. Otherwise null. 1210 */ 1211 public void applyPostLayoutPolicyLw(WindowState win, 1212 WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget); 1213 1214 /** 1215 * Called following layout of all windows and after policy has been applied 1216 * to each window. If in this function you do 1217 * something that may have modified the animation state of another window, 1218 * be sure to return non-zero in order to perform another pass through layout. 1219 * 1220 * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT}, 1221 * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER}, 1222 * or {@link #FINISH_LAYOUT_REDO_ANIM}. 1223 */ 1224 public int finishPostLayoutPolicyLw(); 1225 1226 /** 1227 * Return true if it is okay to perform animations for an app transition 1228 * that is about to occur. You may return false for this if, for example, 1229 * the lock screen is currently displayed so the switch should happen 1230 * immediately. 1231 */ 1232 public boolean allowAppAnimationsLw(); 1233 1234 1235 /** 1236 * A new window has been focused. 1237 */ 1238 public int focusChangedLw(WindowState lastFocus, WindowState newFocus); 1239 1240 /** 1241 * Called when the device has started waking up. 1242 */ 1243 public void startedWakingUp(); 1244 1245 /** 1246 * Called when the device has finished waking up. 1247 */ 1248 public void finishedWakingUp(); 1249 1250 /** 1251 * Called when the device has started going to sleep. 1252 * 1253 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN}, 1254 * or {@link #OFF_BECAUSE_OF_TIMEOUT}. 1255 */ 1256 public void startedGoingToSleep(int why); 1257 1258 /** 1259 * Called when the device has finished going to sleep. 1260 * 1261 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN}, 1262 * or {@link #OFF_BECAUSE_OF_TIMEOUT}. 1263 */ 1264 public void finishedGoingToSleep(int why); 1265 1266 /** 1267 * Called when the device is about to turn on the screen to show content. 1268 * When waking up, this method will be called once after the call to wakingUp(). 1269 * When dozing, the method will be called sometime after the call to goingToSleep() and 1270 * may be called repeatedly in the case where the screen is pulsing on and off. 1271 * 1272 * Must call back on the listener to tell it when the higher-level system 1273 * is ready for the screen to go on (i.e. the lock screen is shown). 1274 */ 1275 public void screenTurningOn(ScreenOnListener screenOnListener); 1276 1277 /** 1278 * Called when the device has actually turned on the screen, i.e. the display power state has 1279 * been set to ON and the screen is unblocked. 1280 */ 1281 public void screenTurnedOn(); 1282 1283 /** 1284 * Called when the display would like to be turned off. This gives policy a chance to do some 1285 * things before the display power state is actually changed to off. 1286 * 1287 * @param screenOffListener Must be called to tell that the display power state can actually be 1288 * changed now after policy has done its work. 1289 */ 1290 public void screenTurningOff(ScreenOffListener screenOffListener); 1291 1292 /** 1293 * Called when the device has turned the screen off. 1294 */ 1295 public void screenTurnedOff(); 1296 1297 public interface ScreenOnListener { 1298 void onScreenOn(); 1299 } 1300 1301 /** 1302 * See {@link #screenTurnedOff} 1303 */ 1304 public interface ScreenOffListener { 1305 void onScreenOff(); 1306 } 1307 1308 /** 1309 * Return whether the default display is on and not blocked by a black surface. 1310 */ 1311 public boolean isScreenOn(); 1312 1313 /** 1314 * Tell the policy that the lid switch has changed state. 1315 * @param whenNanos The time when the change occurred in uptime nanoseconds. 1316 * @param lidOpen True if the lid is now open. 1317 */ 1318 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); 1319 1320 /** 1321 * Tell the policy that the camera lens has been covered or uncovered. 1322 * @param whenNanos The time when the change occurred in uptime nanoseconds. 1323 * @param lensCovered True if the lens is covered. 1324 */ 1325 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered); 1326 1327 /** 1328 * Tell the policy if anyone is requesting that keyguard not come on. 1329 * 1330 * @param enabled Whether keyguard can be on or not. does not actually 1331 * turn it on, unless it was previously disabled with this function. 1332 * 1333 * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard() 1334 * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard() 1335 */ 1336 @SuppressWarnings("javadoc") 1337 public void enableKeyguard(boolean enabled); 1338 1339 /** 1340 * Callback used by {@link WindowManagerPolicy#exitKeyguardSecurely} 1341 */ 1342 interface OnKeyguardExitResult { 1343 void onKeyguardExitResult(boolean success); 1344 } 1345 1346 /** 1347 * Tell the policy if anyone is requesting the keyguard to exit securely 1348 * (this would be called after the keyguard was disabled) 1349 * @param callback Callback to send the result back. 1350 * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult) 1351 */ 1352 @SuppressWarnings("javadoc") 1353 void exitKeyguardSecurely(OnKeyguardExitResult callback); 1354 1355 /** 1356 * isKeyguardLocked 1357 * 1358 * Return whether the keyguard is currently locked. 1359 * 1360 * @return true if in keyguard is locked. 1361 */ 1362 public boolean isKeyguardLocked(); 1363 1364 /** 1365 * isKeyguardSecure 1366 * 1367 * Return whether the keyguard requires a password to unlock. 1368 * @param userId 1369 * 1370 * @return true if in keyguard is secure. 1371 */ 1372 public boolean isKeyguardSecure(int userId); 1373 1374 /** 1375 * Return whether the keyguard is currently occluded. 1376 * 1377 * @return true if in keyguard is occluded, false otherwise 1378 */ 1379 public boolean isKeyguardOccluded(); 1380 1381 /** 1382 * @return true if in keyguard is on and not occluded. 1383 */ 1384 public boolean isKeyguardShowingAndNotOccluded(); 1385 1386 /** 1387 * @return whether Keyguard is in trusted state and can be dismissed without credentials 1388 */ 1389 public boolean isKeyguardTrustedLw(); 1390 1391 /** 1392 * inKeyguardRestrictedKeyInputMode 1393 * 1394 * if keyguard screen is showing or in restricted key input mode (i.e. in 1395 * keyguard password emergency screen). When in such mode, certain keys, 1396 * such as the Home key and the right soft keys, don't work. 1397 * 1398 * @return true if in keyguard restricted input mode. 1399 */ 1400 public boolean inKeyguardRestrictedKeyInputMode(); 1401 1402 /** 1403 * Ask the policy to dismiss the keyguard, if it is currently shown. 1404 * 1405 * @param callback Callback to be informed about the result. 1406 */ 1407 public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback); 1408 1409 /** 1410 * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method 1411 * returns true as soon as we know that Keyguard is disabled. 1412 * 1413 * @return true if the keyguard has drawn. 1414 */ 1415 public boolean isKeyguardDrawnLw(); 1416 1417 public boolean isShowingDreamLw(); 1418 1419 /** 1420 * Given an orientation constant, returns the appropriate surface rotation, 1421 * taking into account sensors, docking mode, rotation lock, and other factors. 1422 * 1423 * @param orientation An orientation constant, such as 1424 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}. 1425 * @param lastRotation The most recently used rotation. 1426 * @return The surface rotation to use. 1427 */ 1428 public int rotationForOrientationLw(@ActivityInfo.ScreenOrientation int orientation, 1429 int lastRotation); 1430 1431 /** 1432 * Given an orientation constant and a rotation, returns true if the rotation 1433 * has compatible metrics to the requested orientation. For example, if 1434 * the application requested landscape and got seascape, then the rotation 1435 * has compatible metrics; if the application requested portrait and got landscape, 1436 * then the rotation has incompatible metrics; if the application did not specify 1437 * a preference, then anything goes. 1438 * 1439 * @param orientation An orientation constant, such as 1440 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}. 1441 * @param rotation The rotation to check. 1442 * @return True if the rotation is compatible with the requested orientation. 1443 */ 1444 public boolean rotationHasCompatibleMetricsLw(@ActivityInfo.ScreenOrientation int orientation, 1445 int rotation); 1446 1447 /** 1448 * Called by the window manager when the rotation changes. 1449 * 1450 * @param rotation The new rotation. 1451 */ 1452 public void setRotationLw(int rotation); 1453 1454 /** 1455 * Called when the system is mostly done booting to set whether 1456 * the system should go into safe mode. 1457 */ 1458 public void setSafeMode(boolean safeMode); 1459 1460 /** 1461 * Called when the system is mostly done booting. 1462 */ 1463 public void systemReady(); 1464 1465 /** 1466 * Called when the system is done booting to the point where the 1467 * user can start interacting with it. 1468 */ 1469 public void systemBooted(); 1470 1471 /** 1472 * Show boot time message to the user. 1473 */ 1474 public void showBootMessage(final CharSequence msg, final boolean always); 1475 1476 /** 1477 * Hide the UI for showing boot messages, never to be displayed again. 1478 */ 1479 public void hideBootMessages(); 1480 1481 /** 1482 * Called when userActivity is signalled in the power manager. 1483 * This is safe to call from any thread, with any window manager locks held or not. 1484 */ 1485 public void userActivity(); 1486 1487 /** 1488 * Called when we have finished booting and can now display the home 1489 * screen to the user. This will happen after systemReady(), and at 1490 * this point the display is active. 1491 */ 1492 public void enableScreenAfterBoot(); 1493 1494 public void setCurrentOrientationLw(@ActivityInfo.ScreenOrientation int newOrientation); 1495 1496 /** 1497 * Call from application to perform haptic feedback on its window. 1498 */ 1499 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always); 1500 1501 /** 1502 * Called when we have started keeping the screen on because a window 1503 * requesting this has become visible. 1504 */ 1505 public void keepScreenOnStartedLw(); 1506 1507 /** 1508 * Called when we have stopped keeping the screen on because the last window 1509 * requesting this is no longer visible. 1510 */ 1511 public void keepScreenOnStoppedLw(); 1512 1513 /** 1514 * Gets the current user rotation mode. 1515 * 1516 * @return The rotation mode. 1517 * 1518 * @see WindowManagerPolicy#USER_ROTATION_LOCKED 1519 * @see WindowManagerPolicy#USER_ROTATION_FREE 1520 */ 1521 @UserRotationMode 1522 public int getUserRotationMode(); 1523 1524 /** 1525 * Inform the policy that the user has chosen a preferred orientation ("rotation lock"). 1526 * 1527 * @param mode One of {@link WindowManagerPolicy#USER_ROTATION_LOCKED} or 1528 * {@link WindowManagerPolicy#USER_ROTATION_FREE}. 1529 * @param rotation One of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90}, 1530 * {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270}. 1531 */ 1532 public void setUserRotationMode(@UserRotationMode int mode, @Surface.Rotation int rotation); 1533 1534 /** 1535 * Called when a new system UI visibility is being reported, allowing 1536 * the policy to adjust what is actually reported. 1537 * @param visibility The raw visibility reported by the status bar. 1538 * @return The new desired visibility. 1539 */ 1540 public int adjustSystemUiVisibilityLw(int visibility); 1541 1542 /** 1543 * Called by System UI to notify of changes to the visibility of Recents. 1544 */ 1545 public void setRecentsVisibilityLw(boolean visible); 1546 1547 /** 1548 * Called by System UI to notify of changes to the visibility of PIP. 1549 */ 1550 void setPipVisibilityLw(boolean visible); 1551 1552 /** 1553 * Specifies whether there is an on-screen navigation bar separate from the status bar. 1554 */ 1555 public boolean hasNavigationBar(); 1556 1557 /** 1558 * Lock the device now. 1559 */ 1560 public void lockNow(Bundle options); 1561 1562 /** 1563 * Set the last used input method window state. This state is used to make IME transition 1564 * smooth. 1565 * @hide 1566 */ 1567 public void setLastInputMethodWindowLw(WindowState ime, WindowState target); 1568 1569 /** 1570 * An internal callback (from InputMethodManagerService) to notify a state change regarding 1571 * whether the back key should dismiss the software keyboard (IME) or not. 1572 * 1573 * @param newValue {@code true} if the software keyboard is shown and the back key is expected 1574 * to dismiss the software keyboard. 1575 * @hide 1576 */ 1577 default void setDismissImeOnBackKeyPressed(boolean newValue) { 1578 // Default implementation does nothing. 1579 } 1580 1581 /** 1582 * Show the recents task list app. 1583 * @hide 1584 */ 1585 public void showRecentApps(boolean fromHome); 1586 1587 /** 1588 * Show the global actions dialog. 1589 * @hide 1590 */ 1591 public void showGlobalActions(); 1592 1593 /** 1594 * @return The current height of the input method window. 1595 */ 1596 public int getInputMethodWindowVisibleHeightLw(); 1597 1598 /** 1599 * Called when the current user changes. Guaranteed to be called before the broadcast 1600 * of the new user id is made to all listeners. 1601 * 1602 * @param newUserId The id of the incoming user. 1603 */ 1604 public void setCurrentUserLw(int newUserId); 1605 1606 /** 1607 * For a given user-switch operation, this will be called once with switching=true before the 1608 * user-switch and once with switching=false afterwards (or if the user-switch was cancelled). 1609 * This gives the policy a chance to alter its behavior for the duration of a user-switch. 1610 * 1611 * @param switching true if a user-switch is in progress 1612 */ 1613 void setSwitchingUser(boolean switching); 1614 1615 /** 1616 * Print the WindowManagerPolicy's state into the given stream. 1617 * 1618 * @param prefix Text to print at the front of each line. 1619 * @param writer The PrintWriter to which you should dump your state. This will be 1620 * closed for you after you return. 1621 * @param args additional arguments to the dump request. 1622 */ 1623 public void dump(String prefix, PrintWriter writer, String[] args); 1624 1625 /** 1626 * Returns whether a given window type can be magnified. 1627 * 1628 * @param windowType The window type. 1629 * @return True if the window can be magnified. 1630 */ 1631 public boolean canMagnifyWindow(int windowType); 1632 1633 /** 1634 * Returns whether a given window type is considered a top level one. 1635 * A top level window does not have a container, i.e. attached window, 1636 * or if it has a container it is laid out as a top-level window, not 1637 * as a child of its container. 1638 * 1639 * @param windowType The window type. 1640 * @return True if the window is a top level one. 1641 */ 1642 public boolean isTopLevelWindow(int windowType); 1643 1644 /** 1645 * Notifies the keyguard to start fading out. 1646 * 1647 * @param startTime the start time of the animation in uptime milliseconds 1648 * @param fadeoutDuration the duration of the exit animation, in milliseconds 1649 */ 1650 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration); 1651 1652 /** 1653 * Calculates the stable insets without running a layout. 1654 * 1655 * @param displayRotation the current display rotation 1656 * @param displayWidth the current display width 1657 * @param displayHeight the current display height 1658 * @param outInsets the insets to return 1659 */ 1660 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, 1661 Rect outInsets); 1662 1663 1664 /** 1665 * @return true if the navigation bar is forced to stay visible 1666 */ 1667 public boolean isNavBarForcedShownLw(WindowState win); 1668 1669 /** 1670 * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system 1671 * bar or button bar. See {@link #getNonDecorDisplayWidth}. 1672 * 1673 * @param displayRotation the current display rotation 1674 * @param displayWidth the current display width 1675 * @param displayHeight the current display height 1676 * @param outInsets the insets to return 1677 */ 1678 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, 1679 Rect outInsets); 1680 1681 /** 1682 * @return True if a specified {@param dockSide} is allowed on the current device, or false 1683 * otherwise. It is guaranteed that at least one dock side for a particular orientation 1684 * is allowed, so for example, if DOCKED_RIGHT is not allowed, DOCKED_LEFT is allowed. 1685 */ 1686 public boolean isDockSideAllowed(int dockSide); 1687 1688 /** 1689 * Called when the configuration has changed, and it's safe to load new values from resources. 1690 */ 1691 public void onConfigurationChanged(); 1692 1693 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation); 1694 1695 /** 1696 * Called when System UI has been started. 1697 */ 1698 void onSystemUiStarted(); 1699 1700 /** 1701 * Checks whether the policy is ready for dismissing the boot animation and completing the boot. 1702 * 1703 * @return true if ready; false otherwise. 1704 */ 1705 boolean canDismissBootAnimation(); 1706 } 1707