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