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.wm; 18 19 import static java.lang.annotation.RetentionPolicy.SOURCE; 20 21 import android.annotation.IntDef; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.annotation.UserIdInt; 25 import android.content.ClipData; 26 import android.content.Context; 27 import android.graphics.Matrix; 28 import android.graphics.Point; 29 import android.graphics.Rect; 30 import android.graphics.Region; 31 import android.hardware.display.DisplayManagerInternal; 32 import android.hardware.display.VirtualDisplayConfig; 33 import android.os.Bundle; 34 import android.os.IBinder; 35 import android.os.Message; 36 import android.util.ArraySet; 37 import android.util.Pair; 38 import android.util.SparseArray; 39 import android.view.ContentRecordingSession; 40 import android.view.Display; 41 import android.view.IInputFilter; 42 import android.view.IRemoteAnimationFinishedCallback; 43 import android.view.IWindow; 44 import android.view.InputChannel; 45 import android.view.MagnificationSpec; 46 import android.view.RemoteAnimationTarget; 47 import android.view.SurfaceControl; 48 import android.view.SurfaceControlViewHost; 49 import android.view.WindowInfo; 50 import android.view.WindowManager.DisplayImePolicy; 51 import android.view.inputmethod.ImeTracker; 52 import android.window.ScreenCapture; 53 import android.window.ScreenCapture.ScreenshotHardwareBuffer; 54 55 import com.android.internal.policy.KeyInterceptionInfo; 56 import com.android.server.input.InputManagerService; 57 import com.android.server.policy.WindowManagerPolicy; 58 import com.android.server.wallpaper.WallpaperCropper.WallpaperCropUtils; 59 import com.android.server.wm.SensitiveContentPackages.PackageInfo; 60 61 import java.lang.annotation.Retention; 62 import java.util.List; 63 import java.util.Set; 64 import java.util.concurrent.CompletableFuture; 65 66 /** 67 * Window manager local system service interface. 68 * 69 * @hide Only for use within the system server. 70 */ 71 public abstract class WindowManagerInternal { 72 73 /** 74 * Interface for accessibility features implemented by AccessibilityController inside 75 * WindowManager. 76 */ 77 public interface AccessibilityControllerInternal { 78 /** 79 * Start tracing for the given logging types. 80 * @param loggingTypeFlags flags of the logging types enabled. 81 */ startTrace(long loggingTypeFlags)82 void startTrace(long loggingTypeFlags); 83 84 /** 85 * Disable accessibility tracing for all logging types. 86 */ stopTrace()87 void stopTrace(); 88 89 /** 90 * Is tracing enabled for any logging type. 91 */ isAccessibilityTracingEnabled()92 boolean isAccessibilityTracingEnabled(); 93 94 /** 95 * Add an accessibility trace entry. 96 * 97 * @param where A string to identify this log entry, which can be used to filter/search 98 * through the tracing file. 99 * @param loggingTypeFlags The flags for the logging types this log entry belongs to. 100 * @param callingParams The parameters for the method to be logged. 101 * @param a11yDump The proto byte array for a11y state when the entry is generated 102 * @param callingUid The calling uid. 103 * @param stackTrace The stack trace, null if not needed. 104 * @param ignoreStackEntries The stack entries can be removed 105 */ logTrace( String where, long loggingTypeFlags, String callingParams, byte[] a11yDump, int callingUid, StackTraceElement[] stackTrace, Set<String> ignoreStackEntries)106 void logTrace( 107 String where, long loggingTypeFlags, String callingParams, byte[] a11yDump, 108 int callingUid, StackTraceElement[] stackTrace, Set<String> ignoreStackEntries); 109 110 /** 111 * Add an accessibility trace entry. 112 * 113 * @param where A string to identify this log entry, which can be used to filter/search 114 * through the tracing file. 115 * @param loggingTypeFlags The flags for the logging types this log entry belongs to. 116 * @param callingParams The parameters for the method to be logged. 117 * @param a11yDump The proto byte array for a11y state when the entry is generated. 118 * @param callingUid The calling uid. 119 * @param callStack The call stack of the method to be logged. 120 * @param timeStamp The time when the method to be logged is called. 121 * @param processId The calling process Id. 122 * @param threadId The calling thread Id. 123 * @param ignoreStackEntries The stack entries can be removed 124 */ logTrace(String where, long loggingTypeFlags, String callingParams, byte[] a11yDump, int callingUid, StackTraceElement[] callStack, long timeStamp, int processId, long threadId, Set<String> ignoreStackEntries)125 void logTrace(String where, long loggingTypeFlags, String callingParams, 126 byte[] a11yDump, int callingUid, StackTraceElement[] callStack, long timeStamp, 127 int processId, long threadId, Set<String> ignoreStackEntries); 128 129 /** 130 * Set by the accessibility related modules which want to listen the event dispatched from 131 * window manager. Accessibility modules can use these callbacks to handle some display 132 * manipulations. 133 * @param callbacks The callbacks to invoke. 134 */ setUiChangesForAccessibilityCallbacks(UiChangesForAccessibilityCallbacks callbacks)135 void setUiChangesForAccessibilityCallbacks(UiChangesForAccessibilityCallbacks callbacks); 136 137 /** 138 * This interface is used by window manager to dispatch some ui change events which may 139 * affect the screen accessibility features. 140 */ 141 interface UiChangesForAccessibilityCallbacks { 142 /** 143 * Called when an application requests a rectangle focus on the screen. 144 * 145 * @param displayId The logical display id 146 * @param left The rectangle left. 147 * @param top The rectangle top. 148 * @param right The rectangle right. 149 * @param bottom The rectangle bottom. 150 */ onRectangleOnScreenRequested(int displayId, int left, int top, int right, int bottom)151 void onRectangleOnScreenRequested(int displayId, int left, int top, int right, 152 int bottom); 153 } 154 } 155 156 /** 157 * Interface to receive a callback when the windows reported for 158 * accessibility changed. 159 */ 160 public interface WindowsForAccessibilityCallback { 161 162 /** 163 * Called when the windows for accessibility changed. This is called if 164 * {@link com.android.server.accessibility.Flags.FLAG_COMPUTE_WINDOW_CHANGES_ON_A11Y_V2} is 165 * false. 166 * 167 * @param forceSend Send the windows for accessibility even if they haven't changed. 168 * @param topFocusedDisplayId The display Id which has the top focused window. 169 * @param topFocusedWindowToken The window token of top focused window. 170 * @param windows The windows for accessibility. 171 */ onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId, IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows)172 void onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId, 173 IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows); 174 175 /** 176 * Called when the windows for accessibility changed. This is called if 177 * {@link com.android.server.accessibility.Flags.FLAG_COMPUTE_WINDOW_CHANGES_ON_A11Y_V2} is 178 * true. 179 * TODO(b/322444245): Remove screenSize parameter by getting it from 180 * DisplayManager#getDisplay(int).getRealSize() on the a11y side. 181 * 182 * @param forceSend Send the windows for accessibility even if they haven't changed. 183 * @param topFocusedDisplayId The display Id which has the top focused window. 184 * @param topFocusedWindowToken The window token of top focused window. 185 * @param screenSize The size of the display that the change happened. 186 * @param windows The windows for accessibility. 187 */ onAccessibilityWindowsChanged(boolean forceSend, int topFocusedDisplayId, @NonNull IBinder topFocusedWindowToken, @NonNull Point screenSize, @NonNull List<AccessibilityWindowsPopulator.AccessibilityWindow> windows)188 void onAccessibilityWindowsChanged(boolean forceSend, int topFocusedDisplayId, 189 @NonNull IBinder topFocusedWindowToken, @NonNull Point screenSize, 190 @NonNull List<AccessibilityWindowsPopulator.AccessibilityWindow> windows); 191 } 192 193 /** 194 * Callbacks for contextual changes that affect the screen magnification 195 * feature. 196 */ 197 public interface MagnificationCallbacks { 198 199 /** 200 * Called when the region where magnification operates changes. Note that this isn't the 201 * entire screen. For example, IMEs are not magnified. 202 * 203 * @param magnificationRegion the current magnification region 204 */ onMagnificationRegionChanged(Region magnificationRegion)205 void onMagnificationRegionChanged(Region magnificationRegion); 206 207 /** 208 * Called when an application requests a rectangle on the screen to allow 209 * the client to apply the appropriate pan and scale. 210 * 211 * @param left The rectangle left. 212 * @param top The rectangle top. 213 * @param right The rectangle right. 214 * @param bottom The rectangle bottom. 215 */ onRectangleOnScreenRequested(int left, int top, int right, int bottom)216 void onRectangleOnScreenRequested(int left, int top, int right, int bottom); 217 218 /** 219 * Notifies that the display size is changed when rotation or the 220 * logical display is changed. 221 * 222 */ onDisplaySizeChanged()223 void onDisplaySizeChanged(); 224 225 /** 226 * Notifies that the context of the user changed. For example, an application 227 * was started. 228 */ onUserContextChanged()229 void onUserContextChanged(); 230 231 /** 232 * Notifies that the IME window visibility changed. 233 * @param shown {@code true} means the IME window shows on the screen. Otherwise it's 234 * hidden. 235 */ onImeWindowVisibilityChanged(boolean shown)236 void onImeWindowVisibilityChanged(boolean shown); 237 } 238 239 /** 240 * Abstract class to be notified about {@link com.android.server.wm.AppTransition} events. Held 241 * as an abstract class so a listener only needs to implement the methods of its interest. 242 */ 243 public static abstract class AppTransitionListener { 244 245 /** 246 * Called when an app transition is being setup and about to be executed. 247 */ onAppTransitionPendingLocked()248 public void onAppTransitionPendingLocked() {} 249 250 /** 251 * Called when a pending app transition gets cancelled. 252 * 253 * @param keyguardGoingAwayCancelled {@code true} if keyguard going away transition was 254 * cancelled. 255 */ onAppTransitionCancelledLocked(boolean keyguardGoingAwayCancelled)256 public void onAppTransitionCancelledLocked(boolean keyguardGoingAwayCancelled) {} 257 258 /** 259 * Called when an app transition is timed out. 260 */ onAppTransitionTimeoutLocked()261 public void onAppTransitionTimeoutLocked() {} 262 263 /** 264 * Called when an app transition gets started 265 * 266 * @param statusBarAnimationStartTime the desired start time for all visual animations in 267 * the status bar caused by this app transition in uptime millis 268 * @param statusBarAnimationDuration the duration for all visual animations in the status 269 * bar caused by this app transition in millis 270 * 271 * @return Return any bit set of {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_LAYOUT}, 272 * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_CONFIG}, 273 * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_WALLPAPER}, 274 * or {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_ANIM}. 275 */ onAppTransitionStartingLocked(long statusBarAnimationStartTime, long statusBarAnimationDuration)276 public int onAppTransitionStartingLocked(long statusBarAnimationStartTime, 277 long statusBarAnimationDuration) { 278 return 0; 279 } 280 281 /** 282 * Called when an app transition is finished running. 283 * 284 * @param token the token for app whose transition has finished 285 */ onAppTransitionFinishedLocked(IBinder token)286 public void onAppTransitionFinishedLocked(IBinder token) {} 287 } 288 289 /** 290 * An interface to be notified when the system bars for a task change. 291 */ 292 public interface TaskSystemBarsListener { 293 294 /** 295 * Called when the visibility of the system bars of a task change. 296 * 297 * @param taskId the identifier of the task. 298 * @param visible if the transient system bars are visible. 299 * @param wereRevealedFromSwipeOnSystemBar if the transient bars were revealed due to a 300 * swipe gesture on a system bar. 301 */ onTransientSystemBarsVisibilityChanged( int taskId, boolean visible, boolean wereRevealedFromSwipeOnSystemBar)302 void onTransientSystemBarsVisibilityChanged( 303 int taskId, 304 boolean visible, 305 boolean wereRevealedFromSwipeOnSystemBar); 306 } 307 308 /** 309 * An interface to be notified on window removal. 310 */ 311 public interface OnWindowRemovedListener { 312 /** 313 * Called when a window is removed. 314 * 315 * @param token the client token 316 */ onWindowRemoved(IBinder token)317 void onWindowRemoved(IBinder token); 318 } 319 320 /** 321 * An interface to be notified when keyguard exit animation should start. 322 */ 323 public interface KeyguardExitAnimationStartListener { 324 /** 325 * Called when keyguard exit animation should start. 326 * @param apps The list of apps to animate. 327 * @param wallpapers The list of wallpapers to animate. 328 * @param finishedCallback The callback to invoke when the animation is finished. 329 */ onAnimationStart(RemoteAnimationTarget[] apps, RemoteAnimationTarget[] wallpapers, IRemoteAnimationFinishedCallback finishedCallback)330 void onAnimationStart(RemoteAnimationTarget[] apps, 331 RemoteAnimationTarget[] wallpapers, 332 IRemoteAnimationFinishedCallback finishedCallback); 333 } 334 335 /** 336 * An interface to be notified about hardware keyboard status. 337 */ 338 public interface OnHardKeyboardStatusChangeListener { onHardKeyboardStatusChange(boolean available)339 public void onHardKeyboardStatusChange(boolean available); 340 } 341 342 /** 343 * An interface to be notified about requested changes in the IME visibility. 344 */ 345 public interface OnImeRequestedChangedListener { 346 /** 347 * Called when the requested IME visibility is changed. 348 * 349 * @param windowToken The window token 350 * @param imeVisible {@code true} if the IME should be shown, {@code false} to hide 351 */ onImeRequestedChanged(IBinder windowToken, boolean imeVisible)352 void onImeRequestedChanged(IBinder windowToken, boolean imeVisible); 353 } 354 355 /** 356 * An interface to customize drag and drop behaviors. 357 */ 358 public interface IDragDropCallback { registerInputChannel( DragState state, Display display, InputManagerService service, InputChannel source)359 default CompletableFuture<Boolean> registerInputChannel( 360 DragState state, Display display, InputManagerService service, 361 InputChannel source) { 362 return state.register(display) 363 .thenApply(unused -> 364 service.startDragAndDrop(source, state.getInputChannel())); 365 } 366 367 /** 368 * Called when drag operation is starting. 369 */ prePerformDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data)370 default boolean prePerformDrag(IWindow window, IBinder dragToken, 371 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, 372 ClipData data) { 373 return true; 374 } 375 376 /** 377 * Called when drag operation is started. 378 */ postPerformDrag()379 default void postPerformDrag() {} 380 381 /** 382 * Called when drop result is being reported. 383 */ preReportDropResult(IWindow window, boolean consumed)384 default void preReportDropResult(IWindow window, boolean consumed) {} 385 386 /** 387 * Called when drop result was reported. 388 */ postReportDropResult()389 default void postReportDropResult() {} 390 391 /** 392 * Called when drag operation is being cancelled. 393 */ preCancelDragAndDrop(IBinder dragToken)394 default void preCancelDragAndDrop(IBinder dragToken) {} 395 396 /** 397 * Called when drag operation was cancelled. 398 */ postCancelDragAndDrop()399 default void postCancelDragAndDrop() {} 400 401 /** 402 * Called when it has entered a View that is willing to accept the drop. 403 */ dragRecipientEntered(IWindow window)404 default void dragRecipientEntered(IWindow window) {} 405 406 /** 407 * Called when it has exited a View that is willing to accept the drop. 408 */ dragRecipientExited(IWindow window)409 default void dragRecipientExited(IWindow window) {} 410 } 411 412 /** 413 * Request the interface to access features implemented by AccessibilityController. 414 */ getAccessibilityController()415 public abstract AccessibilityControllerInternal getAccessibilityController(); 416 417 /** 418 * Request that the window manager call 419 * {@link DisplayManagerInternal#performTraversalInTransactionFromWindowManager} 420 * within a surface transaction at a later time. 421 */ requestTraversalFromDisplayManager()422 public abstract void requestTraversalFromDisplayManager(); 423 424 /** 425 * Called just before display manager has applied the device state to the displays 426 * @param deviceState device state as defined by 427 * {@link android.hardware.devicestate.DeviceStateManager} 428 */ onDisplayManagerReceivedDeviceState(int deviceState)429 public abstract void onDisplayManagerReceivedDeviceState(int deviceState); 430 431 /** 432 * Set by the accessibility layer to observe changes in the magnified region, 433 * rotation, and other window transformations related to display magnification 434 * as the window manager is responsible for doing the actual magnification 435 * and has access to the raw window data while the accessibility layer serves 436 * as a controller. 437 * 438 * @param displayId The logical display id. 439 * @param callbacks The callbacks to invoke. 440 * @return {@code false} if display id is not valid or an embedded display. 441 */ setMagnificationCallbacks(int displayId, @Nullable MagnificationCallbacks callbacks)442 public abstract boolean setMagnificationCallbacks(int displayId, 443 @Nullable MagnificationCallbacks callbacks); 444 445 /** 446 * Set by the accessibility layer to specify the magnification and panning to 447 * be applied to all windows that should be magnified. 448 * 449 * @param displayId The logical display id. 450 * @param spec The MagnficationSpec to set. 451 * 452 * @see #setMagnificationCallbacks(int, MagnificationCallbacks) 453 */ setMagnificationSpec(int displayId, MagnificationSpec spec)454 public abstract void setMagnificationSpec(int displayId, MagnificationSpec spec); 455 456 /** 457 * Set by the accessibility framework to indicate whether fullscreen magnification is activated. 458 * 459 * @param displayId The logical display id. 460 * @param activated The activation of fullscreen magnification 461 */ setFullscreenMagnificationActivated(int displayId, boolean activated)462 public abstract void setFullscreenMagnificationActivated(int displayId, boolean activated); 463 464 /** 465 * Obtains the magnification regions. 466 * 467 * @param displayId The logical display id. 468 * @param magnificationRegion the current magnification region 469 */ getMagnificationRegion(int displayId, @NonNull Region magnificationRegion)470 public abstract void getMagnificationRegion(int displayId, @NonNull Region magnificationRegion); 471 472 /** 473 * Sets a callback for observing which windows are touchable for the purposes 474 * of accessibility on specified display. 475 * 476 * @param displayId The logical display id. 477 * @param callback The callback. 478 */ setWindowsForAccessibilityCallback(int displayId, WindowsForAccessibilityCallback callback)479 public abstract void setWindowsForAccessibilityCallback(int displayId, 480 WindowsForAccessibilityCallback callback); 481 482 /** 483 * Sets a filter for manipulating the input event stream. 484 * 485 * @param filter The filter implementation. 486 */ setInputFilter(IInputFilter filter)487 public abstract void setInputFilter(IInputFilter filter); 488 489 /** 490 * Gets the token of the window that has input focus. 491 * 492 * @return The token. 493 */ getFocusedWindowToken()494 public abstract IBinder getFocusedWindowToken(); 495 496 /** 497 * Gets the token of the window that has input focus. It is from the focused 498 * {@link WindowState}. 499 * 500 * @return The token. 501 */ getFocusedWindowTokenFromWindowStates()502 public abstract IBinder getFocusedWindowTokenFromWindowStates(); 503 504 /** 505 * Moves the given display to the top. 506 */ moveDisplayToTopIfAllowed(int displayId)507 public abstract void moveDisplayToTopIfAllowed(int displayId); 508 509 /** 510 * Request to move window input focus to the window with the provided window token. 511 * 512 * <p> 513 * It is necessary to move window input focus before certain actions on views in a window can 514 * be performed, such as opening an IME. Input normally requests to move focus on window touch 515 * so this method should not be necessary in most cases; only features that bypass normal touch 516 * behavior (like Accessibility actions) require this method. 517 * </p> 518 * @param windowToken The window token. 519 */ requestWindowFocus(IBinder windowToken)520 public abstract void requestWindowFocus(IBinder windowToken); 521 522 /** 523 * @return Whether the keyguard is engaged. 524 */ isKeyguardLocked()525 public abstract boolean isKeyguardLocked(); 526 527 /** 528 * @return Whether the keyguard is showing and not occluded. 529 */ isKeyguardShowingAndNotOccluded()530 public abstract boolean isKeyguardShowingAndNotOccluded(); 531 532 /** 533 * Return whether the keyguard is secured by a PIN, pattern or password or a SIM card is 534 * currently locked. 535 * 536 * @param userId User ID to be queried about. 537 * @return {@code true} if a PIN, pattern or password is set or a SIM card is locked. 538 */ isKeyguardSecure(@serIdInt int userId)539 public abstract boolean isKeyguardSecure(@UserIdInt int userId); 540 541 /** 542 * Gets the frame of a window given its token. 543 * 544 * @param token The token. 545 * @param outBounds The frame to populate. 546 */ getWindowFrame(IBinder token, Rect outBounds)547 public abstract void getWindowFrame(IBinder token, Rect outBounds); 548 549 /** 550 * Get the transformation matrix and MagnificationSpec given its token. 551 * 552 * @param token The token. 553 * @return The pair of the transformation matrix and magnification spec. 554 */ 555 // TODO (b/231663133): Long term solution for tracking window when the 556 // FLAG_RETRIEVE_INTERACTIVE_WINDOWS is unset. 557 public abstract Pair<Matrix, MagnificationSpec> getWindowTransformationMatrixAndMagnificationSpec(IBinder token)558 getWindowTransformationMatrixAndMagnificationSpec(IBinder token); 559 560 /** 561 * Opens the global actions dialog. 562 */ showGlobalActions()563 public abstract void showGlobalActions(); 564 565 /** 566 * Invalidate all visible windows on a given display, and report back on the callback when all 567 * windows have redrawn. 568 * 569 * @param message The message will be sent when all windows have redrawn. Note that the message 570 * must be obtained from handler, otherwise it will throw NPE. 571 * @param timeout calls the callback anyway after the timeout. 572 * @param displayId waits for the windows on the given display, INVALID_DISPLAY to wait for all 573 * windows on all displays. 574 */ waitForAllWindowsDrawn(Message message, long timeout, int displayId)575 public abstract void waitForAllWindowsDrawn(Message message, long timeout, int displayId); 576 577 /** 578 * Overrides the display size. 579 * 580 * @param displayId The display to override the display size. 581 * @param width The width to override. 582 * @param height The height to override. 583 */ setForcedDisplaySize(int displayId, int width, int height)584 public abstract void setForcedDisplaySize(int displayId, int width, int height); 585 586 /** 587 * Recover the display size to real display size. 588 * 589 * @param displayId The display to recover the display size. 590 */ clearForcedDisplaySize(int displayId)591 public abstract void clearForcedDisplaySize(int displayId); 592 593 /** 594 * Adds a window token for a given window type. 595 * 596 * @param token The token to add. 597 * @param type The window type. 598 * @param displayId The display to add the token to. 599 * @param options A bundle used to pass window-related options. 600 */ addWindowToken(@onNull android.os.IBinder token, int type, int displayId, @Nullable Bundle options)601 public abstract void addWindowToken(@NonNull android.os.IBinder token, int type, int displayId, 602 @Nullable Bundle options); 603 604 /** 605 * Removes a window token. 606 * 607 * @param token The toke to remove. 608 * @param removeWindows Whether to also remove the windows associated with the token. 609 * @param displayId The display to remove the token from. 610 */ removeWindowToken(android.os.IBinder token, boolean removeWindows, int displayId)611 public final void removeWindowToken(android.os.IBinder token, boolean removeWindows, 612 int displayId) { 613 removeWindowToken(token, removeWindows, true /* animateExit */, displayId); 614 } 615 616 /** 617 * Removes a window token. 618 * 619 * @param token The toke to remove. 620 * @param removeWindows Whether to also remove the windows associated with the token. 621 * @param animateExit Whether to play the windows exit animation after the token removal. 622 * @param displayId The display to remove the token from. 623 */ removeWindowToken(android.os.IBinder token, boolean removeWindows, boolean animateExit, int displayId)624 public abstract void removeWindowToken(android.os.IBinder token, boolean removeWindows, 625 boolean animateExit, int displayId); 626 627 /** 628 * Registers a listener to be notified about app transition events. 629 * 630 * @param listener The listener to register. 631 */ registerAppTransitionListener(AppTransitionListener listener)632 public abstract void registerAppTransitionListener(AppTransitionListener listener); 633 634 /** 635 * Registers a listener to be notified to when the system bars of a task changes. 636 * 637 * @param listener The listener to register. 638 */ registerTaskSystemBarsListener(TaskSystemBarsListener listener)639 public abstract void registerTaskSystemBarsListener(TaskSystemBarsListener listener); 640 641 /** 642 * Registers a listener to be notified to when the system bars of a task changes. 643 * 644 * @param listener The listener to unregister. 645 */ unregisterTaskSystemBarsListener(TaskSystemBarsListener listener)646 public abstract void unregisterTaskSystemBarsListener(TaskSystemBarsListener listener); 647 648 /** 649 * Reports that the password for the given user has changed. 650 */ reportPasswordChanged(int userId)651 public abstract void reportPasswordChanged(int userId); 652 653 /** 654 * Retrieves a height of input method window for given display. 655 */ getInputMethodWindowVisibleHeight(int displayId)656 public abstract int getInputMethodWindowVisibleHeight(int displayId); 657 658 /** 659 * Notifies WindowManagerService that the expected back-button behavior might have changed. 660 * 661 * <p>Only {@link com.android.server.inputmethod.InputMethodManagerService} is the expected and 662 * tested caller of this method.</p> 663 * 664 * @param dismissImeOnBackKeyPressed {@code true} if the software keyboard is shown and the back 665 * key is expected to dismiss the software keyboard. 666 */ setDismissImeOnBackKeyPressed(boolean dismissImeOnBackKeyPressed)667 public abstract void setDismissImeOnBackKeyPressed(boolean dismissImeOnBackKeyPressed); 668 669 /** 670 * Notifies WindowManagerService that the current IME window status is being changed. 671 * 672 * <p>Only {@link com.android.server.inputmethod.InputMethodManagerService} is the expected and 673 * tested caller of this method.</p> 674 * 675 * @param imeToken token to track the active input method. Corresponding IME windows can be 676 * identified by checking {@link android.view.WindowManager.LayoutParams#token}. 677 * Note that there is no guarantee that the corresponding window is already 678 * created 679 * @param imeTargetWindowToken token to identify the target window that the IME is associated 680 * with 681 */ updateInputMethodTargetWindow(@onNull IBinder imeToken, @NonNull IBinder imeTargetWindowToken)682 public abstract void updateInputMethodTargetWindow(@NonNull IBinder imeToken, 683 @NonNull IBinder imeTargetWindowToken); 684 685 /** 686 * Returns true when the hardware keyboard is available. 687 */ isHardKeyboardAvailable()688 public abstract boolean isHardKeyboardAvailable(); 689 690 /** 691 * Sets the callback listener for hardware keyboard status changes. 692 * 693 * @param listener The listener to set. 694 */ setOnHardKeyboardStatusChangeListener( OnHardKeyboardStatusChangeListener listener)695 public abstract void setOnHardKeyboardStatusChangeListener( 696 OnHardKeyboardStatusChangeListener listener); 697 698 699 /** 700 * Sets the callback listener for requested IME visibility changes in ImeInsetsSourceProvider 701 * 702 * @param listener The listener to set 703 */ setOnImeRequestedChangedListener(OnImeRequestedChangedListener listener)704 public abstract void setOnImeRequestedChangedListener(OnImeRequestedChangedListener listener); 705 706 /** 707 * Requests the window manager to resend the windows for accessibility on specified display. 708 * 709 * @param displayId Display ID to be computed its windows for accessibility 710 */ computeWindowsForAccessibility(int displayId)711 public abstract void computeWindowsForAccessibility(int displayId); 712 713 /** 714 * Called after virtual display Id is updated by 715 * {@link com.android.server.vr.Vr2dDisplay} with a specific 716 * {@param vr2dDisplayId}. 717 */ setVr2dDisplayId(int vr2dDisplayId)718 public abstract void setVr2dDisplayId(int vr2dDisplayId); 719 720 /** 721 * Sets callback to DragDropController. 722 */ registerDragDropControllerCallback(IDragDropCallback callback)723 public abstract void registerDragDropControllerCallback(IDragDropCallback callback); 724 725 /** 726 * @see android.view.IWindowManager#lockNow 727 */ lockNow()728 public abstract void lockNow(); 729 730 /** 731 * Return the user that owns the given window, {@link android.os.UserHandle#USER_NULL} if 732 * the window token is not found. 733 */ getWindowOwnerUserId(IBinder windowToken)734 public abstract int getWindowOwnerUserId(IBinder windowToken); 735 736 /** 737 * Control visilibility of a {@link WallpaperWindowToken} {@code} binder on the lock screen. 738 * 739 * <p>This will also affect its Z-ordering as {@code showWhenLocked} wallpaper tokens are 740 * arranged underneath non-{@code showWhenLocked} wallpaper tokens. 741 * 742 * @param windowToken wallpaper token previously added via {@link #addWindowToken} 743 * @param showWhenLocked whether {@param token} can continue to be shown on the lock screen. 744 */ setWallpaperShowWhenLocked(IBinder windowToken, boolean showWhenLocked)745 public abstract void setWallpaperShowWhenLocked(IBinder windowToken, boolean showWhenLocked); 746 747 /** 748 * Sets the crop hints of a {@link WallpaperWindowToken}. Only effective for image wallpapers. 749 * 750 * @param windowToken wallpaper token previously added via {@link #addWindowToken} 751 * @param cropHints a map that represents which part of the wallpaper should be shown, for 752 * each type of {@link android.app.WallpaperManager.ScreenOrientation}. 753 */ setWallpaperCropHints(IBinder windowToken, SparseArray<Rect> cropHints)754 public abstract void setWallpaperCropHints(IBinder windowToken, SparseArray<Rect> cropHints); 755 756 /** 757 * Transmits the {@link WallpaperCropUtils} instance to {@link WallpaperController}. 758 * {@link WallpaperCropUtils} contains the helpers to properly position the wallpaper. 759 */ setWallpaperCropUtils(WallpaperCropUtils wallpaperCropUtils)760 public abstract void setWallpaperCropUtils(WallpaperCropUtils wallpaperCropUtils); 761 762 /** 763 * Returns {@code true} if a Window owned by {@code uid} has focus. 764 */ isUidFocused(int uid)765 public abstract boolean isUidFocused(int uid); 766 767 /** 768 * Checks whether the specified IME client has IME focus or not. 769 * 770 * @param windowToken The window token of the input method client 771 * @param uid UID of the process to be queried 772 * @param pid PID of the process to be queried 773 * @param displayId Display ID reported from the client. Note that this method also verifies 774 * whether the specified process is allowed to access to this display or not 775 * @return {@code true} if the IME client specified with {@code uid}, {@code pid}, and 776 * {@code displayId} has IME focus 777 */ hasInputMethodClientFocus(IBinder windowToken, int uid, int pid, int displayId)778 public abstract @ImeClientFocusResult int hasInputMethodClientFocus(IBinder windowToken, 779 int uid, int pid, int displayId); 780 781 @Retention(SOURCE) 782 @IntDef({ 783 ImeClientFocusResult.HAS_IME_FOCUS, 784 ImeClientFocusResult.NOT_IME_TARGET_WINDOW, 785 ImeClientFocusResult.DISPLAY_ID_MISMATCH, 786 ImeClientFocusResult.INVALID_DISPLAY_ID 787 }) 788 public @interface ImeClientFocusResult { 789 int HAS_IME_FOCUS = 0; 790 int NOT_IME_TARGET_WINDOW = -1; 791 int DISPLAY_ID_MISMATCH = -2; 792 int INVALID_DISPLAY_ID = -3; 793 } 794 795 /** 796 * Checks whether the given {@code uid} is allowed to use the given {@code displayId} or not. 797 * 798 * @param displayId Display ID to be checked 799 * @param uid UID to be checked. 800 * @return {@code true} if the given {@code uid} is allowed to use the given {@code displayId} 801 */ isUidAllowedOnDisplay(int displayId, int uid)802 public abstract boolean isUidAllowedOnDisplay(int displayId, int uid); 803 804 /** 805 * Return the display Id for given window. 806 */ getDisplayIdForWindow(IBinder windowToken)807 public abstract int getDisplayIdForWindow(IBinder windowToken); 808 809 /** 810 * @return The top focused display ID. 811 */ getTopFocusedDisplayId()812 public abstract int getTopFocusedDisplayId(); 813 814 /** 815 * @return The UI context of top focused display. 816 */ getTopFocusedDisplayUiContext()817 public abstract Context getTopFocusedDisplayUiContext(); 818 819 /** 820 * Sets whether the relevant display content can host the relevant home activity and wallpaper. 821 * 822 * @param displayUniqueId The unique ID of the display. Note that the display may not yet be 823 * created, but whenever it is, this property will be applied. 824 * @param displayType The type of the display, e.g. {@link Display#TYPE_VIRTUAL}. 825 * @param supported Whether home and wallpaper are supported on this display. 826 */ setHomeSupportedOnDisplay( @onNull String displayUniqueId, int displayType, boolean supported)827 public abstract void setHomeSupportedOnDisplay( 828 @NonNull String displayUniqueId, int displayType, boolean supported); 829 830 /** 831 * Checks if this display is configured and allowed to show home activity and wallpaper. 832 * 833 * <p>This is implied for displays that have {@link Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS} 834 * and can also be set via {@link VirtualDisplayConfig.Builder#setHomeSupported}.</p> 835 */ isHomeSupportedOnDisplay(int displayId)836 public abstract boolean isHomeSupportedOnDisplay(int displayId); 837 838 /** 839 * Removes any settings relevant to the given display. 840 * 841 * <p>This may be used when a property is set for a display unique ID before the display 842 * creation but the actual display creation failed for some reason.</p> 843 */ clearDisplaySettings(@onNull String displayUniqueId, int displayType)844 public abstract void clearDisplaySettings(@NonNull String displayUniqueId, int displayType); 845 846 /** 847 * Indicates the policy for how the display should show IME. 848 * 849 * @param displayId The id of the display. 850 * @return The policy for how the display should show IME. 851 */ getDisplayImePolicy(int displayId)852 public abstract @DisplayImePolicy int getDisplayImePolicy(int displayId); 853 854 /** 855 * Show IME on imeTargetWindow once IME has finished layout. 856 * 857 * @param imeTargetWindowToken token of the (IME target) window which IME should be shown. 858 * @param statsToken the token tracking the current IME request. 859 */ showImePostLayout(IBinder imeTargetWindowToken, @NonNull ImeTracker.Token statsToken)860 public abstract void showImePostLayout(IBinder imeTargetWindowToken, 861 @NonNull ImeTracker.Token statsToken); 862 863 /** 864 * Hide IME using imeTargetWindow when requested. 865 * 866 * @param imeTargetWindowToken token of the (IME target) window which requests hiding IME. 867 * @param displayId the id of the display the IME is on. 868 * @param statsToken the token tracking the current IME request. 869 */ hideIme(IBinder imeTargetWindowToken, int displayId, @NonNull ImeTracker.Token statsToken)870 public abstract void hideIme(IBinder imeTargetWindowToken, int displayId, 871 @NonNull ImeTracker.Token statsToken); 872 873 /** 874 * Tell window manager about a package that should be running with a restricted range of 875 * refresh rate setting until removeRefreshRateRangeForPackage is called for the same package. 876 * 877 * This must not be called again for the same package. 878 */ addRefreshRateRangeForPackage(@onNull String packageName, float minRefreshRate, float maxRefreshRate)879 public abstract void addRefreshRateRangeForPackage(@NonNull String packageName, 880 float minRefreshRate, float maxRefreshRate); 881 882 /** 883 * Tell window manager to stop constraining refresh rate for the given package. 884 */ removeRefreshRateRangeForPackage(@onNull String packageName)885 public abstract void removeRefreshRateRangeForPackage(@NonNull String packageName); 886 887 /** 888 * Checks if the device supports touch or faketouch. 889 */ isTouchOrFaketouchDevice()890 public abstract boolean isTouchOrFaketouchDevice(); 891 892 /** 893 * Returns the info associated with the input token used to determine if a key should be 894 * intercepted. This info can be accessed without holding the global wm lock. 895 */ 896 public abstract @Nullable KeyInterceptionInfo getKeyInterceptionInfoFromToken(IBinder inputToken)897 getKeyInterceptionInfoFromToken(IBinder inputToken); 898 899 /** 900 * Clears the snapshot cache of running activities so they show the splash-screen 901 * the next time the activities are opened. 902 */ clearSnapshotCache()903 public abstract void clearSnapshotCache(); 904 905 /** 906 * Assigns accessibility ID a window surface as a layer metadata. 907 */ setAccessibilityIdToSurfaceMetadata( IBinder windowToken, int accessibilityWindowId)908 public abstract void setAccessibilityIdToSurfaceMetadata( 909 IBinder windowToken, int accessibilityWindowId); 910 911 /** 912 * 913 * Returns the window name associated to the given binder. 914 * 915 * @param binder The {@link IBinder} object 916 * @return The corresponding {@link WindowState#getName()} 917 */ getWindowName(@onNull IBinder binder)918 public abstract String getWindowName(@NonNull IBinder binder); 919 920 /** 921 * The callback after the request of show/hide input method is sent. 922 * 923 * @param show Whether to show or hide input method. 924 * @param focusedToken The token of focused window. 925 * @param requestToken The token of window who requests the change. 926 * @param displayId The ID of the display which input method is currently focused. 927 * @return The information of the input method target. 928 */ onToggleImeRequested(boolean show, @NonNull IBinder focusedToken, @NonNull IBinder requestToken, int displayId)929 public abstract ImeTargetInfo onToggleImeRequested(boolean show, 930 @NonNull IBinder focusedToken, @NonNull IBinder requestToken, int displayId); 931 932 /** 933 * Returns the token to identify the target window that the IME is associated with. 934 */ getTargetWindowTokenFromInputToken(IBinder inputToken)935 public abstract @Nullable IBinder getTargetWindowTokenFromInputToken(IBinder inputToken); 936 937 /** The information of input method target when IME is requested to show or hide. */ 938 public static class ImeTargetInfo { 939 public final String focusedWindowName; 940 public final String requestWindowName; 941 942 /** The window name of IME Insets control target. */ 943 public final String imeControlTargetName; 944 945 /** 946 * The current window name of the input method is on top of. 947 * <p> 948 * Note that the concept of this window is only used to reparent the target window behind 949 * the input method window, it may be different from the window reported by 950 * {@link com.android.server.inputmethod.InputMethodManagerService#reportStartInput} which 951 * has input connection. 952 */ 953 public final String imeLayerTargetName; 954 955 /** The surface parent of the IME container. */ 956 public final String imeSurfaceParentName; 957 ImeTargetInfo(String focusedWindowName, String requestWindowName, String imeControlTargetName, String imeLayerTargetName, String imeSurfaceParentName)958 public ImeTargetInfo(String focusedWindowName, String requestWindowName, 959 String imeControlTargetName, String imeLayerTargetName, 960 String imeSurfaceParentName) { 961 this.focusedWindowName = focusedWindowName; 962 this.requestWindowName = requestWindowName; 963 this.imeControlTargetName = imeControlTargetName; 964 this.imeLayerTargetName = imeLayerTargetName; 965 this.imeSurfaceParentName = imeSurfaceParentName; 966 } 967 } 968 969 /** 970 * Sets by the {@link com.android.server.inputmethod.InputMethodManagerService} to monitor 971 * the visibility change of the IME targeted windows. 972 * 973 * @see ImeTargetChangeListener#onImeTargetOverlayVisibilityChanged 974 * @see ImeTargetChangeListener#onImeInputTargetVisibilityChanged 975 */ setInputMethodTargetChangeListener( @onNull ImeTargetChangeListener listener)976 public abstract void setInputMethodTargetChangeListener( 977 @NonNull ImeTargetChangeListener listener); 978 979 /** 980 * Moves the {@link WindowToken} {@code binder} to the display specified by {@code displayId}. 981 */ moveWindowTokenToDisplay(IBinder binder, int displayId)982 public abstract void moveWindowTokenToDisplay(IBinder binder, int displayId); 983 984 /** 985 * Checks whether the given window should restore the last IME visibility. 986 * 987 * @param imeTargetWindowToken The token of the (IME target) window 988 * @return {@code true} when the system allows to restore the IME visibility, 989 * {@code false} otherwise. 990 */ shouldRestoreImeVisibility(IBinder imeTargetWindowToken)991 public abstract boolean shouldRestoreImeVisibility(IBinder imeTargetWindowToken); 992 993 /** 994 * Internal methods for other parts of SystemServer to manage 995 * SurfacePackage based overlays on tasks. 996 * 997 * Since these overlays will overlay application content, they exist 998 * in a container with setTrustedOverlay(true). This means its imperative 999 * that this overlay feature only be used with UI completely under the control 1000 * of the system, without 3rd party content. 1001 * 1002 * Callers prepare a view hierarchy with SurfaceControlViewHost 1003 * and send the package to WM here. The remote view hierarchy will receive 1004 * configuration change, lifecycle events, etc, forwarded over the 1005 * ISurfaceControlViewHost interface inside the SurfacePackage. Embedded 1006 * hierarchies will receive inset changes, including transient inset changes 1007 * (to avoid the status bar in immersive mode). 1008 * 1009 * The embedded hierarchy exists in a coordinate space relative to the task 1010 * bounds. 1011 */ addTrustedTaskOverlay(int taskId, SurfaceControlViewHost.SurfacePackage overlay)1012 public abstract void addTrustedTaskOverlay(int taskId, 1013 SurfaceControlViewHost.SurfacePackage overlay); removeTrustedTaskOverlay(int taskId, SurfaceControlViewHost.SurfacePackage overlay)1014 public abstract void removeTrustedTaskOverlay(int taskId, 1015 SurfaceControlViewHost.SurfacePackage overlay); 1016 1017 /** 1018 * Get a SurfaceControl that is the container layer that should be used to receive input to 1019 * support handwriting (Scribe) by the IME. 1020 */ getHandwritingSurfaceForDisplay(int displayId)1021 public abstract SurfaceControl getHandwritingSurfaceForDisplay(int displayId); 1022 1023 /** 1024 * Returns {@code true} if the given point is within the window bounds of the given window. 1025 * 1026 * @param windowToken the window whose bounds should be used for the hit test. 1027 * @param displayX the x coordinate of the test point in the display's coordinate space. 1028 * @param displayY the y coordinate of the test point in the display's coordinate space. 1029 */ isPointInsideWindow( @onNull IBinder windowToken, int displayId, float displayX, float displayY)1030 public abstract boolean isPointInsideWindow( 1031 @NonNull IBinder windowToken, int displayId, float displayX, float displayY); 1032 1033 /** 1034 * Updates the content recording session. If a different session is already in progress, then 1035 * the pre-existing session is stopped, and the new incoming session takes over. 1036 * 1037 * The DisplayContent for the new session will begin recording when 1038 * {@link RootWindowContainer#onDisplayChanged} is invoked for the new {@link VirtualDisplay}. 1039 * Must be invoked for a valid MediaProjection session. 1040 * 1041 * @param incomingSession the nullable incoming content recording session 1042 * @return {@code true} if successfully set the session, or {@code false} if the session 1043 * could not be prepared and the session needs to be torn down. 1044 */ setContentRecordingSession(ContentRecordingSession incomingSession)1045 public abstract boolean setContentRecordingSession(ContentRecordingSession incomingSession); 1046 1047 /** Returns the SurfaceControl accessibility services should use for accessibility overlays. */ getA11yOverlayLayer(int displayId)1048 public abstract SurfaceControl getA11yOverlayLayer(int displayId); 1049 1050 /** 1051 * Captures the entire display specified by the displayId using the args provided. If the args 1052 * are null or if the sourceCrop is invalid or null, the entire display bounds will be captured. 1053 */ captureDisplay(int displayId, @Nullable ScreenCapture.CaptureArgs captureArgs, ScreenCapture.ScreenCaptureListener listener)1054 public abstract void captureDisplay(int displayId, 1055 @Nullable ScreenCapture.CaptureArgs captureArgs, 1056 ScreenCapture.ScreenCaptureListener listener); 1057 1058 /** 1059 * Device has a software navigation bar (separate from the status bar) on specific display. 1060 * 1061 * @param displayId the id of display to check if there is a software navigation bar. 1062 */ hasNavigationBar(int displayId)1063 public abstract boolean hasNavigationBar(int displayId); 1064 1065 /** 1066 * Controls whether the app-requested screen orientation is always respected. 1067 * 1068 * @param respected If {@code true}, the app requested orientation is always respected. 1069 * Otherwise, the system might ignore the request due to 1070 * {@link com.android.server.wm.DisplayArea#getIgnoreOrientationRequest}. 1071 * @param fromOrientations The orientations we want to map to the correspondent orientations 1072 * in toOrientation. 1073 * @param toOrientations The orientations we map to the ones in fromOrientations at the same 1074 * index 1075 */ setOrientationRequestPolicy(boolean respected, int[] fromOrientations, int[] toOrientations)1076 public abstract void setOrientationRequestPolicy(boolean respected, 1077 int[] fromOrientations, int[] toOrientations); 1078 1079 /** 1080 * Set current screen capture session id that will be used during sensitive content protections. 1081 * 1082 * @param sessionId Session id for this screen capture protection 1083 */ setBlockScreenCaptureForAppsSessionId(long sessionId)1084 public abstract void setBlockScreenCaptureForAppsSessionId(long sessionId); 1085 1086 /** 1087 * Set whether screen capture should be disabled for all windows of a specific app windows based 1088 * on sensitive content protections. 1089 * 1090 * @param packageInfos set of {@link PackageInfo} whose windows should be blocked from capture 1091 */ addBlockScreenCaptureForApps(@onNull ArraySet<PackageInfo> packageInfos)1092 public abstract void addBlockScreenCaptureForApps(@NonNull ArraySet<PackageInfo> packageInfos); 1093 1094 /** 1095 * Clears apps added to collection of apps in which screen capture should be disabled. 1096 * 1097 * @param packageInfos set of {@link PackageInfo} whose windows should be unblocked 1098 * from capture. 1099 */ removeBlockScreenCaptureForApps( @onNull ArraySet<PackageInfo> packageInfos)1100 public abstract void removeBlockScreenCaptureForApps( 1101 @NonNull ArraySet<PackageInfo> packageInfos); 1102 1103 /** 1104 * Clears all apps added to collection of apps in which screen capture should be disabled. 1105 * 1106 * <p> This clears and resets any existing set or added applications from 1107 * * {@link #addBlockScreenCaptureForApps(ArraySet)} 1108 */ clearBlockedApps()1109 public abstract void clearBlockedApps(); 1110 1111 /** 1112 * Register a listener to receive a callback on window removal. 1113 * 1114 * @param listener the listener to be registered. 1115 */ registerOnWindowRemovedListener(OnWindowRemovedListener listener)1116 public abstract void registerOnWindowRemovedListener(OnWindowRemovedListener listener); 1117 1118 /** 1119 * Removes the listener. 1120 * 1121 * @param listener the listener to be removed. 1122 */ unregisterOnWindowRemovedListener(OnWindowRemovedListener listener)1123 public abstract void unregisterOnWindowRemovedListener(OnWindowRemovedListener listener); 1124 1125 /** 1126 * Moves the current focus to the adjacent activity if it has the latest created window. 1127 */ moveFocusToAdjacentEmbeddedActivityIfNeeded()1128 public abstract boolean moveFocusToAdjacentEmbeddedActivityIfNeeded(); 1129 1130 /** 1131 * Returns an instance of {@link ScreenshotHardwareBuffer} containing the current 1132 * screenshot. 1133 */ takeAssistScreenshot( Set<Integer> windowTypesToExclude)1134 public abstract ScreenshotHardwareBuffer takeAssistScreenshot( 1135 Set<Integer> windowTypesToExclude); 1136 } 1137