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 */ registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)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 */ onKeyguardOccludedChangedLw(boolean occluded)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 */ getOwningUid()208 int getOwningUid(); 209 210 /** 211 * Return the package name of the app that owns this window. 212 */ getOwningPackage()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 */ computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overlayFrame, Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame, Rect outsetFrame)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 */ getFrameLw()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 */ getShownPositionLw()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 */ getDisplayFrameLw()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 */ getOverscanFrameLw()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 */ getContentFrameLw()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 */ getVisibleFrameLw()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 */ getGivenInsetsPendingLw()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 */ getGivenContentInsetsLw()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 */ getGivenVisibleInsetsLw()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 */ getAttrs()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 */ getNeedsMenuLw(WindowState bottom)345 public boolean getNeedsMenuLw(WindowState bottom); 346 347 /** 348 * Retrieve the current system UI visibility flags associated with 349 * this window. 350 */ getSystemUiVisibility()351 public int getSystemUiVisibility(); 352 353 /** 354 * Get the layer at which this window's surface will be Z-ordered. 355 */ getSurfaceLayer()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 */ getBaseType()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 */ getAppToken()371 public IApplicationToken getAppToken(); 372 373 /** 374 * Return true if this window is participating in voice interaction. 375 */ isVoiceInteraction()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 */ hasAppShownWindows()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 */ isVisibleLw()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 */ isDisplayedLw()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 */ isAnimatingLw()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 */ canAffectSystemUiFlags()415 boolean canAffectSystemUiFlags(); 416 417 /** 418 * Is this window considered to be gone for purposes of layout? 419 */ isGoneForLayoutLw()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 */ isDrawnLw()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 */ hasDrawnLw()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 */ hideLw(boolean doAnimation)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 */ showLw(boolean doAnimation)451 public boolean showLw(boolean doAnimation); 452 453 /** 454 * Check whether the process hosting this window is currently alive. 455 */ isAlive()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 */ isDefaultDisplay()462 public boolean isDefaultDisplay(); 463 464 /** 465 * Check whether the window is currently dimming. 466 */ isDimming()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 */ getStackId()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 */ isInMultiWindowMode()479 public boolean isInMultiWindowMode(); 480 getRotationAnimationHint()481 public int getRotationAnimationHint(); 482 isInputMethodWindow()483 public boolean isInputMethodWindow(); 484 getDisplayId()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 */ canAddInternalSystemWindow()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 */ canAcquireSleepToken()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 */ dismiss()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 */ remove()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 */ reevaluateStatusBarVisibility()543 public void reevaluateStatusBarVisibility(); 544 545 /** 546 * Add a input consumer which will consume all input events going to any window below it. 547 */ createInputConsumer(Looper looper, String name, InputEventReceiver.Factory inputEventReceiverFactory)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 */ getLidState()554 public int getLidState(); 555 556 /** 557 * Lock the device now. 558 */ lockDeviceNow()559 public void lockDeviceNow(); 560 561 /** 562 * Returns a code that descripbes whether the camera lens is covered or not. 563 */ getCameraLensCoverState()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 */ switchInputMethod(boolean forwardDirection)571 public void switchInputMethod(boolean forwardDirection); 572 shutdown(boolean confirm)573 public void shutdown(boolean confirm); reboot(boolean confirm)574 public void reboot(boolean confirm); rebootSafeMode(boolean confirm)575 public void rebootSafeMode(boolean confirm); 576 577 /** 578 * Return the window manager lock needed to correctly call "Lw" methods. 579 */ getWindowManagerLock()580 public Object getWindowManagerLock(); 581 582 /** Register a system listener for touch events */ registerPointerEventListener(PointerEventListener listener)583 void registerPointerEventListener(PointerEventListener listener); 584 585 /** Unregister a system listener for touch events */ unregisterPointerEventListener(PointerEventListener listener)586 void unregisterPointerEventListener(PointerEventListener listener); 587 588 /** 589 * @return The content insets of the docked divider window. 590 */ getDockedDividerInsetsLw()591 int getDockedDividerInsetsLw(); 592 593 /** 594 * Retrieves the {@param outBounds} from the stack with id {@param stackId}. 595 */ getStackBounds(int stackId, Rect outBounds)596 void getStackBounds(int stackId, Rect outBounds); 597 598 /** 599 * Notifies window manager that {@link #isShowingDreamLw} has changed. 600 */ notifyShowingDreamChanged()601 void notifyShowingDreamChanged(); 602 603 /** 604 * @return The currently active input method window. 605 */ getInputMethodWindowLw()606 WindowState getInputMethodWindowLw(); 607 608 /** 609 * Notifies window manager that {@link #isKeyguardTrustedLw} has changed. 610 */ notifyKeyguardTrustedChanged()611 void notifyKeyguardTrustedChanged(); 612 613 /** 614 * The keyguard showing state has changed 615 */ onKeyguardShowingAndNotOccludedChanged()616 void onKeyguardShowingAndNotOccludedChanged(); 617 618 /** 619 * Notifies the window manager that screen is being turned off. 620 * 621 * @param listener callback to call when display can be turned off 622 */ screenTurningOff(ScreenOffListener listener)623 void screenTurningOff(ScreenOffListener listener); 624 } 625 626 public interface PointerEventListener { 627 /** 628 * 1. onPointerEvent will be called on the service.UiThread. 629 * 2. motionEvent will be recycled after onPointerEvent returns so if it is needed later a 630 * copy() must be made and the copy must be recycled. 631 **/ onPointerEvent(MotionEvent motionEvent)632 void onPointerEvent(MotionEvent motionEvent); 633 634 /** 635 * @see #onPointerEvent(MotionEvent) 636 **/ onPointerEvent(MotionEvent motionEvent, int displayId)637 default void onPointerEvent(MotionEvent motionEvent, int displayId) { 638 if (displayId == DEFAULT_DISPLAY) { 639 onPointerEvent(motionEvent); 640 } 641 } 642 } 643 644 /** Window has been added to the screen. */ 645 public static final int TRANSIT_ENTER = 1; 646 /** Window has been removed from the screen. */ 647 public static final int TRANSIT_EXIT = 2; 648 /** Window has been made visible. */ 649 public static final int TRANSIT_SHOW = 3; 650 /** Window has been made invisible. 651 * TODO: Consider removal as this is unused. */ 652 public static final int TRANSIT_HIDE = 4; 653 /** The "application starting" preview window is no longer needed, and will 654 * animate away to show the real window. */ 655 public static final int TRANSIT_PREVIEW_DONE = 5; 656 657 // NOTE: screen off reasons are in order of significance, with more 658 // important ones lower than less important ones. 659 660 /** Screen turned off because of a device admin */ 661 public final int OFF_BECAUSE_OF_ADMIN = 1; 662 /** Screen turned off because of power button */ 663 public final int OFF_BECAUSE_OF_USER = 2; 664 /** Screen turned off because of timeout */ 665 public final int OFF_BECAUSE_OF_TIMEOUT = 3; 666 667 /** @hide */ 668 @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED}) 669 @Retention(RetentionPolicy.SOURCE) 670 public @interface UserRotationMode {} 671 672 /** When not otherwise specified by the activity's screenOrientation, rotation should be 673 * determined by the system (that is, using sensors). */ 674 public final int USER_ROTATION_FREE = 0; 675 /** When not otherwise specified by the activity's screenOrientation, rotation is set by 676 * the user. */ 677 public final int USER_ROTATION_LOCKED = 1; 678 679 /** 680 * Perform initialization of the policy. 681 * 682 * @param context The system context we are running in. 683 */ init(Context context, IWindowManager windowManager, WindowManagerFuncs windowManagerFuncs)684 public void init(Context context, IWindowManager windowManager, 685 WindowManagerFuncs windowManagerFuncs); 686 687 /** 688 * @return true if com.android.internal.R.bool#config_forceDefaultOrientation is true. 689 */ isDefaultOrientationForced()690 public boolean isDefaultOrientationForced(); 691 692 /** 693 * Called by window manager once it has the initial, default native 694 * display dimensions. 695 */ setInitialDisplaySize(Display display, int width, int height, int density)696 public void setInitialDisplaySize(Display display, int width, int height, int density); 697 698 /** 699 * Called by window manager to set the overscan region that should be used for the 700 * given display. 701 */ setDisplayOverscan(Display display, int left, int top, int right, int bottom)702 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom); 703 704 /** 705 * Check permissions when adding a window. 706 * 707 * @param attrs The window's LayoutParams. 708 * @param outAppOp First element will be filled with the app op corresponding to 709 * this window, or OP_NONE. 710 * 711 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed; 712 * else an error code, usually 713 * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add. 714 */ checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp)715 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp); 716 717 /** 718 * Check permissions when adding a window. 719 * 720 * @param attrs The window's LayoutParams. 721 * 722 * @return True if the window may only be shown to the current user, false if the window can 723 * be shown on all users' windows. 724 */ checkShowToOwnerOnly(WindowManager.LayoutParams attrs)725 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs); 726 727 /** 728 * Sanitize the layout parameters coming from a client. Allows the policy 729 * to do things like ensure that windows of a specific type can't take 730 * input focus. 731 * 732 * @param attrs The window layout parameters to be modified. These values 733 * are modified in-place. 734 */ adjustWindowParamsLw(WindowManager.LayoutParams attrs)735 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs); 736 737 /** 738 * After the window manager has computed the current configuration based 739 * on its knowledge of the display and input devices, it gives the policy 740 * a chance to adjust the information contained in it. If you want to 741 * leave it as-is, simply do nothing. 742 * 743 * <p>This method may be called by any thread in the window manager, but 744 * no internal locks in the window manager will be held. 745 * 746 * @param config The Configuration being computed, for you to change as 747 * desired. 748 * @param keyboardPresence Flags that indicate whether internal or external 749 * keyboards are present. 750 * @param navigationPresence Flags that indicate whether internal or external 751 * navigation devices are present. 752 */ adjustConfigurationLw(Configuration config, int keyboardPresence, int navigationPresence)753 public void adjustConfigurationLw(Configuration config, int keyboardPresence, 754 int navigationPresence); 755 756 /** 757 * Returns the layer assignment for the window state. Allows you to control how different 758 * kinds of windows are ordered on-screen. 759 * 760 * @param win The window state 761 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 762 */ getWindowLayerLw(WindowState win)763 default int getWindowLayerLw(WindowState win) { 764 return getWindowLayerFromTypeLw(win.getBaseType(), win.canAddInternalSystemWindow()); 765 } 766 767 /** 768 * Returns the layer assignment for the window type. Allows you to control how different 769 * kinds of windows are ordered on-screen. 770 * 771 * @param type The type of window being assigned. 772 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 773 */ getWindowLayerFromTypeLw(int type)774 default int getWindowLayerFromTypeLw(int type) { 775 if (isSystemAlertWindowType(type)) { 776 throw new IllegalArgumentException("Use getWindowLayerFromTypeLw() or" 777 + " getWindowLayerLw() for alert window types"); 778 } 779 return getWindowLayerFromTypeLw(type, false /* canAddInternalSystemWindow */); 780 } 781 782 /** 783 * Returns the layer assignment for the window type. Allows you to control how different 784 * kinds of windows are ordered on-screen. 785 * 786 * @param type The type of window being assigned. 787 * @param canAddInternalSystemWindow If the owner window associated with the type we are 788 * evaluating can add internal system windows. I.e they have 789 * {@link permission#INTERNAL_SYSTEM_WINDOW}. If true, alert window 790 * types {@link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)} 791 * can be assigned layers greater than the layer for 792 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} Else, their 793 * layers would be lesser. 794 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 795 */ getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow)796 default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow) { 797 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { 798 return APPLICATION_LAYER; 799 } 800 801 switch (type) { 802 case TYPE_WALLPAPER: 803 // wallpaper is at the bottom, though the window manager may move it. 804 return 1; 805 case TYPE_PRESENTATION: 806 case TYPE_PRIVATE_PRESENTATION: 807 return APPLICATION_LAYER; 808 case TYPE_DOCK_DIVIDER: 809 return APPLICATION_LAYER; 810 case TYPE_QS_DIALOG: 811 return APPLICATION_LAYER; 812 case TYPE_PHONE: 813 return 3; 814 case TYPE_SEARCH_BAR: 815 case TYPE_VOICE_INTERACTION_STARTING: 816 return 4; 817 case TYPE_VOICE_INTERACTION: 818 // voice interaction layer is almost immediately above apps. 819 return 5; 820 case TYPE_INPUT_CONSUMER: 821 return 6; 822 case TYPE_SYSTEM_DIALOG: 823 return 7; 824 case TYPE_TOAST: 825 // toasts and the plugged-in battery thing 826 return 8; 827 case TYPE_PRIORITY_PHONE: 828 // SIM errors and unlock. Not sure if this really should be in a high layer. 829 return 9; 830 case TYPE_SYSTEM_ALERT: 831 // like the ANR / app crashed dialogs 832 return canAddInternalSystemWindow ? 11 : 10; 833 case TYPE_APPLICATION_OVERLAY: 834 return 12; 835 case TYPE_DREAM: 836 // used for Dreams (screensavers with TYPE_DREAM windows) 837 return 13; 838 case TYPE_INPUT_METHOD: 839 // on-screen keyboards and other such input method user interfaces go here. 840 return 14; 841 case TYPE_INPUT_METHOD_DIALOG: 842 // on-screen keyboards and other such input method user interfaces go here. 843 return 15; 844 case TYPE_STATUS_BAR_SUB_PANEL: 845 return 17; 846 case TYPE_STATUS_BAR: 847 return 18; 848 case TYPE_STATUS_BAR_PANEL: 849 return 19; 850 case TYPE_KEYGUARD_DIALOG: 851 return 20; 852 case TYPE_VOLUME_OVERLAY: 853 // the on-screen volume indicator and controller shown when the user 854 // changes the device volume 855 return 21; 856 case TYPE_SYSTEM_OVERLAY: 857 // the on-screen volume indicator and controller shown when the user 858 // changes the device volume 859 return canAddInternalSystemWindow ? 22 : 11; 860 case TYPE_NAVIGATION_BAR: 861 // the navigation bar, if available, shows atop most things 862 return 23; 863 case TYPE_NAVIGATION_BAR_PANEL: 864 // some panels (e.g. search) need to show on top of the navigation bar 865 return 24; 866 case TYPE_SCREENSHOT: 867 // screenshot selection layer shouldn't go above system error, but it should cover 868 // navigation bars at the very least. 869 return 25; 870 case TYPE_SYSTEM_ERROR: 871 // system-level error dialogs 872 return canAddInternalSystemWindow ? 26 : 10; 873 case TYPE_MAGNIFICATION_OVERLAY: 874 // used to highlight the magnified portion of a display 875 return 27; 876 case TYPE_DISPLAY_OVERLAY: 877 // used to simulate secondary display devices 878 return 28; 879 case TYPE_DRAG: 880 // the drag layer: input for drag-and-drop is associated with this window, 881 // which sits above all other focusable windows 882 return 29; 883 case TYPE_ACCESSIBILITY_OVERLAY: 884 // overlay put by accessibility services to intercept user interaction 885 return 30; 886 case TYPE_SECURE_SYSTEM_OVERLAY: 887 return 31; 888 case TYPE_BOOT_PROGRESS: 889 return 32; 890 case TYPE_POINTER: 891 // the (mouse) pointer layer 892 return 33; 893 default: 894 Slog.e("WindowManager", "Unknown window type: " + type); 895 return APPLICATION_LAYER; 896 } 897 } 898 899 int APPLICATION_LAYER = 2; 900 int APPLICATION_MEDIA_SUBLAYER = -2; 901 int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; 902 int APPLICATION_PANEL_SUBLAYER = 1; 903 int APPLICATION_SUB_PANEL_SUBLAYER = 2; 904 int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; 905 906 /** 907 * Return how to Z-order sub-windows in relation to the window they are attached to. 908 * Return positive to have them ordered in front, negative for behind. 909 * 910 * @param type The sub-window type code. 911 * 912 * @return int Layer in relation to the attached window, where positive is 913 * above and negative is below. 914 */ getSubWindowLayerFromTypeLw(int type)915 default int getSubWindowLayerFromTypeLw(int type) { 916 switch (type) { 917 case TYPE_APPLICATION_PANEL: 918 case TYPE_APPLICATION_ATTACHED_DIALOG: 919 return APPLICATION_PANEL_SUBLAYER; 920 case TYPE_APPLICATION_MEDIA: 921 return APPLICATION_MEDIA_SUBLAYER; 922 case TYPE_APPLICATION_MEDIA_OVERLAY: 923 return APPLICATION_MEDIA_OVERLAY_SUBLAYER; 924 case TYPE_APPLICATION_SUB_PANEL: 925 return APPLICATION_SUB_PANEL_SUBLAYER; 926 case TYPE_APPLICATION_ABOVE_SUB_PANEL: 927 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; 928 } 929 Slog.e("WindowManager", "Unknown sub-window type: " + type); 930 return 0; 931 } 932 933 /** 934 * Get the highest layer (actually one more than) that the wallpaper is 935 * allowed to be in. 936 */ getMaxWallpaperLayer()937 public int getMaxWallpaperLayer(); 938 939 /** 940 * Return the display width available after excluding any screen 941 * decorations that could never be removed in Honeycomb. That is, system bar or 942 * button bar. 943 */ getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, int displayId)944 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, 945 int uiMode, int displayId); 946 947 /** 948 * Return the display height available after excluding any screen 949 * decorations that could never be removed in Honeycomb. That is, system bar or 950 * button bar. 951 */ getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, int displayId)952 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, 953 int uiMode, int displayId); 954 955 /** 956 * Return the available screen width that we should report for the 957 * configuration. This must be no larger than 958 * {@link #getNonDecorDisplayWidth(int, int, int)}; it may be smaller than 959 * that to account for more transient decoration like a status bar. 960 */ getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, int displayId)961 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, 962 int uiMode, int displayId); 963 964 /** 965 * Return the available screen height that we should report for the 966 * configuration. This must be no larger than 967 * {@link #getNonDecorDisplayHeight(int, int, int)}; it may be smaller than 968 * that to account for more transient decoration like a status bar. 969 */ getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, int displayId)970 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, 971 int uiMode, int displayId); 972 973 /** 974 * Return whether the given window can become the Keyguard window. Typically returns true for 975 * the StatusBar. 976 */ isKeyguardHostWindow(WindowManager.LayoutParams attrs)977 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs); 978 979 /** 980 * @return whether {@param win} can be hidden by Keyguard 981 */ canBeHiddenByKeyguardLw(WindowState win)982 public boolean canBeHiddenByKeyguardLw(WindowState win); 983 984 /** 985 * Called when the system would like to show a UI to indicate that an 986 * application is starting. You can use this to add a 987 * APPLICATION_STARTING_TYPE window with the given appToken to the window 988 * manager (using the normal window manager APIs) that will be shown until 989 * the application displays its own window. This is called without the 990 * window manager locked so that you can call back into it. 991 * 992 * @param appToken Token of the application being started. 993 * @param packageName The name of the application package being started. 994 * @param theme Resource defining the application's overall visual theme. 995 * @param nonLocalizedLabel The default title label of the application if 996 * no data is found in the resource. 997 * @param labelRes The resource ID the application would like to use as its name. 998 * @param icon The resource ID the application would like to use as its icon. 999 * @param windowFlags Window layout flags. 1000 * @param overrideConfig override configuration to consider when generating 1001 * context to for resources. 1002 * @param displayId Id of the display to show the splash screen at. 1003 * 1004 * @return The starting surface. 1005 * 1006 */ addSplashScreen(IBinder appToken, String packageName, int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, Configuration overrideConfig, int displayId)1007 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme, 1008 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, 1009 int logo, int windowFlags, Configuration overrideConfig, int displayId); 1010 1011 /** 1012 * Prepare for a window being added to the window manager. You can throw an 1013 * exception here to prevent the window being added, or do whatever setup 1014 * you need to keep track of the window. 1015 * 1016 * @param win The window being added. 1017 * @param attrs The window's LayoutParams. 1018 * 1019 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed, else an 1020 * error code to abort the add. 1021 */ prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs)1022 public int prepareAddWindowLw(WindowState win, 1023 WindowManager.LayoutParams attrs); 1024 1025 /** 1026 * Called when a window is being removed from a window manager. Must not 1027 * throw an exception -- clean up as much as possible. 1028 * 1029 * @param win The window being removed. 1030 */ removeWindowLw(WindowState win)1031 public void removeWindowLw(WindowState win); 1032 1033 /** 1034 * Control the animation to run when a window's state changes. Return a 1035 * non-0 number to force the animation to a specific resource ID, or 0 1036 * to use the default animation. 1037 * 1038 * @param win The window that is changing. 1039 * @param transit What is happening to the window: {@link #TRANSIT_ENTER}, 1040 * {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or 1041 * {@link #TRANSIT_HIDE}. 1042 * 1043 * @return Resource ID of the actual animation to use, or 0 for none. 1044 */ selectAnimationLw(WindowState win, int transit)1045 public int selectAnimationLw(WindowState win, int transit); 1046 1047 /** 1048 * Determine the animation to run for a rotation transition based on the 1049 * top fullscreen windows {@link WindowManager.LayoutParams#rotationAnimation} 1050 * and whether it is currently fullscreen and frontmost. 1051 * 1052 * @param anim The exiting animation resource id is stored in anim[0], the 1053 * entering animation resource id is stored in anim[1]. 1054 */ selectRotationAnimationLw(int anim[])1055 public void selectRotationAnimationLw(int anim[]); 1056 1057 /** 1058 * Validate whether the current top fullscreen has specified the same 1059 * {@link WindowManager.LayoutParams#rotationAnimation} value as that 1060 * being passed in from the previous top fullscreen window. 1061 * 1062 * @param exitAnimId exiting resource id from the previous window. 1063 * @param enterAnimId entering resource id from the previous window. 1064 * @param forceDefault For rotation animations only, if true ignore the 1065 * animation values and just return false. 1066 * @return true if the previous values are still valid, false if they 1067 * should be replaced with the default. 1068 */ validateRotationAnimationLw(int exitAnimId, int enterAnimId, boolean forceDefault)1069 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, 1070 boolean forceDefault); 1071 1072 /** 1073 * Create and return an animation to re-display a window that was force hidden by Keyguard. 1074 */ createHiddenByKeyguardExit(boolean onWallpaper, boolean goingToNotificationShade)1075 public Animation createHiddenByKeyguardExit(boolean onWallpaper, 1076 boolean goingToNotificationShade); 1077 1078 /** 1079 * Create and return an animation to let the wallpaper disappear after being shown behind 1080 * Keyguard. 1081 */ createKeyguardWallpaperExit(boolean goingToNotificationShade)1082 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade); 1083 1084 /** 1085 * Called from the input reader thread before a key is enqueued. 1086 * 1087 * <p>There are some actions that need to be handled here because they 1088 * affect the power state of the device, for example, the power keys. 1089 * Generally, it's best to keep as little as possible in the queue thread 1090 * because it's the most fragile. 1091 * @param event The key event. 1092 * @param policyFlags The policy flags associated with the key. 1093 * 1094 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 1095 */ interceptKeyBeforeQueueing(KeyEvent event, int policyFlags)1096 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags); 1097 1098 /** 1099 * Called from the input reader thread before a motion is enqueued when the device is in a 1100 * non-interactive state. 1101 * 1102 * <p>There are some actions that need to be handled here because they 1103 * affect the power state of the device, for example, waking on motions. 1104 * Generally, it's best to keep as little as possible in the queue thread 1105 * because it's the most fragile. 1106 * @param policyFlags The policy flags associated with the motion. 1107 * 1108 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 1109 */ interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags)1110 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags); 1111 1112 /** 1113 * Called from the input dispatcher thread before a key is dispatched to a window. 1114 * 1115 * <p>Allows you to define 1116 * behavior for keys that can not be overridden by applications. 1117 * This method is called from the input thread, with no locks held. 1118 * 1119 * @param win The window that currently has focus. This is where the key 1120 * event will normally go. 1121 * @param event The key event. 1122 * @param policyFlags The policy flags associated with the key. 1123 * @return 0 if the key should be dispatched immediately, -1 if the key should 1124 * not be dispatched ever, or a positive value indicating the number of 1125 * milliseconds by which the key dispatch should be delayed before trying 1126 * again. 1127 */ interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags)1128 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags); 1129 1130 /** 1131 * Called from the input dispatcher thread when an application did not handle 1132 * a key that was dispatched to it. 1133 * 1134 * <p>Allows you to define default global behavior for keys that were not handled 1135 * by applications. This method is called from the input thread, with no locks held. 1136 * 1137 * @param win The window that currently has focus. This is where the key 1138 * event will normally go. 1139 * @param event The key event. 1140 * @param policyFlags The policy flags associated with the key. 1141 * @return Returns an alternate key event to redispatch as a fallback, or null to give up. 1142 * The caller is responsible for recycling the key event. 1143 */ dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags)1144 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags); 1145 1146 /** 1147 * Called when layout of the windows is about to start. 1148 * 1149 * @param isDefaultDisplay true if window is on {@link Display#DEFAULT_DISPLAY}. 1150 * @param displayWidth The current full width of the screen. 1151 * @param displayHeight The current full height of the screen. 1152 * @param displayRotation The current rotation being applied to the base window. 1153 * @param uiMode The current uiMode in configuration. 1154 */ beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, int displayRotation, int uiMode)1155 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, 1156 int displayRotation, int uiMode); 1157 1158 /** 1159 * Returns the bottom-most layer of the system decor, above which no policy decor should 1160 * be applied. 1161 */ getSystemDecorLayerLw()1162 public int getSystemDecorLayerLw(); 1163 1164 /** 1165 * Return the rectangle of the screen that is available for applications to run in. 1166 * This will be called immediately after {@link #beginLayoutLw}. 1167 * 1168 * @param r The rectangle to be filled with the boundaries available to applications. 1169 */ getContentRectLw(Rect r)1170 public void getContentRectLw(Rect r); 1171 1172 /** 1173 * Called for each window attached to the window manager as layout is 1174 * proceeding. The implementation of this function must take care of 1175 * setting the window's frame, either here or in finishLayout(). 1176 * 1177 * @param win The window being positioned. 1178 * @param attached For sub-windows, the window it is attached to; this 1179 * window will already have had layoutWindow() called on it 1180 * so you can use its Rect. Otherwise null. 1181 */ layoutWindowLw(WindowState win, WindowState attached)1182 public void layoutWindowLw(WindowState win, WindowState attached); 1183 1184 1185 /** 1186 * Return the insets for the areas covered by system windows. These values 1187 * are computed on the most recent layout, so they are not guaranteed to 1188 * be correct. 1189 * 1190 * @param attrs The LayoutParams of the window. 1191 * @param taskBounds The bounds of the task this window is on or {@code null} if no task is 1192 * associated with the window. 1193 * @param displayRotation Rotation of the display. 1194 * @param displayWidth The width of the display. 1195 * @param displayHeight The height of the display. 1196 * @param outContentInsets The areas covered by system windows, expressed as positive insets. 1197 * @param outStableInsets The areas covered by stable system windows irrespective of their 1198 * current visibility. Expressed as positive insets. 1199 * @param outOutsets The areas that are not real display, but we would like to treat as such. 1200 * @return Whether to always consume the navigation bar. 1201 * See {@link #isNavBarForcedShownLw(WindowState)}. 1202 */ getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, Rect outStableInsets, Rect outOutsets)1203 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, 1204 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, 1205 Rect outStableInsets, Rect outOutsets); 1206 1207 /** 1208 * Called when layout of the windows is finished. After this function has 1209 * returned, all windows given to layoutWindow() <em>must</em> have had a 1210 * frame assigned. 1211 */ finishLayoutLw()1212 public void finishLayoutLw(); 1213 1214 /** Layout state may have changed (so another layout will be performed) */ 1215 static final int FINISH_LAYOUT_REDO_LAYOUT = 0x0001; 1216 /** Configuration state may have changed */ 1217 static final int FINISH_LAYOUT_REDO_CONFIG = 0x0002; 1218 /** Wallpaper may need to move */ 1219 static final int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004; 1220 /** Need to recompute animations */ 1221 static final int FINISH_LAYOUT_REDO_ANIM = 0x0008; 1222 1223 /** 1224 * Called following layout of all windows before each window has policy applied. 1225 * 1226 * @param displayWidth The current full width of the screen. 1227 * @param displayHeight The current full height of the screen. 1228 */ beginPostLayoutPolicyLw(int displayWidth, int displayHeight)1229 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight); 1230 1231 /** 1232 * Called following layout of all window to apply policy to each window. 1233 * 1234 * @param win The window being positioned. 1235 * @param attrs The LayoutParams of the window. 1236 * @param attached For sub-windows, the window it is attached to. Otherwise null. 1237 */ applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget)1238 public void applyPostLayoutPolicyLw(WindowState win, 1239 WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget); 1240 1241 /** 1242 * Called following layout of all windows and after policy has been applied 1243 * to each window. If in this function you do 1244 * something that may have modified the animation state of another window, 1245 * be sure to return non-zero in order to perform another pass through layout. 1246 * 1247 * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT}, 1248 * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER}, 1249 * or {@link #FINISH_LAYOUT_REDO_ANIM}. 1250 */ finishPostLayoutPolicyLw()1251 public int finishPostLayoutPolicyLw(); 1252 1253 /** 1254 * Return true if it is okay to perform animations for an app transition 1255 * that is about to occur. You may return false for this if, for example, 1256 * the lock screen is currently displayed so the switch should happen 1257 * immediately. 1258 */ allowAppAnimationsLw()1259 public boolean allowAppAnimationsLw(); 1260 1261 1262 /** 1263 * A new window has been focused. 1264 */ focusChangedLw(WindowState lastFocus, WindowState newFocus)1265 public int focusChangedLw(WindowState lastFocus, WindowState newFocus); 1266 1267 /** 1268 * Called when the device has started waking up. 1269 */ startedWakingUp()1270 public void startedWakingUp(); 1271 1272 /** 1273 * Called when the device has finished waking up. 1274 */ finishedWakingUp()1275 public void finishedWakingUp(); 1276 1277 /** 1278 * Called when the device has started going to sleep. 1279 * 1280 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN}, 1281 * or {@link #OFF_BECAUSE_OF_TIMEOUT}. 1282 */ startedGoingToSleep(int why)1283 public void startedGoingToSleep(int why); 1284 1285 /** 1286 * Called when the device has finished going to sleep. 1287 * 1288 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN}, 1289 * or {@link #OFF_BECAUSE_OF_TIMEOUT}. 1290 */ finishedGoingToSleep(int why)1291 public void finishedGoingToSleep(int why); 1292 1293 /** 1294 * Called when the device is about to turn on the screen to show content. 1295 * When waking up, this method will be called once after the call to wakingUp(). 1296 * When dozing, the method will be called sometime after the call to goingToSleep() and 1297 * may be called repeatedly in the case where the screen is pulsing on and off. 1298 * 1299 * Must call back on the listener to tell it when the higher-level system 1300 * is ready for the screen to go on (i.e. the lock screen is shown). 1301 */ screenTurningOn(ScreenOnListener screenOnListener)1302 public void screenTurningOn(ScreenOnListener screenOnListener); 1303 1304 /** 1305 * Called when the device has actually turned on the screen, i.e. the display power state has 1306 * been set to ON and the screen is unblocked. 1307 */ screenTurnedOn()1308 public void screenTurnedOn(); 1309 1310 /** 1311 * Called when the display would like to be turned off. This gives policy a chance to do some 1312 * things before the display power state is actually changed to off. 1313 * 1314 * @param screenOffListener Must be called to tell that the display power state can actually be 1315 * changed now after policy has done its work. 1316 */ screenTurningOff(ScreenOffListener screenOffListener)1317 public void screenTurningOff(ScreenOffListener screenOffListener); 1318 1319 /** 1320 * Called when the device has turned the screen off. 1321 */ screenTurnedOff()1322 public void screenTurnedOff(); 1323 1324 public interface ScreenOnListener { onScreenOn()1325 void onScreenOn(); 1326 } 1327 1328 /** 1329 * See {@link #screenTurnedOff} 1330 */ 1331 public interface ScreenOffListener { onScreenOff()1332 void onScreenOff(); 1333 } 1334 1335 /** 1336 * Return whether the default display is on and not blocked by a black surface. 1337 */ isScreenOn()1338 public boolean isScreenOn(); 1339 1340 /** 1341 * @return whether the device is currently allowed to animate. 1342 * 1343 * Note: this can be true even if it is not appropriate to animate for reasons that are outside 1344 * of the policy's authority. 1345 */ okToAnimate()1346 boolean okToAnimate(); 1347 1348 /** 1349 * Tell the policy that the lid switch has changed state. 1350 * @param whenNanos The time when the change occurred in uptime nanoseconds. 1351 * @param lidOpen True if the lid is now open. 1352 */ notifyLidSwitchChanged(long whenNanos, boolean lidOpen)1353 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); 1354 1355 /** 1356 * Tell the policy that the camera lens has been covered or uncovered. 1357 * @param whenNanos The time when the change occurred in uptime nanoseconds. 1358 * @param lensCovered True if the lens is covered. 1359 */ notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered)1360 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered); 1361 1362 /** 1363 * Tell the policy if anyone is requesting that keyguard not come on. 1364 * 1365 * @param enabled Whether keyguard can be on or not. does not actually 1366 * turn it on, unless it was previously disabled with this function. 1367 * 1368 * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard() 1369 * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard() 1370 */ 1371 @SuppressWarnings("javadoc") enableKeyguard(boolean enabled)1372 public void enableKeyguard(boolean enabled); 1373 1374 /** 1375 * Callback used by {@link WindowManagerPolicy#exitKeyguardSecurely} 1376 */ 1377 interface OnKeyguardExitResult { onKeyguardExitResult(boolean success)1378 void onKeyguardExitResult(boolean success); 1379 } 1380 1381 /** 1382 * Tell the policy if anyone is requesting the keyguard to exit securely 1383 * (this would be called after the keyguard was disabled) 1384 * @param callback Callback to send the result back. 1385 * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult) 1386 */ 1387 @SuppressWarnings("javadoc") exitKeyguardSecurely(OnKeyguardExitResult callback)1388 void exitKeyguardSecurely(OnKeyguardExitResult callback); 1389 1390 /** 1391 * isKeyguardLocked 1392 * 1393 * Return whether the keyguard is currently locked. 1394 * 1395 * @return true if in keyguard is locked. 1396 */ isKeyguardLocked()1397 public boolean isKeyguardLocked(); 1398 1399 /** 1400 * isKeyguardSecure 1401 * 1402 * Return whether the keyguard requires a password to unlock. 1403 * @param userId 1404 * 1405 * @return true if in keyguard is secure. 1406 */ isKeyguardSecure(int userId)1407 public boolean isKeyguardSecure(int userId); 1408 1409 /** 1410 * Return whether the keyguard is currently occluded. 1411 * 1412 * @return true if in keyguard is occluded, false otherwise 1413 */ isKeyguardOccluded()1414 public boolean isKeyguardOccluded(); 1415 1416 /** 1417 * @return true if in keyguard is on and not occluded. 1418 */ isKeyguardShowingAndNotOccluded()1419 public boolean isKeyguardShowingAndNotOccluded(); 1420 1421 /** 1422 * @return whether Keyguard is in trusted state and can be dismissed without credentials 1423 */ isKeyguardTrustedLw()1424 public boolean isKeyguardTrustedLw(); 1425 1426 /** 1427 * inKeyguardRestrictedKeyInputMode 1428 * 1429 * if keyguard screen is showing or in restricted key input mode (i.e. in 1430 * keyguard password emergency screen). When in such mode, certain keys, 1431 * such as the Home key and the right soft keys, don't work. 1432 * 1433 * @return true if in keyguard restricted input mode. 1434 */ inKeyguardRestrictedKeyInputMode()1435 public boolean inKeyguardRestrictedKeyInputMode(); 1436 1437 /** 1438 * Ask the policy to dismiss the keyguard, if it is currently shown. 1439 * 1440 * @param callback Callback to be informed about the result. 1441 */ dismissKeyguardLw(@ullable IKeyguardDismissCallback callback)1442 public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback); 1443 1444 /** 1445 * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method 1446 * returns true as soon as we know that Keyguard is disabled. 1447 * 1448 * @return true if the keyguard has drawn. 1449 */ isKeyguardDrawnLw()1450 public boolean isKeyguardDrawnLw(); 1451 isShowingDreamLw()1452 public boolean isShowingDreamLw(); 1453 1454 /** 1455 * Given an orientation constant, returns the appropriate surface rotation, 1456 * taking into account sensors, docking mode, rotation lock, and other factors. 1457 * 1458 * @param orientation An orientation constant, such as 1459 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}. 1460 * @param lastRotation The most recently used rotation. 1461 * @return The surface rotation to use. 1462 */ rotationForOrientationLw(@ctivityInfo.ScreenOrientation int orientation, int lastRotation)1463 public int rotationForOrientationLw(@ActivityInfo.ScreenOrientation int orientation, 1464 int lastRotation); 1465 1466 /** 1467 * Given an orientation constant and a rotation, returns true if the rotation 1468 * has compatible metrics to the requested orientation. For example, if 1469 * the application requested landscape and got seascape, then the rotation 1470 * has compatible metrics; if the application requested portrait and got landscape, 1471 * then the rotation has incompatible metrics; if the application did not specify 1472 * a preference, then anything goes. 1473 * 1474 * @param orientation An orientation constant, such as 1475 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}. 1476 * @param rotation The rotation to check. 1477 * @return True if the rotation is compatible with the requested orientation. 1478 */ rotationHasCompatibleMetricsLw(@ctivityInfo.ScreenOrientation int orientation, int rotation)1479 public boolean rotationHasCompatibleMetricsLw(@ActivityInfo.ScreenOrientation int orientation, 1480 int rotation); 1481 1482 /** 1483 * Called by the window manager when the rotation changes. 1484 * 1485 * @param rotation The new rotation. 1486 */ setRotationLw(int rotation)1487 public void setRotationLw(int rotation); 1488 1489 /** 1490 * Called when the system is mostly done booting to set whether 1491 * the system should go into safe mode. 1492 */ setSafeMode(boolean safeMode)1493 public void setSafeMode(boolean safeMode); 1494 1495 /** 1496 * Called when the system is mostly done booting. 1497 */ systemReady()1498 public void systemReady(); 1499 1500 /** 1501 * Called when the system is done booting to the point where the 1502 * user can start interacting with it. 1503 */ systemBooted()1504 public void systemBooted(); 1505 1506 /** 1507 * Show boot time message to the user. 1508 */ showBootMessage(final CharSequence msg, final boolean always)1509 public void showBootMessage(final CharSequence msg, final boolean always); 1510 1511 /** 1512 * Hide the UI for showing boot messages, never to be displayed again. 1513 */ hideBootMessages()1514 public void hideBootMessages(); 1515 1516 /** 1517 * Called when userActivity is signalled in the power manager. 1518 * This is safe to call from any thread, with any window manager locks held or not. 1519 */ userActivity()1520 public void userActivity(); 1521 1522 /** 1523 * Called when we have finished booting and can now display the home 1524 * screen to the user. This will happen after systemReady(), and at 1525 * this point the display is active. 1526 */ enableScreenAfterBoot()1527 public void enableScreenAfterBoot(); 1528 setCurrentOrientationLw(@ctivityInfo.ScreenOrientation int newOrientation)1529 public void setCurrentOrientationLw(@ActivityInfo.ScreenOrientation int newOrientation); 1530 1531 /** 1532 * Call from application to perform haptic feedback on its window. 1533 */ performHapticFeedbackLw(WindowState win, int effectId, boolean always)1534 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always); 1535 1536 /** 1537 * Called when we have started keeping the screen on because a window 1538 * requesting this has become visible. 1539 */ keepScreenOnStartedLw()1540 public void keepScreenOnStartedLw(); 1541 1542 /** 1543 * Called when we have stopped keeping the screen on because the last window 1544 * requesting this is no longer visible. 1545 */ keepScreenOnStoppedLw()1546 public void keepScreenOnStoppedLw(); 1547 1548 /** 1549 * Gets the current user rotation mode. 1550 * 1551 * @return The rotation mode. 1552 * 1553 * @see WindowManagerPolicy#USER_ROTATION_LOCKED 1554 * @see WindowManagerPolicy#USER_ROTATION_FREE 1555 */ 1556 @UserRotationMode getUserRotationMode()1557 public int getUserRotationMode(); 1558 1559 /** 1560 * Inform the policy that the user has chosen a preferred orientation ("rotation lock"). 1561 * 1562 * @param mode One of {@link WindowManagerPolicy#USER_ROTATION_LOCKED} or 1563 * {@link WindowManagerPolicy#USER_ROTATION_FREE}. 1564 * @param rotation One of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90}, 1565 * {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270}. 1566 */ setUserRotationMode(@serRotationMode int mode, @Surface.Rotation int rotation)1567 public void setUserRotationMode(@UserRotationMode int mode, @Surface.Rotation int rotation); 1568 1569 /** 1570 * Called when a new system UI visibility is being reported, allowing 1571 * the policy to adjust what is actually reported. 1572 * @param visibility The raw visibility reported by the status bar. 1573 * @return The new desired visibility. 1574 */ adjustSystemUiVisibilityLw(int visibility)1575 public int adjustSystemUiVisibilityLw(int visibility); 1576 1577 /** 1578 * Called by System UI to notify of changes to the visibility of Recents. 1579 */ setRecentsVisibilityLw(boolean visible)1580 public void setRecentsVisibilityLw(boolean visible); 1581 1582 /** 1583 * Called by System UI to notify of changes to the visibility of PIP. 1584 */ setPipVisibilityLw(boolean visible)1585 void setPipVisibilityLw(boolean visible); 1586 1587 /** 1588 * Specifies whether there is an on-screen navigation bar separate from the status bar. 1589 */ hasNavigationBar()1590 public boolean hasNavigationBar(); 1591 1592 /** 1593 * Lock the device now. 1594 */ lockNow(Bundle options)1595 public void lockNow(Bundle options); 1596 1597 /** 1598 * Set the last used input method window state. This state is used to make IME transition 1599 * smooth. 1600 * @hide 1601 */ setLastInputMethodWindowLw(WindowState ime, WindowState target)1602 public void setLastInputMethodWindowLw(WindowState ime, WindowState target); 1603 1604 /** 1605 * An internal callback (from InputMethodManagerService) to notify a state change regarding 1606 * whether the back key should dismiss the software keyboard (IME) or not. 1607 * 1608 * @param newValue {@code true} if the software keyboard is shown and the back key is expected 1609 * to dismiss the software keyboard. 1610 * @hide 1611 */ setDismissImeOnBackKeyPressed(boolean newValue)1612 default void setDismissImeOnBackKeyPressed(boolean newValue) { 1613 // Default implementation does nothing. 1614 } 1615 1616 /** 1617 * Show the recents task list app. 1618 * @hide 1619 */ showRecentApps(boolean fromHome)1620 public void showRecentApps(boolean fromHome); 1621 1622 /** 1623 * Show the global actions dialog. 1624 * @hide 1625 */ showGlobalActions()1626 public void showGlobalActions(); 1627 1628 /** 1629 * @return The current height of the input method window. 1630 */ getInputMethodWindowVisibleHeightLw()1631 public int getInputMethodWindowVisibleHeightLw(); 1632 1633 /** 1634 * Called when the current user changes. Guaranteed to be called before the broadcast 1635 * of the new user id is made to all listeners. 1636 * 1637 * @param newUserId The id of the incoming user. 1638 */ setCurrentUserLw(int newUserId)1639 public void setCurrentUserLw(int newUserId); 1640 1641 /** 1642 * For a given user-switch operation, this will be called once with switching=true before the 1643 * user-switch and once with switching=false afterwards (or if the user-switch was cancelled). 1644 * This gives the policy a chance to alter its behavior for the duration of a user-switch. 1645 * 1646 * @param switching true if a user-switch is in progress 1647 */ setSwitchingUser(boolean switching)1648 void setSwitchingUser(boolean switching); 1649 1650 /** 1651 * Print the WindowManagerPolicy's state into the given stream. 1652 * 1653 * @param prefix Text to print at the front of each line. 1654 * @param writer The PrintWriter to which you should dump your state. This will be 1655 * closed for you after you return. 1656 * @param args additional arguments to the dump request. 1657 */ dump(String prefix, PrintWriter writer, String[] args)1658 public void dump(String prefix, PrintWriter writer, String[] args); 1659 1660 /** 1661 * Returns whether a given window type can be magnified. 1662 * 1663 * @param windowType The window type. 1664 * @return True if the window can be magnified. 1665 */ canMagnifyWindow(int windowType)1666 public boolean canMagnifyWindow(int windowType); 1667 1668 /** 1669 * Returns whether a given window type is considered a top level one. 1670 * A top level window does not have a container, i.e. attached window, 1671 * or if it has a container it is laid out as a top-level window, not 1672 * as a child of its container. 1673 * 1674 * @param windowType The window type. 1675 * @return True if the window is a top level one. 1676 */ isTopLevelWindow(int windowType)1677 public boolean isTopLevelWindow(int windowType); 1678 1679 /** 1680 * Notifies the keyguard to start fading out. 1681 * 1682 * @param startTime the start time of the animation in uptime milliseconds 1683 * @param fadeoutDuration the duration of the exit animation, in milliseconds 1684 */ startKeyguardExitAnimation(long startTime, long fadeoutDuration)1685 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration); 1686 1687 /** 1688 * Calculates the stable insets without running a layout. 1689 * 1690 * @param displayRotation the current display rotation 1691 * @param displayWidth the current display width 1692 * @param displayHeight the current display height 1693 * @param outInsets the insets to return 1694 */ getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, Rect outInsets)1695 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, 1696 Rect outInsets); 1697 1698 1699 /** 1700 * @return true if the navigation bar is forced to stay visible 1701 */ isNavBarForcedShownLw(WindowState win)1702 public boolean isNavBarForcedShownLw(WindowState win); 1703 1704 /** 1705 * @return The side of the screen where navigation bar is positioned. 1706 * @see #NAV_BAR_LEFT 1707 * @see #NAV_BAR_RIGHT 1708 * @see #NAV_BAR_BOTTOM 1709 */ getNavBarPosition()1710 int getNavBarPosition(); 1711 1712 /** 1713 * Calculates the insets for the areas that could never be removed in Honeycomb, i.e. system 1714 * bar or button bar. See {@link #getNonDecorDisplayWidth}. 1715 * 1716 * @param displayRotation the current display rotation 1717 * @param displayWidth the current display width 1718 * @param displayHeight the current display height 1719 * @param outInsets the insets to return 1720 */ getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, Rect outInsets)1721 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, 1722 Rect outInsets); 1723 1724 /** 1725 * @return True if a specified {@param dockSide} is allowed on the current device, or false 1726 * otherwise. It is guaranteed that at least one dock side for a particular orientation 1727 * is allowed, so for example, if DOCKED_RIGHT is not allowed, DOCKED_LEFT is allowed. 1728 */ isDockSideAllowed(int dockSide)1729 public boolean isDockSideAllowed(int dockSide); 1730 1731 /** 1732 * Called when the configuration has changed, and it's safe to load new values from resources. 1733 */ onConfigurationChanged()1734 public void onConfigurationChanged(); 1735 shouldRotateSeamlessly(int oldRotation, int newRotation)1736 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation); 1737 1738 /** 1739 * Called when System UI has been started. 1740 */ onSystemUiStarted()1741 void onSystemUiStarted(); 1742 1743 /** 1744 * Checks whether the policy is ready for dismissing the boot animation and completing the boot. 1745 * 1746 * @return true if ready; false otherwise. 1747 */ canDismissBootAnimation()1748 boolean canDismissBootAnimation(); 1749 } 1750