1 /* 2 * Copyright (C) 2017 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 com.android.server.policy; 18 19 import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; 20 import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; 21 import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; 22 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL; 23 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; 24 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; 25 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; 26 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; 27 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; 28 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; 29 import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; 30 import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY; 31 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; 32 import static android.view.WindowManager.LayoutParams.TYPE_DRAG; 33 import static android.view.WindowManager.LayoutParams.TYPE_DREAM; 34 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; 35 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; 36 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; 37 import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; 38 import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; 39 import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; 40 import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; 41 import static android.view.WindowManager.LayoutParams.TYPE_PHONE; 42 import static android.view.WindowManager.LayoutParams.TYPE_POINTER; 43 import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; 44 import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; 45 import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION; 46 import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; 47 import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; 48 import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; 49 import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; 50 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; 51 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; 52 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; 53 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; 54 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; 55 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; 56 import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; 57 import static android.view.WindowManager.LayoutParams.TYPE_TOAST; 58 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; 59 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; 60 import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; 61 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; 62 import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; 63 64 import static java.lang.annotation.RetentionPolicy.SOURCE; 65 66 import android.annotation.IntDef; 67 import android.annotation.NonNull; 68 import android.annotation.Nullable; 69 import android.app.WindowConfiguration; 70 import android.content.Context; 71 import android.content.res.CompatibilityInfo; 72 import android.content.res.Configuration; 73 import android.graphics.Rect; 74 import android.os.Bundle; 75 import android.os.IBinder; 76 import android.os.Looper; 77 import android.os.RemoteException; 78 import android.util.Slog; 79 import android.util.proto.ProtoOutputStream; 80 import android.view.Display; 81 import android.view.IApplicationToken; 82 import android.view.IDisplayFoldListener; 83 import android.view.IWindowManager; 84 import android.view.InputEventReceiver; 85 import android.view.KeyEvent; 86 import android.view.WindowManager; 87 import android.view.WindowManagerGlobal; 88 import android.view.WindowManagerPolicyConstants; 89 import android.view.animation.Animation; 90 91 import com.android.internal.policy.IKeyguardDismissCallback; 92 import com.android.internal.policy.IShortcutService; 93 import com.android.server.wm.DisplayRotation; 94 import com.android.server.wm.WindowFrames; 95 96 import java.io.PrintWriter; 97 import java.lang.annotation.Retention; 98 import java.lang.annotation.RetentionPolicy; 99 100 /** 101 * This interface supplies all UI-specific behavior of the window manager. An 102 * instance of it is created by the window manager when it starts up, and allows 103 * customization of window layering, special window types, key dispatching, and 104 * layout. 105 * 106 * <p>Because this provides deep interaction with the system window manager, 107 * specific methods on this interface can be called from a variety of contexts 108 * with various restrictions on what they can do. These are encoded through 109 * a suffixes at the end of a method encoding the thread the method is called 110 * from and any locks that are held when it is being called; if no suffix 111 * is attached to a method, then it is not called with any locks and may be 112 * called from the main window manager thread or another thread calling into 113 * the window manager. 114 * 115 * <p>The current suffixes are: 116 * 117 * <dl> 118 * <dt> Ti <dd> Called from the input thread. This is the thread that 119 * collects pending input events and dispatches them to the appropriate window. 120 * It may block waiting for events to be processed, so that the input stream is 121 * properly serialized. 122 * <dt> Tq <dd> Called from the low-level input queue thread. This is the 123 * thread that reads events out of the raw input devices and places them 124 * into the global input queue that is read by the <var>Ti</var> thread. 125 * This thread should not block for a long period of time on anything but the 126 * key driver. 127 * <dt> Lw <dd> Called with the main window manager lock held. Because the 128 * window manager is a very low-level system service, there are few other 129 * system services you can call with this lock held. It is explicitly okay to 130 * make calls into the package manager and power manager; it is explicitly not 131 * okay to make calls into the activity manager or most other services. Note that 132 * {@link android.content.Context#checkPermission(String, int, int)} and 133 * variations require calling into the activity manager. 134 * <dt> Li <dd> Called with the input thread lock held. This lock can be 135 * acquired by the window manager while it holds the window lock, so this is 136 * even more restrictive than <var>Lw</var>. 137 * </dl> 138 */ 139 public interface WindowManagerPolicy extends WindowManagerPolicyConstants { 140 @Retention(SOURCE) 141 @IntDef({NAV_BAR_LEFT, NAV_BAR_RIGHT, NAV_BAR_BOTTOM}) 142 @interface NavigationBarPosition {} 143 144 /** 145 * Pass this event to the user / app. To be returned from 146 * {@link #interceptKeyBeforeQueueing}. 147 */ 148 int ACTION_PASS_TO_USER = 0x00000001; 149 /** Layout state may have changed (so another layout will be performed) */ 150 int FINISH_LAYOUT_REDO_LAYOUT = 0x0001; 151 /** Configuration state may have changed */ 152 int FINISH_LAYOUT_REDO_CONFIG = 0x0002; 153 /** Wallpaper may need to move */ 154 int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004; 155 /** Need to recompute animations */ 156 int FINISH_LAYOUT_REDO_ANIM = 0x0008; 157 /** Layer for the screen off animation */ 158 int COLOR_FADE_LAYER = 0x40000001; 159 160 /** 161 * Register shortcuts for window manager to dispatch. 162 * Shortcut code is packed as (metaState << Integer.SIZE) | keyCode 163 * @hide 164 */ registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver)165 void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver) 166 throws RemoteException; 167 168 /** 169 * Called when the Keyguard occluded state changed. 170 * @param occluded Whether Keyguard is currently occluded or not. 171 */ onKeyguardOccludedChangedLw(boolean occluded)172 void onKeyguardOccludedChangedLw(boolean occluded); 173 174 /** 175 * Interface to the Window Manager state associated with a particular 176 * window. You can hold on to an instance of this interface from the call 177 * to prepareAddWindow() until removeWindow(). 178 */ 179 public interface WindowState { 180 /** 181 * Return the uid of the app that owns this window. 182 */ getOwningUid()183 int getOwningUid(); 184 185 /** 186 * Return the package name of the app that owns this window. 187 */ getOwningPackage()188 String getOwningPackage(); 189 190 /** 191 * Perform standard frame computation. The result can be obtained with 192 * getFrame() if so desired. Must be called with the window manager 193 * lock held. 194 * 195 */ computeFrameLw()196 public void computeFrameLw(); 197 198 /** 199 * Retrieve the current frame of the window that has been assigned by 200 * the window manager. Must be called with the window manager lock held. 201 * 202 * @return Rect The rectangle holding the window frame. 203 */ getFrameLw()204 public Rect getFrameLw(); 205 206 /** 207 * Retrieve the frame of the display that this window was last 208 * laid out in. Must be called with the 209 * window manager lock held. 210 * 211 * @return Rect The rectangle holding the display frame. 212 */ getDisplayFrameLw()213 public Rect getDisplayFrameLw(); 214 215 /** 216 * Retrieve the frame of the area inside the overscan region of the 217 * display that this window was last laid out in. Must be called with the 218 * window manager lock held. 219 * 220 * @return Rect The rectangle holding the display overscan frame. 221 */ getOverscanFrameLw()222 public Rect getOverscanFrameLw(); 223 224 /** 225 * Retrieve the frame of the content area that this window was last 226 * laid out in. This is the area in which the content of the window 227 * should be placed. It will be smaller than the display frame to 228 * account for screen decorations such as a status bar or soft 229 * keyboard. Must be called with the 230 * window manager lock held. 231 * 232 * @return Rect The rectangle holding the content frame. 233 */ getContentFrameLw()234 public Rect getContentFrameLw(); 235 236 /** 237 * Retrieve the frame of the visible area that this window was last 238 * laid out in. This is the area of the screen in which the window 239 * will actually be fully visible. It will be smaller than the 240 * content frame to account for transient UI elements blocking it 241 * such as an input method's candidates UI. Must be called with the 242 * window manager lock held. 243 * 244 * @return Rect The rectangle holding the visible frame. 245 */ getVisibleFrameLw()246 public Rect getVisibleFrameLw(); 247 248 /** 249 * Returns true if this window is waiting to receive its given 250 * internal insets from the client app, and so should not impact the 251 * layout of other windows. 252 */ getGivenInsetsPendingLw()253 public boolean getGivenInsetsPendingLw(); 254 255 /** 256 * Retrieve the insets given by this window's client for the content 257 * area of windows behind it. Must be called with the 258 * window manager lock held. 259 * 260 * @return Rect The left, top, right, and bottom insets, relative 261 * to the window's frame, of the actual contents. 262 */ getGivenContentInsetsLw()263 public Rect getGivenContentInsetsLw(); 264 265 /** 266 * Retrieve the insets given by this window's client for the visible 267 * area of windows behind it. Must be called with the 268 * window manager lock held. 269 * 270 * @return Rect The left, top, right, and bottom insets, relative 271 * to the window's frame, of the actual visible area. 272 */ getGivenVisibleInsetsLw()273 public Rect getGivenVisibleInsetsLw(); 274 275 /** 276 * Retrieve the current LayoutParams of the window. 277 * 278 * @return WindowManager.LayoutParams The window's internal LayoutParams 279 * instance. 280 */ getAttrs()281 public WindowManager.LayoutParams getAttrs(); 282 283 /** 284 * Return whether this window needs the menu key shown. Must be called 285 * with window lock held, because it may need to traverse down through 286 * window list to determine the result. 287 * @param bottom The bottom-most window to consider when determining this. 288 */ getNeedsMenuLw(WindowState bottom)289 public boolean getNeedsMenuLw(WindowState bottom); 290 291 /** 292 * Retrieve the current system UI visibility flags associated with 293 * this window. 294 */ getSystemUiVisibility()295 public int getSystemUiVisibility(); 296 297 /** 298 * Get the layer at which this window's surface will be Z-ordered. 299 */ getSurfaceLayer()300 public int getSurfaceLayer(); 301 302 /** 303 * Retrieve the type of the top-level window. 304 * 305 * @return the base type of the parent window if attached or its own type otherwise 306 */ getBaseType()307 public int getBaseType(); 308 309 /** 310 * Return the token for the application (actually activity) that owns 311 * this window. May return null for system windows. 312 * 313 * @return An IApplicationToken identifying the owning activity. 314 */ getAppToken()315 public IApplicationToken getAppToken(); 316 317 /** 318 * Return true if this window is participating in voice interaction. 319 */ isVoiceInteraction()320 public boolean isVoiceInteraction(); 321 322 /** 323 * Return true if, at any point, the application token associated with 324 * this window has actually displayed any windows. This is most useful 325 * with the "starting up" window to determine if any windows were 326 * displayed when it is closed. 327 * 328 * @return Returns true if one or more windows have been displayed, 329 * else false. 330 */ hasAppShownWindows()331 public boolean hasAppShownWindows(); 332 333 /** 334 * Is this window visible? It is not visible if there is no 335 * surface, or we are in the process of running an exit animation 336 * that will remove the surface. 337 */ isVisibleLw()338 boolean isVisibleLw(); 339 340 /** 341 * Is this window currently visible to the user on-screen? It is 342 * displayed either if it is visible or it is currently running an 343 * animation before no longer being visible. Must be called with the 344 * window manager lock held. 345 */ isDisplayedLw()346 boolean isDisplayedLw(); 347 348 /** 349 * Return true if this window (or a window it is attached to, but not 350 * considering its app token) is currently animating. 351 */ isAnimatingLw()352 boolean isAnimatingLw(); 353 354 /** 355 * @return Whether the window can affect SystemUI flags, meaning that SystemUI (system bars, 356 * for example) will be affected by the flags specified in this window. This is the 357 * case when the surface is on screen but not exiting. 358 */ canAffectSystemUiFlags()359 boolean canAffectSystemUiFlags(); 360 361 /** 362 * Is this window considered to be gone for purposes of layout? 363 */ isGoneForLayoutLw()364 boolean isGoneForLayoutLw(); 365 366 /** 367 * Returns true if the window has a surface that it has drawn a 368 * complete UI in to. Note that this is different from {@link #hasDrawnLw()} 369 * in that it also returns true if the window is READY_TO_SHOW, but was not yet 370 * promoted to HAS_DRAWN. 371 */ isDrawnLw()372 boolean isDrawnLw(); 373 374 /** 375 * Returns true if this window has been shown on screen at some time in 376 * the past. Must be called with the window manager lock held. 377 * 378 * @deprecated Use {@link #isDrawnLw} or any of the other drawn/visibility methods. 379 */ 380 @Deprecated hasDrawnLw()381 public boolean hasDrawnLw(); 382 383 /** 384 * Can be called by the policy to force a window to be hidden, 385 * regardless of whether the client or window manager would like 386 * it shown. Must be called with the window manager lock held. 387 * Returns true if {@link #showLw} was last called for the window. 388 */ hideLw(boolean doAnimation)389 public boolean hideLw(boolean doAnimation); 390 391 /** 392 * Can be called to undo the effect of {@link #hideLw}, allowing a 393 * window to be shown as long as the window manager and client would 394 * also like it to be shown. Must be called with the window manager 395 * lock held. 396 * Returns true if {@link #hideLw} was last called for the window. 397 */ showLw(boolean doAnimation)398 public boolean showLw(boolean doAnimation); 399 400 /** 401 * Check whether the process hosting this window is currently alive. 402 */ isAlive()403 public boolean isAlive(); 404 405 /** 406 * Check if window is on {@link Display#DEFAULT_DISPLAY}. 407 * @return true if window is on default display. 408 */ isDefaultDisplay()409 public boolean isDefaultDisplay(); 410 411 /** 412 * Check whether the window is currently dimming. 413 */ isDimming()414 public boolean isDimming(); 415 416 /** 417 * Returns true if the window is letterboxed for the display cutout. 418 */ isLetterboxedForDisplayCutoutLw()419 default boolean isLetterboxedForDisplayCutoutLw() { 420 return false; 421 } 422 423 /** 424 * Returns true if the window has a letterbox and any part of that letterbox overlaps with 425 * the given {@code rect}. 426 */ isLetterboxedOverlappingWith(Rect rect)427 default boolean isLetterboxedOverlappingWith(Rect rect) { 428 return false; 429 } 430 431 /** @return the current windowing mode of this window. */ getWindowingMode()432 int getWindowingMode(); 433 434 /** 435 * Returns the {@link WindowConfiguration.ActivityType} associated with the configuration 436 * of this window. 437 */ getActivityType()438 default int getActivityType() { 439 return WindowConfiguration.WINDOWING_MODE_UNDEFINED; 440 } 441 442 /** 443 * Returns true if the window is current in multi-windowing mode. i.e. it shares the 444 * screen with other application windows. 445 */ inMultiWindowMode()446 boolean inMultiWindowMode(); 447 getRotationAnimationHint()448 public int getRotationAnimationHint(); 449 isInputMethodWindow()450 public boolean isInputMethodWindow(); 451 isInputMethodTarget()452 public boolean isInputMethodTarget(); 453 getDisplayId()454 public int getDisplayId(); 455 456 /** 457 * Returns true if the window owner can add internal system windows. 458 * That is, they have {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}. 459 */ canAddInternalSystemWindow()460 default boolean canAddInternalSystemWindow() { 461 return false; 462 } 463 464 /** 465 * Returns true if the window owner has the permission to acquire a sleep token when it's 466 * visible. That is, they have the permission {@link Manifest.permission#DEVICE_POWER}. 467 */ canAcquireSleepToken()468 boolean canAcquireSleepToken(); 469 470 /** @return true if this window desires key events. */ canReceiveKeys()471 boolean canReceiveKeys(); 472 473 /** @return true if the window can show over keyguard. */ canShowWhenLocked()474 boolean canShowWhenLocked(); 475 476 /** 477 * Writes {@link com.android.server.wm.IdentifierProto} to stream. 478 */ writeIdentifierToProto(ProtoOutputStream proto, long fieldId)479 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId); 480 481 /** 482 * @return The {@link WindowFrames} associated with this {@link WindowState} 483 */ getWindowFrames()484 WindowFrames getWindowFrames(); 485 } 486 487 /** 488 * Representation of a input consumer that the policy has added to the 489 * window manager to consume input events going to windows below it. 490 */ 491 public interface InputConsumer { 492 /** 493 * Remove the input consumer from the window manager. 494 */ dismiss()495 void dismiss(); 496 } 497 498 /** 499 * Holds the contents of a starting window. {@link #addSplashScreen} needs to wrap the 500 * contents of the starting window into an class implementing this interface, which then will be 501 * held by WM and released with {@link #remove} when no longer needed. 502 */ 503 interface StartingSurface { 504 505 /** 506 * Removes the starting window surface. Do not hold the window manager lock when calling 507 * this method! 508 */ remove()509 void remove(); 510 } 511 512 /** 513 * Interface for calling back in to the window manager that is private 514 * between it and the policy. 515 */ 516 public interface WindowManagerFuncs { 517 public static final int LID_ABSENT = -1; 518 public static final int LID_CLOSED = 0; 519 public static final int LID_OPEN = 1; 520 521 public static final int LID_BEHAVIOR_NONE = 0; 522 public static final int LID_BEHAVIOR_SLEEP = 1; 523 public static final int LID_BEHAVIOR_LOCK = 2; 524 525 public static final int CAMERA_LENS_COVER_ABSENT = -1; 526 public static final int CAMERA_LENS_UNCOVERED = 0; 527 public static final int CAMERA_LENS_COVERED = 1; 528 529 /** 530 * Add a input consumer which will consume all input events going to any window below it. 531 */ createInputConsumer(Looper looper, String name, InputEventReceiver.Factory inputEventReceiverFactory, int displayId)532 public InputConsumer createInputConsumer(Looper looper, String name, 533 InputEventReceiver.Factory inputEventReceiverFactory, int displayId); 534 535 /** 536 * Returns a code that describes the current state of the lid switch. 537 */ getLidState()538 public int getLidState(); 539 540 /** 541 * Lock the device now. 542 */ lockDeviceNow()543 public void lockDeviceNow(); 544 545 /** 546 * Returns a code that descripbes whether the camera lens is covered or not. 547 */ getCameraLensCoverState()548 public int getCameraLensCoverState(); 549 550 /** 551 * Switch the keyboard layout for the given device. 552 * Direction should be +1 or -1 to go to the next or previous keyboard layout. 553 */ switchKeyboardLayout(int deviceId, int direction)554 public void switchKeyboardLayout(int deviceId, int direction); 555 shutdown(boolean confirm)556 public void shutdown(boolean confirm); reboot(boolean confirm)557 public void reboot(boolean confirm); rebootSafeMode(boolean confirm)558 public void rebootSafeMode(boolean confirm); 559 560 /** 561 * Return the window manager lock needed to correctly call "Lw" methods. 562 */ getWindowManagerLock()563 public Object getWindowManagerLock(); 564 565 /** Register a system listener for touch events */ registerPointerEventListener(PointerEventListener listener, int displayId)566 void registerPointerEventListener(PointerEventListener listener, int displayId); 567 568 /** Unregister a system listener for touch events */ unregisterPointerEventListener(PointerEventListener listener, int displayId)569 void unregisterPointerEventListener(PointerEventListener listener, int displayId); 570 571 /** 572 * Retrieves the {@param outBounds} from the stack matching the {@param windowingMode} and 573 * {@param activityType}. 574 */ getStackBounds(int windowingMode, int activityType, Rect outBounds)575 void getStackBounds(int windowingMode, int activityType, Rect outBounds); 576 577 /** 578 * @return The currently active input method window. 579 */ getInputMethodWindowLw()580 WindowState getInputMethodWindowLw(); 581 582 /** 583 * Notifies window manager that {@link #isKeyguardTrustedLw} has changed. 584 */ notifyKeyguardTrustedChanged()585 void notifyKeyguardTrustedChanged(); 586 587 /** 588 * Notifies the window manager that screen is being turned off. 589 * 590 * @param listener callback to call when display can be turned off 591 */ screenTurningOff(ScreenOffListener listener)592 void screenTurningOff(ScreenOffListener listener); 593 594 /** 595 * Convert the lid state to a human readable format. 596 */ lidStateToString(int lid)597 static String lidStateToString(int lid) { 598 switch (lid) { 599 case LID_ABSENT: 600 return "LID_ABSENT"; 601 case LID_CLOSED: 602 return "LID_CLOSED"; 603 case LID_OPEN: 604 return "LID_OPEN"; 605 default: 606 return Integer.toString(lid); 607 } 608 } 609 610 /** 611 * Convert the camera lens state to a human readable format. 612 */ cameraLensStateToString(int lens)613 static String cameraLensStateToString(int lens) { 614 switch (lens) { 615 case CAMERA_LENS_COVER_ABSENT: 616 return "CAMERA_LENS_COVER_ABSENT"; 617 case CAMERA_LENS_UNCOVERED: 618 return "CAMERA_LENS_UNCOVERED"; 619 case CAMERA_LENS_COVERED: 620 return "CAMERA_LENS_COVERED"; 621 default: 622 return Integer.toString(lens); 623 } 624 } 625 626 /** 627 * Hint to window manager that the user has started a navigation action that should 628 * abort animations that have no timeout, in case they got stuck. 629 */ triggerAnimationFailsafe()630 void triggerAnimationFailsafe(); 631 632 /** 633 * The keyguard showing state has changed 634 */ onKeyguardShowingAndNotOccludedChanged()635 void onKeyguardShowingAndNotOccludedChanged(); 636 637 /** 638 * Notifies window manager that power key is being pressed. 639 */ onPowerKeyDown(boolean isScreenOn)640 void onPowerKeyDown(boolean isScreenOn); 641 642 /** 643 * Notifies window manager that user is switched. 644 */ onUserSwitched()645 void onUserSwitched(); 646 647 /** 648 * Hint to window manager that the user is interacting with a display that should be treated 649 * as the top display. 650 */ moveDisplayToTop(int displayId)651 void moveDisplayToTop(int displayId); 652 } 653 654 /** 655 * Provides the rotation of a device. 656 * 657 * @see com.android.server.policy.WindowOrientationListener 658 */ 659 public interface RotationSource { getProposedRotation()660 int getProposedRotation(); 661 setCurrentRotation(int rotation)662 void setCurrentRotation(int rotation); 663 } 664 665 /** 666 * Interface to get public information of a display content. 667 */ 668 public interface DisplayContentInfo { getDisplayRotation()669 DisplayRotation getDisplayRotation(); getDisplay()670 Display getDisplay(); 671 } 672 673 /** Window has been added to the screen. */ 674 public static final int TRANSIT_ENTER = 1; 675 /** Window has been removed from the screen. */ 676 public static final int TRANSIT_EXIT = 2; 677 /** Window has been made visible. */ 678 public static final int TRANSIT_SHOW = 3; 679 /** Window has been made invisible. 680 * TODO: Consider removal as this is unused. */ 681 public static final int TRANSIT_HIDE = 4; 682 /** The "application starting" preview window is no longer needed, and will 683 * animate away to show the real window. */ 684 public static final int TRANSIT_PREVIEW_DONE = 5; 685 686 // NOTE: screen off reasons are in order of significance, with more 687 // important ones lower than less important ones. 688 689 /** @hide */ 690 @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED}) 691 @Retention(RetentionPolicy.SOURCE) 692 public @interface UserRotationMode {} 693 694 /** When not otherwise specified by the activity's screenOrientation, rotation should be 695 * determined by the system (that is, using sensors). */ 696 public final int USER_ROTATION_FREE = 0; 697 /** When not otherwise specified by the activity's screenOrientation, rotation is set by 698 * the user. */ 699 public final int USER_ROTATION_LOCKED = 1; 700 701 /** 702 * Set the default display content to provide basic functions for the policy. 703 */ setDefaultDisplay(DisplayContentInfo displayContentInfo)704 public void setDefaultDisplay(DisplayContentInfo displayContentInfo); 705 706 /** 707 * Perform initialization of the policy. 708 * 709 * @param context The system context we are running in. 710 */ init(Context context, IWindowManager windowManager, WindowManagerFuncs windowManagerFuncs)711 public void init(Context context, IWindowManager windowManager, 712 WindowManagerFuncs windowManagerFuncs); 713 714 /** 715 * Check permissions when adding a window. 716 * 717 * @param attrs The window's LayoutParams. 718 * @param outAppOp First element will be filled with the app op corresponding to 719 * this window, or OP_NONE. 720 * 721 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed; 722 * else an error code, usually 723 * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add. 724 */ checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp)725 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp); 726 727 /** 728 * Check permissions when adding a window. 729 * 730 * @param attrs The window's LayoutParams. 731 * 732 * @return True if the window may only be shown to the current user, false if the window can 733 * be shown on all users' windows. 734 */ checkShowToOwnerOnly(WindowManager.LayoutParams attrs)735 public boolean checkShowToOwnerOnly(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 Manifest.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 // Type is deprecated for non-system apps. For system apps, this type should be 833 // in a higher layer than TYPE_APPLICATION_OVERLAY. 834 return canAddInternalSystemWindow ? 13 : 10; 835 case TYPE_APPLICATION_OVERLAY: 836 return 12; 837 case TYPE_DREAM: 838 // used for Dreams (screensavers with TYPE_DREAM windows) 839 return 14; 840 case TYPE_INPUT_METHOD: 841 // on-screen keyboards and other such input method user interfaces go here. 842 return 15; 843 case TYPE_INPUT_METHOD_DIALOG: 844 // on-screen keyboards and other such input method user interfaces go here. 845 return 16; 846 case TYPE_STATUS_BAR: 847 return 17; 848 case TYPE_STATUS_BAR_PANEL: 849 return 18; 850 case TYPE_STATUS_BAR_SUB_PANEL: 851 return 19; 852 case TYPE_KEYGUARD_DIALOG: 853 return 20; 854 case TYPE_VOLUME_OVERLAY: 855 // the on-screen volume indicator and controller shown when the user 856 // changes the device volume 857 return 21; 858 case TYPE_SYSTEM_OVERLAY: 859 // the on-screen volume indicator and controller shown when the user 860 // changes the device volume 861 return canAddInternalSystemWindow ? 22 : 11; 862 case TYPE_NAVIGATION_BAR: 863 // the navigation bar, if available, shows atop most things 864 return 23; 865 case TYPE_NAVIGATION_BAR_PANEL: 866 // some panels (e.g. search) need to show on top of the navigation bar 867 return 24; 868 case TYPE_SCREENSHOT: 869 // screenshot selection layer shouldn't go above system error, but it should cover 870 // navigation bars at the very least. 871 return 25; 872 case TYPE_SYSTEM_ERROR: 873 // system-level error dialogs 874 return canAddInternalSystemWindow ? 26 : 10; 875 case TYPE_MAGNIFICATION_OVERLAY: 876 // used to highlight the magnified portion of a display 877 return 27; 878 case TYPE_DISPLAY_OVERLAY: 879 // used to simulate secondary display devices 880 return 28; 881 case TYPE_DRAG: 882 // the drag layer: input for drag-and-drop is associated with this window, 883 // which sits above all other focusable windows 884 return 29; 885 case TYPE_ACCESSIBILITY_OVERLAY: 886 // overlay put by accessibility services to intercept user interaction 887 return 30; 888 case TYPE_SECURE_SYSTEM_OVERLAY: 889 return 31; 890 case TYPE_BOOT_PROGRESS: 891 return 32; 892 case TYPE_POINTER: 893 // the (mouse) pointer layer 894 return 33; 895 default: 896 Slog.e("WindowManager", "Unknown window type: " + type); 897 return APPLICATION_LAYER; 898 } 899 } 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 */ getSubWindowLayerFromTypeLw(int type)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 */ getMaxWallpaperLayer()932 public int getMaxWallpaperLayer(); 933 934 /** 935 * Return whether the given window can become the Keyguard window. Typically returns true for 936 * the StatusBar. 937 */ isKeyguardHostWindow(WindowManager.LayoutParams attrs)938 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs); 939 940 /** 941 * @return whether {@param win} can be hidden by Keyguard 942 */ canBeHiddenByKeyguardLw(WindowState win)943 public boolean canBeHiddenByKeyguardLw(WindowState win); 944 945 /** 946 * Called when the system would like to show a UI to indicate that an 947 * application is starting. You can use this to add a 948 * APPLICATION_STARTING_TYPE window with the given appToken to the window 949 * manager (using the normal window manager APIs) that will be shown until 950 * the application displays its own window. This is called without the 951 * window manager locked so that you can call back into it. 952 * 953 * @param appToken Token of the application being started. 954 * @param packageName The name of the application package being started. 955 * @param theme Resource defining the application's overall visual theme. 956 * @param nonLocalizedLabel The default title label of the application if 957 * no data is found in the resource. 958 * @param labelRes The resource ID the application would like to use as its name. 959 * @param icon The resource ID the application would like to use as its icon. 960 * @param windowFlags Window layout flags. 961 * @param overrideConfig override configuration to consider when generating 962 * context to for resources. 963 * @param displayId Id of the display to show the splash screen at. 964 * 965 * @return The starting surface. 966 * 967 */ addSplashScreen(IBinder appToken, String packageName, int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, Configuration overrideConfig, int displayId)968 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme, 969 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, 970 int logo, int windowFlags, Configuration overrideConfig, int displayId); 971 972 /** 973 * Set or clear a window which can behave as the keyguard. 974 * 975 * @param win The window which can behave as the keyguard. 976 */ setKeyguardCandidateLw(@ullable WindowState win)977 void setKeyguardCandidateLw(@Nullable WindowState win); 978 979 /** 980 * Create and return an animation to re-display a window that was force hidden by Keyguard. 981 */ createHiddenByKeyguardExit(boolean onWallpaper, boolean goingToNotificationShade)982 public Animation createHiddenByKeyguardExit(boolean onWallpaper, 983 boolean goingToNotificationShade); 984 985 /** 986 * Create and return an animation to let the wallpaper disappear after being shown behind 987 * Keyguard. 988 */ createKeyguardWallpaperExit(boolean goingToNotificationShade)989 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade); 990 991 /** 992 * Called from the input reader thread before a key is enqueued. 993 * 994 * <p>There are some actions that need to be handled here because they 995 * affect the power state of the device, for example, the power keys. 996 * Generally, it's best to keep as little as possible in the queue thread 997 * because it's the most fragile. 998 * @param event The key event. 999 * @param policyFlags The policy flags associated with the key. 1000 * 1001 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 1002 */ interceptKeyBeforeQueueing(KeyEvent event, int policyFlags)1003 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags); 1004 1005 /** 1006 * Called from the input reader thread before a motion is enqueued when the device is in a 1007 * non-interactive state. 1008 * 1009 * <p>There are some actions that need to be handled here because they 1010 * affect the power state of the device, for example, waking on motions. 1011 * Generally, it's best to keep as little as possible in the queue thread 1012 * because it's the most fragile. 1013 * @param displayId The display ID of the motion event. 1014 * @param policyFlags The policy flags associated with the motion. 1015 * 1016 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 1017 */ interceptMotionBeforeQueueingNonInteractive(int displayId, long whenNanos, int policyFlags)1018 int interceptMotionBeforeQueueingNonInteractive(int displayId, long whenNanos, 1019 int policyFlags); 1020 1021 /** 1022 * Called from the input dispatcher thread before a key is dispatched to a window. 1023 * 1024 * <p>Allows you to define 1025 * behavior for keys that can not be overridden by applications. 1026 * This method is called from the input thread, with no locks held. 1027 * 1028 * @param win The window that currently has focus. This is where the key 1029 * event will normally go. 1030 * @param event The key event. 1031 * @param policyFlags The policy flags associated with the key. 1032 * @return 0 if the key should be dispatched immediately, -1 if the key should 1033 * not be dispatched ever, or a positive value indicating the number of 1034 * milliseconds by which the key dispatch should be delayed before trying 1035 * again. 1036 */ interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags)1037 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags); 1038 1039 /** 1040 * Called from the input dispatcher thread when an application did not handle 1041 * a key that was dispatched to it. 1042 * 1043 * <p>Allows you to define default global behavior for keys that were not handled 1044 * by applications. This method is called from the input thread, with no locks held. 1045 * 1046 * @param win The window that currently has focus. This is where the key 1047 * event will normally go. 1048 * @param event The key event. 1049 * @param policyFlags The policy flags associated with the key. 1050 * @return Returns an alternate key event to redispatch as a fallback, or null to give up. 1051 * The caller is responsible for recycling the key event. 1052 */ dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags)1053 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags); 1054 1055 /** 1056 * Called when the top focused display is changed. 1057 * 1058 * @param displayId The ID of the top focused display. 1059 */ setTopFocusedDisplay(int displayId)1060 void setTopFocusedDisplay(int displayId); 1061 1062 /** 1063 * Apply the keyguard policy to a specific window. 1064 * 1065 * @param win The window to apply the keyguard policy. 1066 * @param imeTarget The current IME target window. 1067 */ applyKeyguardPolicyLw(WindowState win, WindowState imeTarget)1068 void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget); 1069 1070 /** 1071 * Called when the state of allow-lockscreen-when-on of the display is changed. See 1072 * {@link WindowManager.LayoutParams#FLAG_ALLOW_LOCK_WHILE_SCREEN_ON} 1073 * 1074 * @param displayId The ID of the display. 1075 * @param allow Whether the display allows showing lockscreen when it is on. 1076 */ setAllowLockscreenWhenOn(int displayId, boolean allow)1077 void setAllowLockscreenWhenOn(int displayId, boolean allow); 1078 1079 /** 1080 * Called when the device has started waking up. 1081 */ startedWakingUp(@nReason int reason)1082 void startedWakingUp(@OnReason int reason); 1083 1084 /** 1085 * Called when the device has finished waking up. 1086 */ finishedWakingUp(@nReason int reason)1087 void finishedWakingUp(@OnReason int reason); 1088 1089 /** 1090 * Called when the device has started going to sleep. 1091 * 1092 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN}, 1093 * or {@link #OFF_BECAUSE_OF_TIMEOUT}. 1094 */ startedGoingToSleep(int why)1095 public void startedGoingToSleep(int why); 1096 1097 /** 1098 * Called when the device has finished going to sleep. 1099 * 1100 * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN}, 1101 * or {@link #OFF_BECAUSE_OF_TIMEOUT}. 1102 */ finishedGoingToSleep(int why)1103 public void finishedGoingToSleep(int why); 1104 1105 /** 1106 * Called when the device is about to turn on the screen to show content. 1107 * When waking up, this method will be called once after the call to wakingUp(). 1108 * When dozing, the method will be called sometime after the call to goingToSleep() and 1109 * may be called repeatedly in the case where the screen is pulsing on and off. 1110 * 1111 * Must call back on the listener to tell it when the higher-level system 1112 * is ready for the screen to go on (i.e. the lock screen is shown). 1113 */ screenTurningOn(ScreenOnListener screenOnListener)1114 public void screenTurningOn(ScreenOnListener screenOnListener); 1115 1116 /** 1117 * Called when the device has actually turned on the screen, i.e. the display power state has 1118 * been set to ON and the screen is unblocked. 1119 */ screenTurnedOn()1120 public void screenTurnedOn(); 1121 1122 /** 1123 * Called when the display would like to be turned off. This gives policy a chance to do some 1124 * things before the display power state is actually changed to off. 1125 * 1126 * @param screenOffListener Must be called to tell that the display power state can actually be 1127 * changed now after policy has done its work. 1128 */ screenTurningOff(ScreenOffListener screenOffListener)1129 public void screenTurningOff(ScreenOffListener screenOffListener); 1130 1131 /** 1132 * Called when the device has turned the screen off. 1133 */ screenTurnedOff()1134 public void screenTurnedOff(); 1135 1136 public interface ScreenOnListener { onScreenOn()1137 void onScreenOn(); 1138 } 1139 1140 /** 1141 * See {@link #screenTurnedOff} 1142 */ 1143 public interface ScreenOffListener { onScreenOff()1144 void onScreenOff(); 1145 } 1146 1147 /** 1148 * Return whether the default display is on and not blocked by a black surface. 1149 */ isScreenOn()1150 public boolean isScreenOn(); 1151 1152 /** 1153 * @return whether the device is currently allowed to animate. 1154 * 1155 * Note: this can be true even if it is not appropriate to animate for reasons that are outside 1156 * of the policy's authority. 1157 */ okToAnimate()1158 boolean okToAnimate(); 1159 1160 /** 1161 * Tell the policy that the lid switch has changed state. 1162 * @param whenNanos The time when the change occurred in uptime nanoseconds. 1163 * @param lidOpen True if the lid is now open. 1164 */ notifyLidSwitchChanged(long whenNanos, boolean lidOpen)1165 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); 1166 1167 /** 1168 * Tell the policy that the camera lens has been covered or uncovered. 1169 * @param whenNanos The time when the change occurred in uptime nanoseconds. 1170 * @param lensCovered True if the lens is covered. 1171 */ notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered)1172 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered); 1173 1174 /** 1175 * Tell the policy if anyone is requesting that keyguard not come on. 1176 * 1177 * @param enabled Whether keyguard can be on or not. does not actually 1178 * turn it on, unless it was previously disabled with this function. 1179 * 1180 * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard() 1181 * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard() 1182 */ 1183 @SuppressWarnings("javadoc") enableKeyguard(boolean enabled)1184 public void enableKeyguard(boolean enabled); 1185 1186 /** 1187 * Callback used by {@link #exitKeyguardSecurely} 1188 */ 1189 interface OnKeyguardExitResult { onKeyguardExitResult(boolean success)1190 void onKeyguardExitResult(boolean success); 1191 } 1192 1193 /** 1194 * Tell the policy if anyone is requesting the keyguard to exit securely 1195 * (this would be called after the keyguard was disabled) 1196 * @param callback Callback to send the result back. 1197 * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult) 1198 */ 1199 @SuppressWarnings("javadoc") exitKeyguardSecurely(OnKeyguardExitResult callback)1200 void exitKeyguardSecurely(OnKeyguardExitResult callback); 1201 1202 /** 1203 * isKeyguardLocked 1204 * 1205 * Return whether the keyguard is currently locked. 1206 * 1207 * @return true if in keyguard is locked. 1208 */ isKeyguardLocked()1209 public boolean isKeyguardLocked(); 1210 1211 /** 1212 * isKeyguardSecure 1213 * 1214 * Return whether the keyguard requires a password to unlock. 1215 * @param userId 1216 * 1217 * @return true if in keyguard is secure. 1218 */ isKeyguardSecure(int userId)1219 public boolean isKeyguardSecure(int userId); 1220 1221 /** 1222 * Return whether the keyguard is currently occluded. 1223 * 1224 * @return true if in keyguard is occluded, false otherwise 1225 */ isKeyguardOccluded()1226 public boolean isKeyguardOccluded(); 1227 1228 /** 1229 * @return true if in keyguard is on and not occluded. 1230 */ isKeyguardShowingAndNotOccluded()1231 public boolean isKeyguardShowingAndNotOccluded(); 1232 1233 /** 1234 * @return whether Keyguard is in trusted state and can be dismissed without credentials 1235 */ isKeyguardTrustedLw()1236 public boolean isKeyguardTrustedLw(); 1237 1238 /** 1239 * inKeyguardRestrictedKeyInputMode 1240 * 1241 * If keyguard screen is showing or in restricted key input mode (i.e. in 1242 * keyguard password emergency screen). When in such mode, certain keys, 1243 * such as the Home key and the right soft keys, don't work. 1244 * 1245 * @return true if in keyguard restricted input mode. 1246 */ inKeyguardRestrictedKeyInputMode()1247 public boolean inKeyguardRestrictedKeyInputMode(); 1248 1249 /** 1250 * Ask the policy to dismiss the keyguard, if it is currently shown. 1251 * 1252 * @param callback Callback to be informed about the result. 1253 * @param message A message that should be displayed in the keyguard. 1254 */ dismissKeyguardLw(@ullable IKeyguardDismissCallback callback, CharSequence message)1255 public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback, 1256 CharSequence message); 1257 1258 /** 1259 * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method 1260 * returns true as soon as we know that Keyguard is disabled. 1261 * 1262 * @return true if the keyguard has drawn. 1263 */ isKeyguardDrawnLw()1264 public boolean isKeyguardDrawnLw(); 1265 1266 /** 1267 * Called when the system is mostly done booting to set whether 1268 * the system should go into safe mode. 1269 */ setSafeMode(boolean safeMode)1270 public void setSafeMode(boolean safeMode); 1271 1272 /** 1273 * Called when the system is mostly done booting. 1274 */ systemReady()1275 public void systemReady(); 1276 1277 /** 1278 * Called when the system is done booting to the point where the 1279 * user can start interacting with it. 1280 */ systemBooted()1281 public void systemBooted(); 1282 1283 /** 1284 * Show boot time message to the user. 1285 */ showBootMessage(final CharSequence msg, final boolean always)1286 public void showBootMessage(final CharSequence msg, final boolean always); 1287 1288 /** 1289 * Hide the UI for showing boot messages, never to be displayed again. 1290 */ hideBootMessages()1291 public void hideBootMessages(); 1292 1293 /** 1294 * Called when userActivity is signalled in the power manager. 1295 * This is safe to call from any thread, with any window manager locks held or not. 1296 */ userActivity()1297 public void userActivity(); 1298 1299 /** 1300 * Called when we have finished booting and can now display the home 1301 * screen to the user. This will happen after systemReady(), and at 1302 * this point the display is active. 1303 */ enableScreenAfterBoot()1304 public void enableScreenAfterBoot(); 1305 1306 /** 1307 * Call from application to perform haptic feedback on its window. 1308 */ performHapticFeedback(int uid, String packageName, int effectId, boolean always, String reason)1309 public boolean performHapticFeedback(int uid, String packageName, int effectId, 1310 boolean always, String reason); 1311 1312 /** 1313 * Called when we have started keeping the screen on because a window 1314 * requesting this has become visible. 1315 */ keepScreenOnStartedLw()1316 public void keepScreenOnStartedLw(); 1317 1318 /** 1319 * Called when we have stopped keeping the screen on because the last window 1320 * requesting this is no longer visible. 1321 */ keepScreenOnStoppedLw()1322 public void keepScreenOnStoppedLw(); 1323 1324 /** 1325 * Called by System UI to notify of changes to the visibility of Recents. 1326 */ setRecentsVisibilityLw(boolean visible)1327 public void setRecentsVisibilityLw(boolean visible); 1328 1329 /** 1330 * Called by System UI to notify of changes to the visibility of PIP. 1331 */ setPipVisibilityLw(boolean visible)1332 void setPipVisibilityLw(boolean visible); 1333 1334 /** 1335 * Called by System UI to enable or disable haptic feedback on the navigation bar buttons. 1336 */ setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled)1337 void setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled); 1338 1339 /** 1340 * Specifies whether there is an on-screen navigation bar separate from the status bar. 1341 */ hasNavigationBar()1342 public boolean hasNavigationBar(); 1343 1344 /** 1345 * Lock the device now. 1346 */ lockNow(Bundle options)1347 public void lockNow(Bundle options); 1348 1349 /** 1350 * An internal callback (from InputMethodManagerService) to notify a state change regarding 1351 * whether the back key should dismiss the software keyboard (IME) or not. 1352 * 1353 * @param newValue {@code true} if the software keyboard is shown and the back key is expected 1354 * to dismiss the software keyboard. 1355 * @hide 1356 */ setDismissImeOnBackKeyPressed(boolean newValue)1357 default void setDismissImeOnBackKeyPressed(boolean newValue) { 1358 // Default implementation does nothing. 1359 } 1360 1361 /** 1362 * Show the recents task list app. 1363 * @hide 1364 */ showRecentApps()1365 public void showRecentApps(); 1366 1367 /** 1368 * Show the global actions dialog. 1369 * @hide 1370 */ showGlobalActions()1371 public void showGlobalActions(); 1372 1373 /** 1374 * Returns whether the user setup is complete. 1375 */ isUserSetupComplete()1376 boolean isUserSetupComplete(); 1377 1378 /** 1379 * Returns the current UI mode. 1380 */ getUiMode()1381 int getUiMode(); 1382 1383 /** 1384 * Called when the current user changes. Guaranteed to be called before the broadcast 1385 * of the new user id is made to all listeners. 1386 * 1387 * @param newUserId The id of the incoming user. 1388 */ setCurrentUserLw(int newUserId)1389 public void setCurrentUserLw(int newUserId); 1390 1391 /** 1392 * For a given user-switch operation, this will be called once with switching=true before the 1393 * user-switch and once with switching=false afterwards (or if the user-switch was cancelled). 1394 * This gives the policy a chance to alter its behavior for the duration of a user-switch. 1395 * 1396 * @param switching true if a user-switch is in progress 1397 */ setSwitchingUser(boolean switching)1398 void setSwitchingUser(boolean switching); 1399 1400 /** 1401 * Print the WindowManagerPolicy's state into the given stream. 1402 * 1403 * @param prefix Text to print at the front of each line. 1404 * @param writer The PrintWriter to which you should dump your state. This will be 1405 * closed for you after you return. 1406 * @param args additional arguments to the dump request. 1407 */ dump(String prefix, PrintWriter writer, String[] args)1408 public void dump(String prefix, PrintWriter writer, String[] args); 1409 1410 /** 1411 * Write the WindowManagerPolicy's state into the protocol buffer. 1412 * The message is described in {@link com.android.server.wm.WindowManagerPolicyProto} 1413 * 1414 * @param proto The protocol buffer output stream to write to. 1415 */ writeToProto(ProtoOutputStream proto, long fieldId)1416 void writeToProto(ProtoOutputStream proto, long fieldId); 1417 1418 /** 1419 * Returns whether a given window type is considered a top level one. 1420 * A top level window does not have a container, i.e. attached window, 1421 * or if it has a container it is laid out as a top-level window, not 1422 * as a child of its container. 1423 * 1424 * @param windowType The window type. 1425 * @return True if the window is a top level one. 1426 */ isTopLevelWindow(int windowType)1427 public boolean isTopLevelWindow(int windowType); 1428 1429 /** 1430 * Notifies the keyguard to start fading out. 1431 * 1432 * @param startTime the start time of the animation in uptime milliseconds 1433 * @param fadeoutDuration the duration of the exit animation, in milliseconds 1434 */ startKeyguardExitAnimation(long startTime, long fadeoutDuration)1435 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration); 1436 1437 /** 1438 * Called when System UI has been started. 1439 */ onSystemUiStarted()1440 void onSystemUiStarted(); 1441 1442 /** 1443 * Checks whether the policy is ready for dismissing the boot animation and completing the boot. 1444 * 1445 * @return true if ready; false otherwise. 1446 */ canDismissBootAnimation()1447 boolean canDismissBootAnimation(); 1448 1449 /** 1450 * Convert the user rotation mode to a human readable format. 1451 */ userRotationModeToString(int mode)1452 static String userRotationModeToString(int mode) { 1453 switch(mode) { 1454 case USER_ROTATION_FREE: 1455 return "USER_ROTATION_FREE"; 1456 case USER_ROTATION_LOCKED: 1457 return "USER_ROTATION_LOCKED"; 1458 default: 1459 return Integer.toString(mode); 1460 } 1461 } 1462 1463 /** 1464 * Requests that the WindowManager sends 1465 * WindowManagerPolicyConstants#ACTION_USER_ACTIVITY_NOTIFICATION on the next user activity. 1466 */ requestUserActivityNotification()1467 public void requestUserActivityNotification(); 1468 1469 /** 1470 * Registers an IDisplayFoldListener. 1471 */ registerDisplayFoldListener(IDisplayFoldListener listener)1472 default void registerDisplayFoldListener(IDisplayFoldListener listener) {} 1473 1474 /** 1475 * Unregisters an IDisplayFoldListener. 1476 */ unregisterDisplayFoldListener(IDisplayFoldListener listener)1477 default void unregisterDisplayFoldListener(IDisplayFoldListener listener) {} 1478 1479 /** 1480 * Overrides the folded area. 1481 * 1482 * @param area the overriding folded area or an empty {@code Rect} to clear the override. 1483 */ setOverrideFoldedArea(@onNull Rect area)1484 default void setOverrideFoldedArea(@NonNull Rect area) {} 1485 1486 /** 1487 * Get the display folded area. 1488 */ getFoldedArea()1489 default @NonNull Rect getFoldedArea() { 1490 return new Rect(); 1491 } 1492 1493 /** 1494 * A new window on default display has been focused. 1495 */ onDefaultDisplayFocusChangedLw(WindowState newFocus)1496 default void onDefaultDisplayFocusChangedLw(WindowState newFocus) {} 1497 1498 /** 1499 * Updates the flag about whether AOD is showing. 1500 * 1501 * @return whether the value was changed. 1502 */ setAodShowing(boolean aodShowing)1503 boolean setAodShowing(boolean aodShowing); 1504 } 1505