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