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