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_VOICE_INTERACTION; 60 import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; 61 import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; 62 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; 63 import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; 64 65 import static java.lang.annotation.RetentionPolicy.SOURCE; 66 67 import android.annotation.IntDef; 68 import android.annotation.NonNull; 69 import android.annotation.Nullable; 70 import android.companion.virtual.VirtualDevice; 71 import android.content.ComponentName; 72 import android.content.Context; 73 import android.content.res.Configuration; 74 import android.graphics.Rect; 75 import android.hardware.display.VirtualDisplay; 76 import android.os.Bundle; 77 import android.os.IBinder; 78 import android.os.PowerManager; 79 import android.os.RemoteException; 80 import android.util.Slog; 81 import android.util.proto.ProtoOutputStream; 82 import android.view.Display; 83 import android.view.IDisplayFoldListener; 84 import android.view.KeyEvent; 85 import android.view.KeyboardShortcutGroup; 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 95 import java.io.PrintWriter; 96 import java.lang.annotation.Retention; 97 import java.lang.annotation.RetentionPolicy; 98 import java.util.List; 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 * 171 * @param occluded Whether Keyguard is currently occluded or not. 172 */ onKeyguardOccludedChangedLw(boolean occluded)173 void onKeyguardOccludedChangedLw(boolean occluded); 174 175 /** 176 * Commit any queued changes to keyguard occlude status that had been deferred during the 177 * start of an animation or transition. 178 */ applyKeyguardOcclusionChange()179 int applyKeyguardOcclusionChange(); 180 181 /** 182 * Shows the keyguard immediately if not already shown. 183 * Does NOT immediately request the device to lock. 184 */ showDismissibleKeyguard()185 void showDismissibleKeyguard(); 186 187 /** 188 * Interface to the Window Manager state associated with a particular 189 * window. You can hold on to an instance of this interface from the call 190 * to prepareAddWindow() until removeWindow(). 191 */ 192 public interface WindowState { 193 /** 194 * Return the package name of the app that owns this window. 195 */ getOwningPackage()196 String getOwningPackage(); 197 198 /** 199 * Retrieve the type of the top-level window. 200 * 201 * @return the base type of the parent window if attached or its own type otherwise 202 */ getBaseType()203 public int getBaseType(); 204 205 /** 206 * Return true if this window (or a window it is attached to, but not 207 * considering its app token) is currently animating. 208 */ isAnimatingLw()209 boolean isAnimatingLw(); 210 211 /** 212 * Returns true if the window owner can add internal system windows. 213 * That is, they have {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}. 214 */ canAddInternalSystemWindow()215 default boolean canAddInternalSystemWindow() { 216 return false; 217 } 218 219 /** @return true if the window can show over keyguard. */ canShowWhenLocked()220 boolean canShowWhenLocked(); 221 } 222 223 /** 224 * Interface for calling back in to the window manager that is private 225 * between it and the policy. 226 */ 227 public interface WindowManagerFuncs { 228 public static final int LID_ABSENT = -1; 229 public static final int LID_CLOSED = 0; 230 public static final int LID_OPEN = 1; 231 232 public static final int LID_BEHAVIOR_NONE = 0; 233 public static final int LID_BEHAVIOR_SLEEP = 1; 234 public static final int LID_BEHAVIOR_LOCK = 2; 235 236 public static final int CAMERA_LENS_COVER_ABSENT = -1; 237 public static final int CAMERA_LENS_UNCOVERED = 0; 238 public static final int CAMERA_LENS_COVERED = 1; 239 240 /** 241 * Returns a code that describes the current state of the lid switch. 242 */ getLidState()243 public int getLidState(); 244 245 /** 246 * Lock the device now. 247 */ lockDeviceNow()248 public void lockDeviceNow(); 249 250 /** 251 * Returns a code that descripbes whether the camera lens is covered or not. 252 */ getCameraLensCoverState()253 public int getCameraLensCoverState(); 254 shutdown(boolean confirm)255 public void shutdown(boolean confirm); reboot(boolean confirm)256 public void reboot(boolean confirm); rebootSafeMode(boolean confirm)257 public void rebootSafeMode(boolean confirm); 258 259 /** 260 * Return the window manager lock needed to correctly call "Lw" methods. 261 */ getWindowManagerLock()262 public Object getWindowManagerLock(); 263 264 /** Register a system listener for touch events */ registerPointerEventListener(PointerEventListener listener, int displayId)265 void registerPointerEventListener(PointerEventListener listener, int displayId); 266 267 /** Unregister a system listener for touch events */ unregisterPointerEventListener(PointerEventListener listener, int displayId)268 void unregisterPointerEventListener(PointerEventListener listener, int displayId); 269 270 /** 271 * Notifies window manager that {@link #isKeyguardTrustedLw} has changed. 272 */ notifyKeyguardTrustedChanged()273 void notifyKeyguardTrustedChanged(); 274 275 /** 276 * Notifies the window manager that screen is being turned off. 277 * 278 * @param displayId the ID of the display which is turning off 279 * @param listener callback to call when display can be turned off 280 */ screenTurningOff(int displayId, ScreenOffListener listener)281 void screenTurningOff(int displayId, ScreenOffListener listener); 282 283 /** 284 * Convert the lid state to a human readable format. 285 */ lidStateToString(int lid)286 static String lidStateToString(int lid) { 287 switch (lid) { 288 case LID_ABSENT: 289 return "LID_ABSENT"; 290 case LID_CLOSED: 291 return "LID_CLOSED"; 292 case LID_OPEN: 293 return "LID_OPEN"; 294 default: 295 return Integer.toString(lid); 296 } 297 } 298 299 /** 300 * Convert the camera lens state to a human readable format. 301 */ cameraLensStateToString(int lens)302 static String cameraLensStateToString(int lens) { 303 switch (lens) { 304 case CAMERA_LENS_COVER_ABSENT: 305 return "CAMERA_LENS_COVER_ABSENT"; 306 case CAMERA_LENS_UNCOVERED: 307 return "CAMERA_LENS_UNCOVERED"; 308 case CAMERA_LENS_COVERED: 309 return "CAMERA_LENS_COVERED"; 310 default: 311 return Integer.toString(lens); 312 } 313 } 314 315 /** 316 * The keyguard showing state has changed 317 */ onKeyguardShowingAndNotOccludedChanged()318 void onKeyguardShowingAndNotOccludedChanged(); 319 320 /** 321 * Notifies window manager that power key is being pressed. 322 */ onPowerKeyDown(boolean isScreenOn)323 void onPowerKeyDown(boolean isScreenOn); 324 325 /** 326 * Notifies window manager that user is switched. 327 */ onUserSwitched()328 void onUserSwitched(); 329 330 /** 331 * Hint to window manager that the user is interacting with a display that should be treated 332 * as the top display. 333 * 334 * Calling this method does not guarantee that the display will be moved to top. The window 335 * manager will make the final decision whether or not to move the display. 336 */ moveDisplayToTopIfAllowed(int displayId)337 void moveDisplayToTopIfAllowed(int displayId); 338 339 /** 340 * Enables the screen if all conditions are met. 341 */ enableScreenIfNeeded()342 void enableScreenIfNeeded(); 343 344 /** 345 * Updates the current screen rotation based on the current state of the world. 346 * 347 * @param alwaysSendConfiguration Flag to force a new configuration to be evaluated. 348 * This can be used when there are other parameters in 349 * configuration that are changing. 350 * @param forceRelayout If true, the window manager will always do a relayout of its 351 * windows even if the rotation hasn't changed. 352 */ updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout)353 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout); 354 355 /** 356 * Invoked when a screenshot is taken of the given display to notify registered listeners. 357 */ notifyScreenshotListeners(int displayId)358 List<ComponentName> notifyScreenshotListeners(int displayId); 359 360 /** 361 * Returns whether the given UID is the owner of a virtual device, which the given display 362 * belongs to. 363 */ isCallerVirtualDeviceOwner(int displayId, int callingUid)364 boolean isCallerVirtualDeviceOwner(int displayId, int callingUid); 365 366 /** 367 * Returns whether the display with the given ID is trusted. 368 */ isDisplayTrusted(int displayId)369 boolean isDisplayTrusted(int displayId); 370 } 371 372 /** 373 * Interface to get public information of a display content. 374 */ 375 public interface DisplayContentInfo { getDisplayRotation()376 DisplayRotation getDisplayRotation(); getDisplay()377 Display getDisplay(); 378 } 379 380 /** Window has been added to the screen. */ 381 public static final int TRANSIT_ENTER = 1; 382 /** Window has been removed from the screen. */ 383 public static final int TRANSIT_EXIT = 2; 384 /** Window has been made visible. */ 385 public static final int TRANSIT_SHOW = 3; 386 /** Window has been made invisible. 387 * TODO: Consider removal as this is unused. */ 388 public static final int TRANSIT_HIDE = 4; 389 /** The "application starting" preview window is no longer needed, and will 390 * animate away to show the real window. */ 391 public static final int TRANSIT_PREVIEW_DONE = 5; 392 393 // NOTE: screen off reasons are in order of significance, with more 394 // important ones lower than less important ones. 395 396 /** @hide */ 397 @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED}) 398 @Retention(RetentionPolicy.SOURCE) 399 public @interface UserRotationMode {} 400 401 /** When not otherwise specified by the activity's screenOrientation, rotation should be 402 * determined by the system (that is, using sensors). */ 403 public final int USER_ROTATION_FREE = 0; 404 /** When not otherwise specified by the activity's screenOrientation, rotation is set by 405 * the user. */ 406 public final int USER_ROTATION_LOCKED = 1; 407 408 /** 409 * Set the default display content to provide basic functions for the policy. 410 */ setDefaultDisplay(DisplayContentInfo displayContentInfo)411 public void setDefaultDisplay(DisplayContentInfo displayContentInfo); 412 413 /** 414 * Perform initialization of the policy. 415 * 416 * @param context The system context we are running in. 417 */ init(Context context, WindowManagerFuncs windowManagerFuncs)418 void init(Context context, WindowManagerFuncs windowManagerFuncs); 419 420 /** 421 * Check permissions when adding a window. 422 * 423 * @param type The window type 424 * @param isRoundedCornerOverlay {@code true} to indicate the adding window is 425 * round corner overlay. 426 * @param packageName package name 427 * @param outAppOp First element will be filled with the app op corresponding to 428 * this window, or OP_NONE. 429 * @param displayId The display on which this window is being added. 430 * 431 * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed; 432 * else an error code, usually 433 * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add. 434 * 435 * @see WindowManager.LayoutParams#PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY 436 */ checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName, int[] outAppOp, int displayId)437 int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName, 438 int[] outAppOp, int displayId); 439 440 /** 441 * After the window manager has computed the current configuration based 442 * on its knowledge of the display and input devices, it gives the policy 443 * a chance to adjust the information contained in it. If you want to 444 * leave it as-is, simply do nothing. 445 * 446 * <p>This method may be called by any thread in the window manager, but 447 * no internal locks in the window manager will be held. 448 * 449 * @param config The Configuration being computed, for you to change as 450 * desired. 451 * @param keyboardPresence Flags that indicate whether internal or external 452 * keyboards are present. 453 * @param navigationPresence Flags that indicate whether internal or external 454 * navigation devices are present. 455 */ adjustConfigurationLw(Configuration config, int keyboardPresence, int navigationPresence)456 public void adjustConfigurationLw(Configuration config, int keyboardPresence, 457 int navigationPresence); 458 459 /** 460 * Returns the layer assignment for the window state. Allows you to control how different 461 * kinds of windows are ordered on-screen. 462 * 463 * @param win The window state 464 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 465 */ getWindowLayerLw(WindowState win)466 default int getWindowLayerLw(WindowState win) { 467 return getWindowLayerFromTypeLw(win.getBaseType(), win.canAddInternalSystemWindow()); 468 } 469 470 /** 471 * Returns the layer assignment for the window type. Allows you to control how different 472 * kinds of windows are ordered on-screen. 473 * 474 * @param type The type of window being assigned. 475 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 476 */ getWindowLayerFromTypeLw(int type)477 default int getWindowLayerFromTypeLw(int type) { 478 if (isSystemAlertWindowType(type)) { 479 throw new IllegalArgumentException("Use getWindowLayerFromTypeLw() or" 480 + " getWindowLayerLw() for alert window types"); 481 } 482 return getWindowLayerFromTypeLw(type, false /* canAddInternalSystemWindow */); 483 } 484 485 /** 486 * Returns the layer assignment for the window type. Allows you to control how different 487 * kinds of windows are ordered on-screen. 488 * 489 * @param type The type of window being assigned. 490 * @param canAddInternalSystemWindow If the owner window associated with the type we are 491 * evaluating can add internal system windows. I.e they have 492 * {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}. If true, alert window 493 * types {@link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)} 494 * can be assigned layers greater than the layer for 495 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} Else, their 496 * layers would be lesser. 497 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 498 */ getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow)499 default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow) { 500 return getWindowLayerFromTypeLw(type, canAddInternalSystemWindow, 501 false /* roundedCornerOverlay */); 502 } 503 504 /** 505 * Returns the layer assignment for the window type. Allows you to control how different 506 * kinds of windows are ordered on-screen. 507 * 508 * @param type The type of window being assigned. 509 * @param canAddInternalSystemWindow If the owner window associated with the type we are 510 * evaluating can add internal system windows. I.e they have 511 * {@link Manifest.permission#INTERNAL_SYSTEM_WINDOW}. If true, alert window 512 * types {@link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)} 513 * can be assigned layers greater than the layer for 514 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} Else, their 515 * layers would be lesser. 516 * @param roundedCornerOverlay {#code true} to indicate that the owner window is rounded corner 517 * overlay. 518 * @return int An arbitrary integer used to order windows, with lower numbers below higher ones. 519 */ getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow, boolean roundedCornerOverlay)520 default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow, 521 boolean roundedCornerOverlay) { 522 // Always put the rounded corner layer to the top most. 523 if (roundedCornerOverlay && canAddInternalSystemWindow) { 524 return getMaxWindowLayer(); 525 } 526 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { 527 return APPLICATION_LAYER; 528 } 529 530 switch (type) { 531 case TYPE_WALLPAPER: 532 // wallpaper is at the bottom, though the window manager may move it. 533 return 1; 534 case TYPE_PRESENTATION: 535 case TYPE_PRIVATE_PRESENTATION: 536 case TYPE_DOCK_DIVIDER: 537 case TYPE_QS_DIALOG: 538 case TYPE_PHONE: 539 return 3; 540 case TYPE_SEARCH_BAR: 541 return 4; 542 case TYPE_INPUT_CONSUMER: 543 return 5; 544 case TYPE_SYSTEM_DIALOG: 545 return 6; 546 case TYPE_TOAST: 547 // toasts and the plugged-in battery thing 548 return 7; 549 case TYPE_PRIORITY_PHONE: 550 // SIM errors and unlock. Not sure if this really should be in a high layer. 551 return 8; 552 case TYPE_SYSTEM_ALERT: 553 // like the ANR / app crashed dialogs 554 // Type is deprecated for non-system apps. For system apps, this type should be 555 // in a higher layer than TYPE_APPLICATION_OVERLAY. 556 return canAddInternalSystemWindow ? 12 : 9; 557 case TYPE_APPLICATION_OVERLAY: 558 return 11; 559 case TYPE_INPUT_METHOD: 560 // on-screen keyboards and other such input method user interfaces go here. 561 return 13; 562 case TYPE_INPUT_METHOD_DIALOG: 563 // on-screen keyboards and other such input method user interfaces go here. 564 return 14; 565 case TYPE_STATUS_BAR: 566 return 15; 567 case TYPE_STATUS_BAR_ADDITIONAL: 568 return 16; 569 case TYPE_NOTIFICATION_SHADE: 570 return 17; 571 case TYPE_STATUS_BAR_SUB_PANEL: 572 return 18; 573 case TYPE_KEYGUARD_DIALOG: 574 return 19; 575 case TYPE_VOICE_INTERACTION_STARTING: 576 return 20; 577 case TYPE_VOICE_INTERACTION: 578 // voice interaction layer should show above the lock screen. 579 return 21; 580 case TYPE_VOLUME_OVERLAY: 581 // the on-screen volume indicator and controller shown when the user 582 // changes the device volume 583 return 22; 584 case TYPE_SYSTEM_OVERLAY: 585 // the on-screen volume indicator and controller shown when the user 586 // changes the device volume 587 return canAddInternalSystemWindow ? 23 : 10; 588 case TYPE_NAVIGATION_BAR: 589 // the navigation bar, if available, shows atop most things 590 return 24; 591 case TYPE_NAVIGATION_BAR_PANEL: 592 // some panels (e.g. search) need to show on top of the navigation bar 593 return 25; 594 case TYPE_SCREENSHOT: 595 // screenshot selection layer shouldn't go above system error, but it should cover 596 // navigation bars at the very least. 597 return 26; 598 case TYPE_SYSTEM_ERROR: 599 // system-level error dialogs 600 return canAddInternalSystemWindow ? 27 : 9; 601 case TYPE_MAGNIFICATION_OVERLAY: 602 // used to highlight the magnified portion of a display 603 return 28; 604 case TYPE_DISPLAY_OVERLAY: 605 // used to simulate secondary display devices 606 return 29; 607 case TYPE_DRAG: 608 // the drag layer: input for drag-and-drop is associated with this window, 609 // which sits above all other focusable windows 610 return 30; 611 case TYPE_ACCESSIBILITY_OVERLAY: 612 // overlay put by accessibility services to intercept user interaction 613 return 31; 614 case TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY: 615 return 32; 616 case TYPE_SECURE_SYSTEM_OVERLAY: 617 return 33; 618 case TYPE_BOOT_PROGRESS: 619 return 34; 620 case TYPE_POINTER: 621 // the (mouse) pointer layer 622 return 35; 623 default: 624 Slog.e("WindowManager", "Unknown window type: " + type); 625 return 3; 626 } 627 } 628 629 // TODO(b/155340867): consider to remove the logic after using pure Surface for rounded corner 630 // overlay. 631 /** 632 * Returns the max window layer. 633 * <p>Note that the max window layer should be higher that the maximum value which reported 634 * by {@link #getWindowLayerFromTypeLw(int, boolean)} to contain rounded corner overlay.</p> 635 * 636 * @see WindowManager.LayoutParams#PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY 637 */ getMaxWindowLayer()638 default int getMaxWindowLayer() { 639 return 36; 640 } 641 642 /** 643 * Return how to Z-order sub-windows in relation to the window they are attached to. 644 * Return positive to have them ordered in front, negative for behind. 645 * 646 * @param type The sub-window type code. 647 * 648 * @return int Layer in relation to the attached window, where positive is 649 * above and negative is below. 650 */ getSubWindowLayerFromTypeLw(int type)651 default int getSubWindowLayerFromTypeLw(int type) { 652 switch (type) { 653 case TYPE_APPLICATION_PANEL: 654 case TYPE_APPLICATION_ATTACHED_DIALOG: 655 return APPLICATION_PANEL_SUBLAYER; 656 case TYPE_APPLICATION_MEDIA: 657 return APPLICATION_MEDIA_SUBLAYER; 658 case TYPE_APPLICATION_MEDIA_OVERLAY: 659 return APPLICATION_MEDIA_OVERLAY_SUBLAYER; 660 case TYPE_APPLICATION_SUB_PANEL: 661 return APPLICATION_SUB_PANEL_SUBLAYER; 662 case TYPE_APPLICATION_ABOVE_SUB_PANEL: 663 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; 664 } 665 Slog.e("WindowManager", "Unknown sub-window type: " + type); 666 return 0; 667 } 668 669 /** 670 * Return whether the given window can become the Keyguard window. Typically returns true for 671 * the StatusBar. 672 */ isKeyguardHostWindow(WindowManager.LayoutParams attrs)673 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs); 674 675 /** 676 * Create and return an animation to re-display a window that was force hidden by Keyguard. 677 */ createHiddenByKeyguardExit(boolean onWallpaper, boolean goingToNotificationShade, boolean subtleAnimation)678 public Animation createHiddenByKeyguardExit(boolean onWallpaper, 679 boolean goingToNotificationShade, boolean subtleAnimation); 680 681 /** 682 * Create and return an animation to let the wallpaper disappear after being shown behind 683 * Keyguard. 684 */ createKeyguardWallpaperExit(boolean goingToNotificationShade)685 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade); 686 687 /** 688 * Called from the input reader thread before a key is enqueued. 689 * 690 * <p>There are some actions that need to be handled here because they 691 * affect the power state of the device, for example, the power keys. 692 * Generally, it's best to keep as little as possible in the queue thread 693 * because it's the most fragile. 694 * @param event The key event. 695 * @param policyFlags The policy flags associated with the key. 696 * 697 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 698 */ interceptKeyBeforeQueueing(KeyEvent event, int policyFlags)699 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags); 700 701 /** 702 * Return the set of applicaition launch keyboard shortcuts the system supports. 703 * 704 * @param deviceId The id of the {@link InputDevice} that will trigger the shortcut. 705 * 706 * @return {@link KeyboardShortcutGroup} containing the shortcuts. 707 */ getApplicationLaunchKeyboardShortcuts(int deviceId)708 KeyboardShortcutGroup getApplicationLaunchKeyboardShortcuts(int deviceId); 709 710 /** 711 * Called from the input reader thread before a motion is enqueued when the device is in a 712 * non-interactive state. 713 * 714 * <p>There are some actions that need to be handled here because they 715 * affect the power state of the device, for example, waking on motions. 716 * Generally, it's best to keep as little as possible in the queue thread 717 * because it's the most fragile. 718 * @param displayId The display ID of the motion event. 719 * @param source the {@link InputDevice} source that caused the motion. 720 * @param action the {@link MotionEvent} action for the motion. 721 * @param policyFlags The policy flags associated with the motion. 722 * 723 * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}. 724 */ interceptMotionBeforeQueueingNonInteractive(int displayId, int source, int action, long whenNanos, int policyFlags)725 int interceptMotionBeforeQueueingNonInteractive(int displayId, int source, int action, 726 long whenNanos, int policyFlags); 727 728 /** 729 * Called from the input dispatcher thread before a key is dispatched to a window. 730 * 731 * <p>Allows you to define 732 * behavior for keys that can not be overridden by applications. 733 * This method is called from the input thread, with no locks held. 734 * 735 * @param focusedToken Client window token that currently has focus. This is where the key 736 * event will normally go. 737 * @param event The key event. 738 * @param policyFlags The policy flags associated with the key. 739 * @return 0 if the key should be dispatched immediately, -1 if the key should 740 * not be dispatched ever, or a positive value indicating the number of 741 * milliseconds by which the key dispatch should be delayed before trying 742 * again. 743 */ interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event, int policyFlags)744 long interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event, int policyFlags); 745 746 /** 747 * Called from the input dispatcher thread when an application did not handle 748 * a key that was dispatched to it. 749 * 750 * <p>Allows you to define default global behavior for keys that were not handled 751 * by applications. This method is called from the input thread, with no locks held. 752 * 753 * @param focusedToken Client window token that currently has focus. This is where the key 754 * event will normally go. 755 * @param event The key event. 756 * @return true if the unhandled key is intercepted by the policy. 757 */ interceptUnhandledKey(KeyEvent event, IBinder focusedToken)758 boolean interceptUnhandledKey(KeyEvent event, IBinder focusedToken); 759 760 /** 761 * Called when the top focused display is changed. 762 * 763 * @param displayId The ID of the top focused display. 764 */ setTopFocusedDisplay(int displayId)765 void setTopFocusedDisplay(int displayId); 766 767 /** 768 * Called when the state of allow-lockscreen-when-on of the display is changed. See 769 * {@link WindowManager.LayoutParams#FLAG_ALLOW_LOCK_WHILE_SCREEN_ON} 770 * 771 * @param displayId The ID of the display. 772 * @param allow Whether the display allows showing lockscreen when it is on. 773 */ setAllowLockscreenWhenOn(int displayId, boolean allow)774 void setAllowLockscreenWhenOn(int displayId, boolean allow); 775 776 /** 777 * Called when the global wakefulness is becoming awake. 778 * 779 * @param reason One of PowerManager.WAKE_REASON_*, detailing the reason for the change. 780 */ startedWakingUpGlobal(@owerManager.WakeReason int reason)781 void startedWakingUpGlobal(@PowerManager.WakeReason int reason); 782 783 /** 784 * Called when the global wakefulness has finished becoming awake. 785 * 786 * @param reason One of PowerManager.WAKE_REASON_*, detailing the reason for the change. 787 */ finishedWakingUpGlobal(@owerManager.WakeReason int reason)788 void finishedWakingUpGlobal(@PowerManager.WakeReason int reason); 789 790 /** 791 * Called when the global wakefulness has started going to sleep. 792 * 793 * @param reason One of PowerManager.WAKE_REASON_*, detailing the reason for the change. 794 */ startedGoingToSleepGlobal(@owerManager.GoToSleepReason int reason)795 void startedGoingToSleepGlobal(@PowerManager.GoToSleepReason int reason); 796 797 /** 798 * Called when the global wakefulness has finished going to sleep. 799 * 800 * @param reason One of PowerManager.WAKE_REASON_*, detailing the reason for the change. 801 */ finishedGoingToSleepGlobal(@owerManager.GoToSleepReason int reason)802 void finishedGoingToSleepGlobal(@PowerManager.GoToSleepReason int reason); 803 804 /** 805 * Called when the device has started waking up. 806 * 807 * @param displayGroupId The id of the display group that has started waking up. This will often 808 * be {@link Display#DEFAULT_DISPLAY_GROUP}, but it is possible for other 809 * display groups to exist, for example when there is a 810 * {@link VirtualDevice} with one or more {@link VirtualDisplay}s. 811 * @param pmWakeReason One of PowerManager.WAKE_REASON_*, detailing the specific reason this 812 * display group is waking up, such as WAKE_REASON_POWER_BUTTON or 813 * WAKE_REASON_GESTURE. 814 */ startedWakingUp(int displayGroupId, @PowerManager.WakeReason int pmWakeReason)815 void startedWakingUp(int displayGroupId, @PowerManager.WakeReason int pmWakeReason); 816 817 /** 818 * Called when the device has finished waking up. 819 * 820 * @param displayGroupId The id of the display group that has finished waking. This will often 821 * be {@link Display#DEFAULT_DISPLAY_GROUP}, but it is possible for other 822 * display groups to exist, for example when there is a 823 * {@link VirtualDevice} with one or more {@link VirtualDisplay}s. 824 * @param pmWakeReason One of PowerManager.WAKE_REASON_*, detailing the specific reason this 825 * display group is waking up, such as WAKE_REASON_POWER_BUTTON or 826 * WAKE_REASON_GESTURE. 827 */ finishedWakingUp(int displayGroupId, @PowerManager.WakeReason int pmWakeReason)828 void finishedWakingUp(int displayGroupId, @PowerManager.WakeReason int pmWakeReason); 829 830 /** 831 * Called when the device has started going to sleep. 832 * 833 * @param displayGroupId The id of the display group that has started going to sleep. This 834 * will often be {@link Display#DEFAULT_DISPLAY_GROUP}, but it is 835 * possible for other display groups to exist, for example when there is a 836 * {@link VirtualDevice} with one or more {@link VirtualDisplay}s. 837 * @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the specific reason 838 * this display group is going to sleep, such as 839 * GO_TO_SLEEP_REASON_POWER_BUTTON or GO_TO_SLEEP_REASON_TIMEOUT. 840 */ startedGoingToSleep(int displayGroupId, @PowerManager.GoToSleepReason int pmSleepReason)841 void startedGoingToSleep(int displayGroupId, @PowerManager.GoToSleepReason int pmSleepReason); 842 843 /** 844 * Called when the device has finished going to sleep. 845 * 846 * @param displayGroupId The id of the display group that has finished going to sleep. This 847 * will often be {@link Display#DEFAULT_DISPLAY_GROUP}, but it is 848 * possible for other display groups to exist, for example when there is a 849 * {@link VirtualDevice} with one or more {@link VirtualDisplay}s. 850 * @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the specific reason 851 * we're going to sleep, such as GO_TO_SLEEP_REASON_POWER_BUTTON or 852 * GO_TO_SLEEP_REASON_TIMEOUT. 853 */ finishedGoingToSleep(int displayGroupId, @PowerManager.GoToSleepReason int pmSleepReason)854 void finishedGoingToSleep(int displayGroupId, @PowerManager.GoToSleepReason int pmSleepReason); 855 856 /** 857 * Called when the display is about to turn on to show content. 858 * When waking up, this method will be called once after the call to wakingUp(). 859 * When dozing, the method will be called sometime after the call to goingToSleep() and 860 * may be called repeatedly in the case where the screen is pulsing on and off. 861 * 862 * Must call back on the listener to tell it when the higher-level system 863 * is ready for the screen to go on (i.e. the lock screen is shown). 864 */ screenTurningOn(int displayId, ScreenOnListener screenOnListener)865 public void screenTurningOn(int displayId, ScreenOnListener screenOnListener); 866 867 /** 868 * Called when the display has actually turned on, i.e. the display power state has been set to 869 * ON and the screen is unblocked. 870 */ screenTurnedOn(int displayId)871 public void screenTurnedOn(int displayId); 872 873 /** 874 * Called when the display would like to be turned off. This gives policy a chance to do some 875 * things before the display power state is actually changed to off. 876 * 877 * @param screenOffListener Must be called to tell that the display power state can actually be 878 * changed now after policy has done its work. 879 */ screenTurningOff(int displayId, ScreenOffListener screenOffListener)880 public void screenTurningOff(int displayId, ScreenOffListener screenOffListener); 881 882 /** 883 * Called when the display has turned off. 884 * @param displayId The display to apply to. 885 * @param isSwappingDisplay Whether the display is swapping to another physical display. 886 */ screenTurnedOff(int displayId, boolean isSwappingDisplay)887 void screenTurnedOff(int displayId, boolean isSwappingDisplay); 888 889 public interface ScreenOnListener { onScreenOn()890 void onScreenOn(); 891 } 892 893 /** 894 * See {@link #screenTurnedOff} 895 */ 896 public interface ScreenOffListener { onScreenOff()897 void onScreenOff(); 898 } 899 900 /** Called when the physical display starts to switch, e.g. fold/unfold. */ onDisplaySwitchStart(int displayId)901 void onDisplaySwitchStart(int displayId); 902 903 /** 904 * Return whether the default display is on and not blocked by a black surface. 905 */ isScreenOn()906 public boolean isScreenOn(); 907 908 /** 909 * @param ignoreScreenOn {@code true} if screen state should be ignored. 910 * @return whether the device is currently allowed to animate. 911 * 912 * Note: this can be true even if it is not appropriate to animate for reasons that are outside 913 * of the policy's authority. 914 */ okToAnimate(boolean ignoreScreenOn)915 boolean okToAnimate(boolean ignoreScreenOn); 916 917 /** 918 * Tell the policy that the lid switch has changed state. 919 * @param whenNanos The time when the change occurred in uptime nanoseconds. 920 * @param lidOpen True if the lid is now open. 921 */ notifyLidSwitchChanged(long whenNanos, boolean lidOpen)922 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); 923 924 /** 925 * Tell the policy that the camera lens has been covered or uncovered. 926 * @param whenNanos The time when the change occurred in uptime nanoseconds. 927 * @param lensCovered True if the lens is covered. 928 */ notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered)929 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered); 930 931 /** 932 * Tell the policy if anyone is requesting that keyguard not come on. 933 * 934 * @param enabled Whether keyguard can be on or not. does not actually 935 * turn it on, unless it was previously disabled with this function. 936 * 937 * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard() 938 * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard() 939 */ 940 @SuppressWarnings("javadoc") enableKeyguard(boolean enabled)941 public void enableKeyguard(boolean enabled); 942 943 /** 944 * Callback used by {@link #exitKeyguardSecurely} 945 */ 946 interface OnKeyguardExitResult { onKeyguardExitResult(boolean success)947 void onKeyguardExitResult(boolean success); 948 } 949 950 /** 951 * Tell the policy if anyone is requesting the keyguard to exit securely 952 * (this would be called after the keyguard was disabled) 953 * @param callback Callback to send the result back. 954 * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult) 955 */ 956 @SuppressWarnings("javadoc") exitKeyguardSecurely(OnKeyguardExitResult callback)957 void exitKeyguardSecurely(OnKeyguardExitResult callback); 958 959 /** 960 * isKeyguardLocked 961 * 962 * Return whether the keyguard is currently locked. 963 * 964 * @return true if in keyguard is locked. 965 */ isKeyguardLocked()966 public boolean isKeyguardLocked(); 967 968 /** 969 * isKeyguardSecure 970 * 971 * Return whether the keyguard requires a password to unlock. 972 * @param userId 973 * 974 * @return true if in keyguard is secure. 975 */ isKeyguardSecure(int userId)976 public boolean isKeyguardSecure(int userId); 977 978 /** 979 * Return whether the keyguard is currently occluded. 980 * 981 * @return true if in keyguard is occluded, false otherwise 982 */ isKeyguardOccluded()983 public boolean isKeyguardOccluded(); 984 985 /** 986 * @return true if in keyguard is on. 987 */ isKeyguardShowing()988 boolean isKeyguardShowing(); 989 990 /** 991 * @return true if in keyguard is on and not occluded. 992 */ isKeyguardShowingAndNotOccluded()993 public boolean isKeyguardShowingAndNotOccluded(); 994 995 /** 996 * @return whether Keyguard is in trusted state and can be dismissed without credentials 997 */ isKeyguardTrustedLw()998 public boolean isKeyguardTrustedLw(); 999 1000 /** 1001 * inKeyguardRestrictedKeyInputMode 1002 * 1003 * If keyguard screen is showing or in restricted key input mode (i.e. in 1004 * keyguard password emergency screen). When in such mode, certain keys, 1005 * such as the Home key and the right soft keys, don't work. 1006 * 1007 * @return true if in keyguard restricted input mode. 1008 */ inKeyguardRestrictedKeyInputMode()1009 public boolean inKeyguardRestrictedKeyInputMode(); 1010 1011 /** 1012 * Ask the policy to dismiss the keyguard, if it is currently shown. 1013 * 1014 * @param callback Callback to be informed about the result. 1015 * @param message A message that should be displayed in the keyguard. 1016 */ dismissKeyguardLw(@ullable IKeyguardDismissCallback callback, CharSequence message)1017 public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback, 1018 CharSequence message); 1019 1020 /** 1021 * Ask the policy whether the Keyguard has drawn. If the Keyguard is disabled, this method 1022 * returns true as soon as we know that Keyguard is disabled. 1023 * 1024 * @return true if the keyguard has drawn. 1025 */ isKeyguardDrawnLw()1026 public boolean isKeyguardDrawnLw(); 1027 1028 /** 1029 * Called when the system is mostly done booting to set whether 1030 * the system should go into safe mode. 1031 */ setSafeMode(boolean safeMode)1032 public void setSafeMode(boolean safeMode); 1033 1034 /** 1035 * Called when the system is mostly done booting. 1036 */ systemReady()1037 public void systemReady(); 1038 1039 /** 1040 * Called when the system is done booting to the point where the 1041 * user can start interacting with it. 1042 */ systemBooted()1043 public void systemBooted(); 1044 1045 /** 1046 * Show boot time message to the user. 1047 */ showBootMessage(final CharSequence msg, final boolean always)1048 public void showBootMessage(final CharSequence msg, final boolean always); 1049 1050 /** 1051 * Hide the UI for showing boot messages, never to be displayed again. 1052 */ hideBootMessages()1053 public void hideBootMessages(); 1054 1055 /** 1056 * Called when userActivity is signalled in the power manager. 1057 * This is safe to call from any thread, with any window manager locks held or not. 1058 */ userActivity(int displayGroupId, int event)1059 void userActivity(int displayGroupId, int event); 1060 1061 /** 1062 * Called when we have finished booting and can now display the home 1063 * screen to the user. This will happen after systemReady(), and at 1064 * this point the display is active. 1065 */ enableScreenAfterBoot()1066 public void enableScreenAfterBoot(); 1067 1068 /** 1069 * Called when we have started keeping the screen on because a window 1070 * requesting this has become visible. 1071 */ keepScreenOnStartedLw()1072 public void keepScreenOnStartedLw(); 1073 1074 /** 1075 * Called when we have stopped keeping the screen on because the last window 1076 * requesting this is no longer visible. 1077 */ keepScreenOnStoppedLw()1078 public void keepScreenOnStoppedLw(); 1079 1080 /** 1081 * Called by System UI to notify of changes to the visibility of Recents. 1082 */ setRecentsVisibilityLw(boolean visible)1083 public void setRecentsVisibilityLw(boolean visible); 1084 1085 /** 1086 * Called by System UI to notify of changes to the visibility of PIP. 1087 */ setPipVisibilityLw(boolean visible)1088 void setPipVisibilityLw(boolean visible); 1089 1090 /** 1091 * Called by System UI to enable or disable haptic feedback on the navigation bar buttons. 1092 */ setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled)1093 void setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled); 1094 1095 /** 1096 * Specifies whether there is an on-screen navigation bar separate from the status bar. 1097 */ hasNavigationBar()1098 public boolean hasNavigationBar(); 1099 1100 /** 1101 * Lock the device now. 1102 */ lockNow(Bundle options)1103 public void lockNow(Bundle options); 1104 1105 /** 1106 * An internal callback (from InputMethodManagerService) to notify a state change regarding 1107 * whether the back key should dismiss the software keyboard (IME) or not. 1108 * 1109 * @param newValue {@code true} if the software keyboard is shown and the back key is expected 1110 * to dismiss the software keyboard. 1111 * @hide 1112 */ setDismissImeOnBackKeyPressed(boolean newValue)1113 default void setDismissImeOnBackKeyPressed(boolean newValue) { 1114 // Default implementation does nothing. 1115 } 1116 1117 /** 1118 * Show the recents task list app. 1119 * @hide 1120 */ showRecentApps()1121 public void showRecentApps(); 1122 1123 /** 1124 * Show the global actions dialog. 1125 * @hide 1126 */ showGlobalActions()1127 public void showGlobalActions(); 1128 1129 /** 1130 * Returns whether the user setup is complete. 1131 */ isUserSetupComplete()1132 boolean isUserSetupComplete(); 1133 1134 /** 1135 * Returns the current UI mode. 1136 */ getUiMode()1137 int getUiMode(); 1138 1139 /** 1140 * Called when the current user changes. Guaranteed to be called before the broadcast 1141 * of the new user id is made to all listeners. 1142 * 1143 * @param newUserId The id of the incoming user. 1144 */ setCurrentUserLw(int newUserId)1145 public void setCurrentUserLw(int newUserId); 1146 1147 /** 1148 * For a given user-switch operation, this will be called once with switching=true before the 1149 * user-switch and once with switching=false afterwards (or if the user-switch was cancelled). 1150 * This gives the policy a chance to alter its behavior for the duration of a user-switch. 1151 * 1152 * @param switching true if a user-switch is in progress 1153 */ setSwitchingUser(boolean switching)1154 void setSwitchingUser(boolean switching); 1155 1156 /** 1157 * Print the WindowManagerPolicy's state into the given stream. 1158 * 1159 * @param prefix Text to print at the front of each line. 1160 * @param writer The PrintWriter to which you should dump your state. This will be 1161 * closed for you after you return. 1162 * @param args additional arguments to the dump request. 1163 */ dump(String prefix, PrintWriter writer, String[] args)1164 public void dump(String prefix, PrintWriter writer, String[] args); 1165 1166 /** 1167 * Write the WindowManagerPolicy's state into the protocol buffer. 1168 * The message is described in {@link com.android.server.wm.WindowManagerPolicyProto} 1169 * 1170 * @param proto The protocol buffer output stream to write to. 1171 */ dumpDebug(ProtoOutputStream proto, long fieldId)1172 void dumpDebug(ProtoOutputStream proto, long fieldId); 1173 1174 /** 1175 * Notifies the keyguard to start fading out. 1176 * @param startTime the start time of the animation in uptime milliseconds 1177 * 1178 */ startKeyguardExitAnimation(long startTime)1179 void startKeyguardExitAnimation(long startTime); 1180 1181 /** 1182 * Called when System UI has been started. 1183 */ onSystemUiStarted()1184 void onSystemUiStarted(); 1185 1186 /** 1187 * Checks whether the policy is ready for dismissing the boot animation and completing the boot. 1188 * 1189 * @return true if ready; false otherwise. 1190 */ canDismissBootAnimation()1191 boolean canDismissBootAnimation(); 1192 1193 /** 1194 * Convert the user rotation mode to a human readable format. 1195 */ userRotationModeToString(int mode)1196 static String userRotationModeToString(int mode) { 1197 switch(mode) { 1198 case USER_ROTATION_FREE: 1199 return "USER_ROTATION_FREE"; 1200 case USER_ROTATION_LOCKED: 1201 return "USER_ROTATION_LOCKED"; 1202 default: 1203 return Integer.toString(mode); 1204 } 1205 } 1206 1207 /** 1208 * Registers an IDisplayFoldListener. 1209 */ registerDisplayFoldListener(IDisplayFoldListener listener)1210 default void registerDisplayFoldListener(IDisplayFoldListener listener) {} 1211 1212 /** 1213 * Unregisters an IDisplayFoldListener. 1214 */ unregisterDisplayFoldListener(IDisplayFoldListener listener)1215 default void unregisterDisplayFoldListener(IDisplayFoldListener listener) {} 1216 1217 /** 1218 * Overrides the folded area. 1219 * 1220 * @param area the overriding folded area or an empty {@code Rect} to clear the override. 1221 */ setOverrideFoldedArea(@onNull Rect area)1222 default void setOverrideFoldedArea(@NonNull Rect area) {} 1223 1224 /** 1225 * Get the display folded area. 1226 */ getFoldedArea()1227 default @NonNull Rect getFoldedArea() { 1228 return new Rect(); 1229 } 1230 1231 /** 1232 * A new window on default display has been focused. 1233 */ onDefaultDisplayFocusChangedLw(WindowState newFocus)1234 default void onDefaultDisplayFocusChangedLw(WindowState newFocus) {} 1235 1236 /** 1237 * Returns {@code true} if the key will be handled globally and not forwarded to all apps. 1238 * 1239 * @param keyCode the key code to check 1240 * @return {@code true} if the key will be handled globally. 1241 */ isGlobalKey(int keyCode)1242 boolean isGlobalKey(int keyCode); 1243 } 1244