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.content.ClipData; 25 import android.content.Context; 26 import android.graphics.Matrix; 27 import android.graphics.Rect; 28 import android.graphics.Region; 29 import android.hardware.display.DisplayManagerInternal; 30 import android.os.Bundle; 31 import android.os.IBinder; 32 import android.util.Pair; 33 import android.view.ContentRecordingSession; 34 import android.view.Display; 35 import android.view.IInputFilter; 36 import android.view.IRemoteAnimationFinishedCallback; 37 import android.view.IWindow; 38 import android.view.InputChannel; 39 import android.view.MagnificationSpec; 40 import android.view.RemoteAnimationTarget; 41 import android.view.SurfaceControl; 42 import android.view.SurfaceControlViewHost; 43 import android.view.WindowInfo; 44 import android.view.WindowManager.DisplayImePolicy; 45 46 import com.android.internal.policy.KeyInterceptionInfo; 47 import com.android.server.input.InputManagerService; 48 import com.android.server.policy.WindowManagerPolicy; 49 50 import java.lang.annotation.Retention; 51 import java.util.List; 52 import java.util.Set; 53 54 /** 55 * Window manager local system service interface. 56 * 57 * @hide Only for use within the system server. 58 */ 59 public abstract class WindowManagerInternal { 60 61 /** 62 * Interface for accessibility features implemented by AccessibilityController inside 63 * WindowManager. 64 */ 65 public interface AccessibilityControllerInternal { 66 /** 67 * Start tracing for the given logging types. 68 * @param loggingTypeFlags flags of the logging types enabled. 69 */ startTrace(long loggingTypeFlags)70 void startTrace(long loggingTypeFlags); 71 72 /** 73 * Disable accessibility tracing for all logging types. 74 */ stopTrace()75 void stopTrace(); 76 77 /** 78 * Is tracing enabled for any logging type. 79 */ isAccessibilityTracingEnabled()80 boolean isAccessibilityTracingEnabled(); 81 82 /** 83 * Add an accessibility trace entry. 84 * 85 * @param where A string to identify this log entry, which can be used to filter/search 86 * through the tracing file. 87 * @param loggingTypeFlags The flags for the logging types this log entry belongs to. 88 * @param callingParams The parameters for the method to be logged. 89 * @param a11yDump The proto byte array for a11y state when the entry is generated 90 * @param callingUid The calling uid. 91 * @param stackTrace The stack trace, null if not needed. 92 * @param ignoreStackEntries The stack entries can be removed 93 */ logTrace( String where, long loggingTypeFlags, String callingParams, byte[] a11yDump, int callingUid, StackTraceElement[] stackTrace, Set<String> ignoreStackEntries)94 void logTrace( 95 String where, long loggingTypeFlags, String callingParams, byte[] a11yDump, 96 int callingUid, StackTraceElement[] stackTrace, Set<String> ignoreStackEntries); 97 98 /** 99 * Add an accessibility trace entry. 100 * 101 * @param where A string to identify this log entry, which can be used to filter/search 102 * through the tracing file. 103 * @param loggingTypeFlags The flags for the logging types this log entry belongs to. 104 * @param callingParams The parameters for the method to be logged. 105 * @param a11yDump The proto byte array for a11y state when the entry is generated. 106 * @param callingUid The calling uid. 107 * @param callStack The call stack of the method to be logged. 108 * @param timeStamp The time when the method to be logged is called. 109 * @param processId The calling process Id. 110 * @param threadId The calling thread Id. 111 * @param ignoreStackEntries The stack entries can be removed 112 */ logTrace(String where, long loggingTypeFlags, String callingParams, byte[] a11yDump, int callingUid, StackTraceElement[] callStack, long timeStamp, int processId, long threadId, Set<String> ignoreStackEntries)113 void logTrace(String where, long loggingTypeFlags, String callingParams, 114 byte[] a11yDump, int callingUid, StackTraceElement[] callStack, long timeStamp, 115 int processId, long threadId, Set<String> ignoreStackEntries); 116 117 /** 118 * Set by the accessibility related modules which want to listen the event dispatched from 119 * window manager. Accessibility modules can use these callbacks to handle some display 120 * manipulations. 121 * @param callbacks The callbacks to invoke. 122 */ setUiChangesForAccessibilityCallbacks(UiChangesForAccessibilityCallbacks callbacks)123 void setUiChangesForAccessibilityCallbacks(UiChangesForAccessibilityCallbacks callbacks); 124 125 /** 126 * This interface is used by window manager to dispatch some ui change events which may 127 * affect the screen accessibility features. 128 */ 129 interface UiChangesForAccessibilityCallbacks { 130 /** 131 * Called when an application requests a rectangle focus on the screen. 132 * 133 * @param displayId The logical display id 134 * @param left The rectangle left. 135 * @param top The rectangle top. 136 * @param right The rectangle right. 137 * @param bottom The rectangle bottom. 138 */ onRectangleOnScreenRequested(int displayId, int left, int top, int right, int bottom)139 void onRectangleOnScreenRequested(int displayId, int left, int top, int right, 140 int bottom); 141 } 142 } 143 144 /** 145 * Interface to receive a callback when the windows reported for 146 * accessibility changed. 147 */ 148 public interface WindowsForAccessibilityCallback { 149 150 /** 151 * Called when the windows for accessibility changed. 152 * 153 * @param forceSend Send the windows for accessibility even if they haven't changed. 154 * @param topFocusedDisplayId The display Id which has the top focused window. 155 * @param topFocusedWindowToken The window token of top focused window. 156 * @param windows The windows for accessibility. 157 */ onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId, IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows)158 void onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId, 159 IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows); 160 } 161 162 /** 163 * Callbacks for contextual changes that affect the screen magnification 164 * feature. 165 */ 166 public interface MagnificationCallbacks { 167 168 /** 169 * Called when the region where magnification operates changes. Note that this isn't the 170 * entire screen. For example, IMEs are not magnified. 171 * 172 * @param magnificationRegion the current magnification region 173 */ onMagnificationRegionChanged(Region magnificationRegion)174 void onMagnificationRegionChanged(Region magnificationRegion); 175 176 /** 177 * Called when an application requests a rectangle on the screen to allow 178 * the client to apply the appropriate pan and scale. 179 * 180 * @param left The rectangle left. 181 * @param top The rectangle top. 182 * @param right The rectangle right. 183 * @param bottom The rectangle bottom. 184 */ onRectangleOnScreenRequested(int left, int top, int right, int bottom)185 void onRectangleOnScreenRequested(int left, int top, int right, int bottom); 186 187 /** 188 * Notifies that the display size is changed when rotation or the 189 * logical display is changed. 190 * 191 */ onDisplaySizeChanged()192 void onDisplaySizeChanged(); 193 194 /** 195 * Notifies that the context of the user changed. For example, an application 196 * was started. 197 */ onUserContextChanged()198 void onUserContextChanged(); 199 200 /** 201 * Notifies that the IME window visibility changed. 202 * @param shown {@code true} means the IME window shows on the screen. Otherwise it's 203 * hidden. 204 */ onImeWindowVisibilityChanged(boolean shown)205 void onImeWindowVisibilityChanged(boolean shown); 206 } 207 208 /** 209 * Abstract class to be notified about {@link com.android.server.wm.AppTransition} events. Held 210 * as an abstract class so a listener only needs to implement the methods of its interest. 211 */ 212 public static abstract class AppTransitionListener { 213 214 /** 215 * Called when an app transition is being setup and about to be executed. 216 */ onAppTransitionPendingLocked()217 public void onAppTransitionPendingLocked() {} 218 219 /** 220 * Called when a pending app transition gets cancelled. 221 * 222 * @param keyguardGoingAway true if keyguard going away transition got cancelled. 223 */ onAppTransitionCancelledLocked(boolean keyguardGoingAway)224 public void onAppTransitionCancelledLocked(boolean keyguardGoingAway) {} 225 226 /** 227 * Called when an app transition is timed out. 228 */ onAppTransitionTimeoutLocked()229 public void onAppTransitionTimeoutLocked() {} 230 231 /** 232 * Called when an app transition gets started 233 * 234 * @param keyguardGoingAway true if keyguard going away transition is started. 235 * @param keyguardOccluding true if keyguard (un)occlude transition is started. 236 * @param duration the total duration of the transition 237 * @param statusBarAnimationStartTime the desired start time for all visual animations in 238 * the status bar caused by this app transition in uptime millis 239 * @param statusBarAnimationDuration the duration for all visual animations in the status 240 * bar caused by this app transition in millis 241 * 242 * @return Return any bit set of {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_LAYOUT}, 243 * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_CONFIG}, 244 * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_WALLPAPER}, 245 * or {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_ANIM}. 246 */ onAppTransitionStartingLocked(boolean keyguardGoingAway, boolean keyguardOccluding, long duration, long statusBarAnimationStartTime, long statusBarAnimationDuration)247 public int onAppTransitionStartingLocked(boolean keyguardGoingAway, 248 boolean keyguardOccluding, long duration, long statusBarAnimationStartTime, 249 long statusBarAnimationDuration) { 250 return 0; 251 } 252 253 /** 254 * Called when an app transition is finished running. 255 * 256 * @param token the token for app whose transition has finished 257 */ onAppTransitionFinishedLocked(IBinder token)258 public void onAppTransitionFinishedLocked(IBinder token) {} 259 } 260 261 /** 262 * An interface to be notified when the system bars for a task change. 263 */ 264 public interface TaskSystemBarsListener { 265 266 /** 267 * Called when the visibility of the system bars of a task change. 268 * 269 * @param taskId the identifier of the task. 270 * @param visible if the transient system bars are visible. 271 * @param wereRevealedFromSwipeOnSystemBar if the transient bars were revealed due to a 272 * swipe gesture on a system bar. 273 */ onTransientSystemBarsVisibilityChanged( int taskId, boolean visible, boolean wereRevealedFromSwipeOnSystemBar)274 void onTransientSystemBarsVisibilityChanged( 275 int taskId, 276 boolean visible, 277 boolean wereRevealedFromSwipeOnSystemBar); 278 } 279 280 /** 281 * An interface to be notified when keyguard exit animation should start. 282 */ 283 public interface KeyguardExitAnimationStartListener { 284 /** 285 * Called when keyguard exit animation should start. 286 * @param apps The list of apps to animate. 287 * @param wallpapers The list of wallpapers to animate. 288 * @param finishedCallback The callback to invoke when the animation is finished. 289 */ onAnimationStart(RemoteAnimationTarget[] apps, RemoteAnimationTarget[] wallpapers, IRemoteAnimationFinishedCallback finishedCallback)290 void onAnimationStart(RemoteAnimationTarget[] apps, 291 RemoteAnimationTarget[] wallpapers, 292 IRemoteAnimationFinishedCallback finishedCallback); 293 } 294 295 /** 296 * An interface to be notified about hardware keyboard status. 297 */ 298 public interface OnHardKeyboardStatusChangeListener { onHardKeyboardStatusChange(boolean available)299 public void onHardKeyboardStatusChange(boolean available); 300 } 301 302 /** 303 * An interface to customize drag and drop behaviors. 304 */ 305 public interface IDragDropCallback { registerInputChannel( DragState state, Display display, InputManagerService service, InputChannel source)306 default boolean registerInputChannel( 307 DragState state, Display display, InputManagerService service, 308 InputChannel source) { 309 state.register(display); 310 return service.transferTouchFocus(source, state.getInputChannel(), 311 true /* isDragDrop */); 312 } 313 314 /** 315 * Called when drag operation is starting. 316 */ prePerformDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data)317 default boolean prePerformDrag(IWindow window, IBinder dragToken, 318 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, 319 ClipData data) { 320 return true; 321 } 322 323 /** 324 * Called when drag operation is started. 325 */ postPerformDrag()326 default void postPerformDrag() {} 327 328 /** 329 * Called when drop result is being reported. 330 */ preReportDropResult(IWindow window, boolean consumed)331 default void preReportDropResult(IWindow window, boolean consumed) {} 332 333 /** 334 * Called when drop result was reported. 335 */ postReportDropResult()336 default void postReportDropResult() {} 337 338 /** 339 * Called when drag operation is being cancelled. 340 */ preCancelDragAndDrop(IBinder dragToken)341 default void preCancelDragAndDrop(IBinder dragToken) {} 342 343 /** 344 * Called when drag operation was cancelled. 345 */ postCancelDragAndDrop()346 default void postCancelDragAndDrop() {} 347 348 /** 349 * Called when it has entered a View that is willing to accept the drop. 350 */ dragRecipientEntered(IWindow window)351 default void dragRecipientEntered(IWindow window) {} 352 353 /** 354 * Called when it has exited a View that is willing to accept the drop. 355 */ dragRecipientExited(IWindow window)356 default void dragRecipientExited(IWindow window) {} 357 } 358 359 /** 360 * Request the interface to access features implemented by AccessibilityController. 361 */ getAccessibilityController()362 public abstract AccessibilityControllerInternal getAccessibilityController(); 363 364 /** 365 * Request that the window manager call 366 * {@link DisplayManagerInternal#performTraversalInTransactionFromWindowManager} 367 * within a surface transaction at a later time. 368 */ requestTraversalFromDisplayManager()369 public abstract void requestTraversalFromDisplayManager(); 370 371 /** 372 * Set by the accessibility layer to observe changes in the magnified region, 373 * rotation, and other window transformations related to display magnification 374 * as the window manager is responsible for doing the actual magnification 375 * and has access to the raw window data while the accessibility layer serves 376 * as a controller. 377 * 378 * @param displayId The logical display id. 379 * @param callbacks The callbacks to invoke. 380 * @return {@code false} if display id is not valid or an embedded display. 381 */ setMagnificationCallbacks(int displayId, @Nullable MagnificationCallbacks callbacks)382 public abstract boolean setMagnificationCallbacks(int displayId, 383 @Nullable MagnificationCallbacks callbacks); 384 385 /** 386 * Set by the accessibility layer to specify the magnification and panning to 387 * be applied to all windows that should be magnified. 388 * 389 * @param displayId The logical display id. 390 * @param spec The MagnficationSpec to set. 391 * 392 * @see #setMagnificationCallbacks(int, MagnificationCallbacks) 393 */ setMagnificationSpec(int displayId, MagnificationSpec spec)394 public abstract void setMagnificationSpec(int displayId, MagnificationSpec spec); 395 396 /** 397 * Set by the accessibility framework to indicate whether the magnifiable regions of the display 398 * should be shown. 399 * 400 * @param displayId The logical display id. 401 * @param show {@code true} to show magnifiable region bounds, {@code false} to hide 402 */ setForceShowMagnifiableBounds(int displayId, boolean show)403 public abstract void setForceShowMagnifiableBounds(int displayId, boolean show); 404 405 /** 406 * Obtains the magnification regions. 407 * 408 * @param displayId The logical display id. 409 * @param magnificationRegion the current magnification region 410 */ getMagnificationRegion(int displayId, @NonNull Region magnificationRegion)411 public abstract void getMagnificationRegion(int displayId, @NonNull Region magnificationRegion); 412 413 /** 414 * Sets a callback for observing which windows are touchable for the purposes 415 * of accessibility on specified display. 416 * 417 * @param displayId The logical display id. 418 * @param callback The callback. 419 */ setWindowsForAccessibilityCallback(int displayId, WindowsForAccessibilityCallback callback)420 public abstract void setWindowsForAccessibilityCallback(int displayId, 421 WindowsForAccessibilityCallback callback); 422 423 /** 424 * Sets a filter for manipulating the input event stream. 425 * 426 * @param filter The filter implementation. 427 */ setInputFilter(IInputFilter filter)428 public abstract void setInputFilter(IInputFilter filter); 429 430 /** 431 * Gets the token of the window that has input focus. 432 * 433 * @return The token. 434 */ getFocusedWindowToken()435 public abstract IBinder getFocusedWindowToken(); 436 437 /** 438 * Gets the token of the window that has input focus. It is from the focused 439 * {@link WindowState}. 440 * 441 * @return The token. 442 */ getFocusedWindowTokenFromWindowStates()443 public abstract IBinder getFocusedWindowTokenFromWindowStates(); 444 445 /** 446 * @return Whether the keyguard is engaged. 447 */ isKeyguardLocked()448 public abstract boolean isKeyguardLocked(); 449 450 /** 451 * @return Whether the keyguard is showing and not occluded. 452 */ isKeyguardShowingAndNotOccluded()453 public abstract boolean isKeyguardShowingAndNotOccluded(); 454 455 /** 456 * Gets the frame of a window given its token. 457 * 458 * @param token The token. 459 * @param outBounds The frame to populate. 460 */ getWindowFrame(IBinder token, Rect outBounds)461 public abstract void getWindowFrame(IBinder token, Rect outBounds); 462 463 /** 464 * Get the transformation matrix and MagnificationSpec given its token. 465 * 466 * @param token The token. 467 * @return The pair of the transformation matrix and magnification spec. 468 */ 469 // TODO (b/231663133): Long term solution for tracking window when the 470 // FLAG_RETRIEVE_INTERACTIVE_WINDOWS is unset. 471 public abstract Pair<Matrix, MagnificationSpec> getWindowTransformationMatrixAndMagnificationSpec(IBinder token)472 getWindowTransformationMatrixAndMagnificationSpec(IBinder token); 473 474 /** 475 * Opens the global actions dialog. 476 */ showGlobalActions()477 public abstract void showGlobalActions(); 478 479 /** 480 * Invalidate all visible windows on a given display, and report back on the callback when all 481 * windows have redrawn. 482 * 483 * @param callback reporting callback to be called when all windows have redrawn. 484 * @param timeout calls the callback anyway after the timeout. 485 * @param displayId waits for the windows on the given display, INVALID_DISPLAY to wait for all 486 * windows on all displays. 487 */ waitForAllWindowsDrawn(Runnable callback, long timeout, int displayId)488 public abstract void waitForAllWindowsDrawn(Runnable callback, long timeout, int displayId); 489 490 /** 491 * Overrides the display size. 492 * 493 * @param displayId The display to override the display size. 494 * @param width The width to override. 495 * @param height The height to override. 496 */ setForcedDisplaySize(int displayId, int width, int height)497 public abstract void setForcedDisplaySize(int displayId, int width, int height); 498 499 /** 500 * Recover the display size to real display size. 501 * 502 * @param displayId The display to recover the display size. 503 */ clearForcedDisplaySize(int displayId)504 public abstract void clearForcedDisplaySize(int displayId); 505 506 /** 507 * Adds a window token for a given window type. 508 * 509 * @param token The token to add. 510 * @param type The window type. 511 * @param displayId The display to add the token to. 512 * @param options A bundle used to pass window-related options. 513 */ addWindowToken(@onNull android.os.IBinder token, int type, int displayId, @Nullable Bundle options)514 public abstract void addWindowToken(@NonNull android.os.IBinder token, int type, int displayId, 515 @Nullable Bundle options); 516 517 /** 518 * Removes a window token. 519 * 520 * @param token The toke to remove. 521 * @param removeWindows Whether to also remove the windows associated with the token. 522 * @param displayId The display to remove the token from. 523 */ removeWindowToken(android.os.IBinder token, boolean removeWindows, int displayId)524 public final void removeWindowToken(android.os.IBinder token, boolean removeWindows, 525 int displayId) { 526 removeWindowToken(token, removeWindows, true /* animateExit */, displayId); 527 } 528 529 /** 530 * Removes a window token. 531 * 532 * @param token The toke to remove. 533 * @param removeWindows Whether to also remove the windows associated with the token. 534 * @param animateExit Whether to play the windows exit animation after the token removal. 535 * @param displayId The display to remove the token from. 536 */ removeWindowToken(android.os.IBinder token, boolean removeWindows, boolean animateExit, int displayId)537 public abstract void removeWindowToken(android.os.IBinder token, boolean removeWindows, 538 boolean animateExit, int displayId); 539 540 /** 541 * Registers a listener to be notified about app transition events. 542 * 543 * @param listener The listener to register. 544 */ registerAppTransitionListener(AppTransitionListener listener)545 public abstract void registerAppTransitionListener(AppTransitionListener listener); 546 547 /** 548 * Registers a listener to be notified to when the system bars of a task changes. 549 * 550 * @param listener The listener to register. 551 */ registerTaskSystemBarsListener(TaskSystemBarsListener listener)552 public abstract void registerTaskSystemBarsListener(TaskSystemBarsListener listener); 553 554 /** 555 * Registers a listener to be notified to when the system bars of a task changes. 556 * 557 * @param listener The listener to unregister. 558 */ unregisterTaskSystemBarsListener(TaskSystemBarsListener listener)559 public abstract void unregisterTaskSystemBarsListener(TaskSystemBarsListener listener); 560 561 /** 562 * Registers a listener to be notified to start the keyguard exit animation. 563 * 564 * @param listener The listener to register. 565 */ registerKeyguardExitAnimationStartListener( KeyguardExitAnimationStartListener listener)566 public abstract void registerKeyguardExitAnimationStartListener( 567 KeyguardExitAnimationStartListener listener); 568 569 /** 570 * Reports that the password for the given user has changed. 571 */ reportPasswordChanged(int userId)572 public abstract void reportPasswordChanged(int userId); 573 574 /** 575 * Retrieves a height of input method window for given display. 576 */ getInputMethodWindowVisibleHeight(int displayId)577 public abstract int getInputMethodWindowVisibleHeight(int displayId); 578 579 /** 580 * Notifies WindowManagerService that the expected back-button behavior might have changed. 581 * 582 * <p>Only {@link com.android.server.inputmethod.InputMethodManagerService} is the expected and 583 * tested caller of this method.</p> 584 * 585 * @param dismissImeOnBackKeyPressed {@code true} if the software keyboard is shown and the back 586 * key is expected to dismiss the software keyboard. 587 */ setDismissImeOnBackKeyPressed(boolean dismissImeOnBackKeyPressed)588 public abstract void setDismissImeOnBackKeyPressed(boolean dismissImeOnBackKeyPressed); 589 590 /** 591 * Notifies WindowManagerService that the current IME window status is being changed. 592 * 593 * <p>Only {@link com.android.server.inputmethod.InputMethodManagerService} is the expected and 594 * tested caller of this method.</p> 595 * 596 * @param imeToken token to track the active input method. Corresponding IME windows can be 597 * identified by checking {@link android.view.WindowManager.LayoutParams#token}. 598 * Note that there is no guarantee that the corresponding window is already 599 * created 600 * @param imeTargetWindowToken token to identify the target window that the IME is associated 601 * with 602 */ updateInputMethodTargetWindow(@onNull IBinder imeToken, @NonNull IBinder imeTargetWindowToken)603 public abstract void updateInputMethodTargetWindow(@NonNull IBinder imeToken, 604 @NonNull IBinder imeTargetWindowToken); 605 606 /** 607 * Returns true when the hardware keyboard is available. 608 */ isHardKeyboardAvailable()609 public abstract boolean isHardKeyboardAvailable(); 610 611 /** 612 * Sets the callback listener for hardware keyboard status changes. 613 * 614 * @param listener The listener to set. 615 */ setOnHardKeyboardStatusChangeListener( OnHardKeyboardStatusChangeListener listener)616 public abstract void setOnHardKeyboardStatusChangeListener( 617 OnHardKeyboardStatusChangeListener listener); 618 619 /** 620 * Requests the window manager to resend the windows for accessibility on specified display. 621 * 622 * @param displayId Display ID to be computed its windows for accessibility 623 */ computeWindowsForAccessibility(int displayId)624 public abstract void computeWindowsForAccessibility(int displayId); 625 626 /** 627 * Called after virtual display Id is updated by 628 * {@link com.android.server.vr.Vr2dDisplay} with a specific 629 * {@param vr2dDisplayId}. 630 */ setVr2dDisplayId(int vr2dDisplayId)631 public abstract void setVr2dDisplayId(int vr2dDisplayId); 632 633 /** 634 * Sets callback to DragDropController. 635 */ registerDragDropControllerCallback(IDragDropCallback callback)636 public abstract void registerDragDropControllerCallback(IDragDropCallback callback); 637 638 /** 639 * @see android.view.IWindowManager#lockNow 640 */ lockNow()641 public abstract void lockNow(); 642 643 /** 644 * Return the user that owns the given window, {@link android.os.UserHandle#USER_NULL} if 645 * the window token is not found. 646 */ getWindowOwnerUserId(IBinder windowToken)647 public abstract int getWindowOwnerUserId(IBinder windowToken); 648 649 /** 650 * Returns {@code true} if a Window owned by {@code uid} has focus. 651 */ isUidFocused(int uid)652 public abstract boolean isUidFocused(int uid); 653 654 /** 655 * Checks whether the specified IME client has IME focus or not. 656 * 657 * @param windowToken The window token of the input method client 658 * @param uid UID of the process to be queried 659 * @param pid PID of the process to be queried 660 * @param displayId Display ID reported from the client. Note that this method also verifies 661 * whether the specified process is allowed to access to this display or not 662 * @return {@code true} if the IME client specified with {@code uid}, {@code pid}, and 663 * {@code displayId} has IME focus 664 */ hasInputMethodClientFocus(IBinder windowToken, int uid, int pid, int displayId)665 public abstract @ImeClientFocusResult int hasInputMethodClientFocus(IBinder windowToken, 666 int uid, int pid, int displayId); 667 668 @Retention(SOURCE) 669 @IntDef({ 670 ImeClientFocusResult.HAS_IME_FOCUS, 671 ImeClientFocusResult.NOT_IME_TARGET_WINDOW, 672 ImeClientFocusResult.DISPLAY_ID_MISMATCH, 673 ImeClientFocusResult.INVALID_DISPLAY_ID 674 }) 675 public @interface ImeClientFocusResult { 676 int HAS_IME_FOCUS = 0; 677 int NOT_IME_TARGET_WINDOW = -1; 678 int DISPLAY_ID_MISMATCH = -2; 679 int INVALID_DISPLAY_ID = -3; 680 } 681 682 /** 683 * Checks whether the given {@code uid} is allowed to use the given {@code displayId} or not. 684 * 685 * @param displayId Display ID to be checked 686 * @param uid UID to be checked. 687 * @return {@code true} if the given {@code uid} is allowed to use the given {@code displayId} 688 */ isUidAllowedOnDisplay(int displayId, int uid)689 public abstract boolean isUidAllowedOnDisplay(int displayId, int uid); 690 691 /** 692 * Return the display Id for given window. 693 */ getDisplayIdForWindow(IBinder windowToken)694 public abstract int getDisplayIdForWindow(IBinder windowToken); 695 696 /** 697 * @return The top focused display ID. 698 */ getTopFocusedDisplayId()699 public abstract int getTopFocusedDisplayId(); 700 701 /** 702 * @return The UI context of top focused display. 703 */ getTopFocusedDisplayUiContext()704 public abstract Context getTopFocusedDisplayUiContext(); 705 706 /** 707 * Checks if this display is configured and allowed to show system decorations. 708 */ shouldShowSystemDecorOnDisplay(int displayId)709 public abstract boolean shouldShowSystemDecorOnDisplay(int displayId); 710 711 /** 712 * Indicates the policy for how the display should show IME. 713 * 714 * @param displayId The id of the display. 715 * @return The policy for how the display should show IME. 716 */ getDisplayImePolicy(int displayId)717 public abstract @DisplayImePolicy int getDisplayImePolicy(int displayId); 718 719 /** 720 * Show IME on imeTargetWindow once IME has finished layout. 721 * 722 * @param imeTargetWindowToken token of the (IME target) window on which IME should be shown. 723 */ showImePostLayout(IBinder imeTargetWindowToken)724 public abstract void showImePostLayout(IBinder imeTargetWindowToken); 725 726 /** 727 * Hide IME using imeTargetWindow when requested. 728 * 729 * @param imeTargetWindowToken token of the (IME target) window on which IME should be hidden. 730 * @param displayId the id of the display the IME is on. 731 */ hideIme(IBinder imeTargetWindowToken, int displayId)732 public abstract void hideIme(IBinder imeTargetWindowToken, int displayId); 733 734 /** 735 * Tell window manager about a package that should be running with a restricted range of 736 * refresh rate setting until removeRefreshRateRangeForPackage is called for the same package. 737 * 738 * This must not be called again for the same package. 739 */ addRefreshRateRangeForPackage(@onNull String packageName, float minRefreshRate, float maxRefreshRate)740 public abstract void addRefreshRateRangeForPackage(@NonNull String packageName, 741 float minRefreshRate, float maxRefreshRate); 742 743 /** 744 * Tell window manager to stop constraining refresh rate for the given package. 745 */ removeRefreshRateRangeForPackage(@onNull String packageName)746 public abstract void removeRefreshRateRangeForPackage(@NonNull String packageName); 747 748 /** 749 * Checks if the device supports touch or faketouch. 750 */ isTouchOrFaketouchDevice()751 public abstract boolean isTouchOrFaketouchDevice(); 752 753 /** 754 * Returns the info associated with the input token used to determine if a key should be 755 * intercepted. This info can be accessed without holding the global wm lock. 756 */ 757 public abstract @Nullable KeyInterceptionInfo getKeyInterceptionInfoFromToken(IBinder inputToken)758 getKeyInterceptionInfoFromToken(IBinder inputToken); 759 760 /** 761 * Clears the snapshot cache of running activities so they show the splash-screen 762 * the next time the activities are opened. 763 */ clearSnapshotCache()764 public abstract void clearSnapshotCache(); 765 766 /** 767 * Assigns accessibility ID a window surface as a layer metadata. 768 */ setAccessibilityIdToSurfaceMetadata( IBinder windowToken, int accessibilityWindowId)769 public abstract void setAccessibilityIdToSurfaceMetadata( 770 IBinder windowToken, int accessibilityWindowId); 771 772 /** 773 * 774 * Returns the window name associated to the given binder. 775 * 776 * @param binder The {@link IBinder} object 777 * @return The corresponding {@link WindowState#getName()} 778 */ getWindowName(@onNull IBinder binder)779 public abstract String getWindowName(@NonNull IBinder binder); 780 781 /** 782 * The callback after the request of show/hide input method is sent. 783 * 784 * @param show Whether to show or hide input method. 785 * @param focusedToken The token of focused window. 786 * @param requestToken The token of window who requests the change. 787 * @param displayId The ID of the display which input method is currently focused. 788 * @return The information of the input method target. 789 */ onToggleImeRequested(boolean show, @NonNull IBinder focusedToken, @NonNull IBinder requestToken, int displayId)790 public abstract ImeTargetInfo onToggleImeRequested(boolean show, 791 @NonNull IBinder focusedToken, @NonNull IBinder requestToken, int displayId); 792 793 /** The information of input method target when IME is requested to show or hide. */ 794 public static class ImeTargetInfo { 795 public final String focusedWindowName; 796 public final String requestWindowName; 797 798 /** The window name of IME Insets control target. */ 799 public final String imeControlTargetName; 800 801 /** 802 * The current window name of the input method is on top of. 803 * <p> 804 * Note that the concept of this window is only used to reparent the target window behind 805 * the input method window, it may be different from the window reported by 806 * {@link com.android.server.inputmethod.InputMethodManagerService#reportStartInput} which 807 * has input connection. 808 */ 809 public final String imeLayerTargetName; 810 ImeTargetInfo(String focusedWindowName, String requestWindowName, String imeControlTargetName, String imeLayerTargetName)811 public ImeTargetInfo(String focusedWindowName, String requestWindowName, 812 String imeControlTargetName, String imeLayerTargetName) { 813 this.focusedWindowName = focusedWindowName; 814 this.requestWindowName = requestWindowName; 815 this.imeControlTargetName = imeControlTargetName; 816 this.imeLayerTargetName = imeLayerTargetName; 817 } 818 } 819 820 /** 821 * Moves the {@link WindowToken} {@code binder} to the display specified by {@code displayId}. 822 */ moveWindowTokenToDisplay(IBinder binder, int displayId)823 public abstract void moveWindowTokenToDisplay(IBinder binder, int displayId); 824 825 /** 826 * Checks whether the given window should restore the last IME visibility. 827 * 828 * @param imeTargetWindowToken The token of the (IME target) window 829 * @return {@code true} when the system allows to restore the IME visibility, 830 * {@code false} otherwise. 831 */ shouldRestoreImeVisibility(IBinder imeTargetWindowToken)832 public abstract boolean shouldRestoreImeVisibility(IBinder imeTargetWindowToken); 833 834 /** 835 * Internal methods for other parts of SystemServer to manage 836 * SurfacePackage based overlays on tasks. 837 * 838 * Since these overlays will overlay application content, they exist 839 * in a container with setTrustedOverlay(true). This means its imperative 840 * that this overlay feature only be used with UI completely under the control 841 * of the system, without 3rd party content. 842 * 843 * Callers prepare a view hierarchy with SurfaceControlViewHost 844 * and send the package to WM here. The remote view hierarchy will receive 845 * configuration change, lifecycle events, etc, forwarded over the 846 * ISurfaceControlViewHost interface inside the SurfacePackage. Embedded 847 * hierarchies will receive inset changes, including transient inset changes 848 * (to avoid the status bar in immersive mode). 849 * 850 * The embedded hierarchy exists in a coordinate space relative to the task 851 * bounds. 852 */ addTrustedTaskOverlay(int taskId, SurfaceControlViewHost.SurfacePackage overlay)853 public abstract void addTrustedTaskOverlay(int taskId, 854 SurfaceControlViewHost.SurfacePackage overlay); removeTrustedTaskOverlay(int taskId, SurfaceControlViewHost.SurfacePackage overlay)855 public abstract void removeTrustedTaskOverlay(int taskId, 856 SurfaceControlViewHost.SurfacePackage overlay); 857 858 /** 859 * Get a SurfaceControl that is the container layer that should be used to receive input to 860 * support handwriting (Scribe) by the IME. 861 */ getHandwritingSurfaceForDisplay(int displayId)862 public abstract SurfaceControl getHandwritingSurfaceForDisplay(int displayId); 863 864 /** 865 * Returns {@code true} if the given point is within the window bounds of the given window. 866 * 867 * @param windowToken the window whose bounds should be used for the hit test. 868 * @param displayX the x coordinate of the test point in the display's coordinate space. 869 * @param displayY the y coordinate of the test point in the display's coordinate space. 870 */ isPointInsideWindow( @onNull IBinder windowToken, int displayId, float displayX, float displayY)871 public abstract boolean isPointInsideWindow( 872 @NonNull IBinder windowToken, int displayId, float displayX, float displayY); 873 874 /** 875 * Updates the content recording session. If a different session is already in progress, then 876 * the pre-existing session is stopped, and the new incoming session takes over. 877 * 878 * The DisplayContent for the new session will begin recording when 879 * {@link RootWindowContainer#onDisplayChanged} is invoked for the new {@link VirtualDisplay}. 880 * Must be invoked for a valid MediaProjection session. 881 * 882 * @param incomingSession the nullable incoming content recording session 883 * @return {@code true} if successfully set the session, or {@code false} if the session 884 * could not be prepared and the session needs to be torn down. 885 */ setContentRecordingSession(ContentRecordingSession incomingSession)886 public abstract boolean setContentRecordingSession(ContentRecordingSession incomingSession); 887 } 888