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 android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.ClipData; 22 import android.content.Context; 23 import android.graphics.Rect; 24 import android.graphics.Region; 25 import android.hardware.display.DisplayManagerInternal; 26 import android.os.IBinder; 27 import android.view.Display; 28 import android.view.IInputFilter; 29 import android.view.IWindow; 30 import android.view.InputChannel; 31 import android.view.MagnificationSpec; 32 import android.view.WindowInfo; 33 34 import com.android.internal.policy.KeyInterceptionInfo; 35 import com.android.server.input.InputManagerService; 36 import com.android.server.policy.WindowManagerPolicy; 37 38 import java.util.List; 39 40 /** 41 * Window manager local system service interface. 42 * 43 * @hide Only for use within the system server. 44 */ 45 public abstract class WindowManagerInternal { 46 47 /** 48 * Interface to receive a callback when the windows reported for 49 * accessibility changed. 50 */ 51 public interface WindowsForAccessibilityCallback { 52 53 /** 54 * Called when the windows for accessibility changed. 55 * 56 * @param forceSend Send the windows for accessibility even if they haven't changed. 57 * @param topFocusedDisplayId The display Id which has the top focused window. 58 * @param topFocusedWindowToken The window token of top focused window. 59 * @param windows The windows for accessibility. 60 */ onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId, IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows)61 void onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId, 62 IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows); 63 } 64 65 /** 66 * Callbacks for contextual changes that affect the screen magnification 67 * feature. 68 */ 69 public interface MagnificationCallbacks { 70 71 /** 72 * Called when the region where magnification operates changes. Note that this isn't the 73 * entire screen. For example, IMEs are not magnified. 74 * 75 * @param magnificationRegion the current magnification region 76 */ onMagnificationRegionChanged(Region magnificationRegion)77 public void onMagnificationRegionChanged(Region magnificationRegion); 78 79 /** 80 * Called when an application requests a rectangle on the screen to allow 81 * the client to apply the appropriate pan and scale. 82 * 83 * @param left The rectangle left. 84 * @param top The rectangle top. 85 * @param right The rectangle right. 86 * @param bottom The rectangle bottom. 87 */ onRectangleOnScreenRequested(int left, int top, int right, int bottom)88 public void onRectangleOnScreenRequested(int left, int top, int right, int bottom); 89 90 /** 91 * Notifies that the rotation changed. 92 * 93 * @param rotation The current rotation. 94 */ onRotationChanged(int rotation)95 public void onRotationChanged(int rotation); 96 97 /** 98 * Notifies that the context of the user changed. For example, an application 99 * was started. 100 */ onUserContextChanged()101 public void onUserContextChanged(); 102 } 103 104 /** 105 * Abstract class to be notified about {@link com.android.server.wm.AppTransition} events. Held 106 * as an abstract class so a listener only needs to implement the methods of its interest. 107 */ 108 public static abstract class AppTransitionListener { 109 110 /** 111 * Called when an app transition is being setup and about to be executed. 112 */ onAppTransitionPendingLocked()113 public void onAppTransitionPendingLocked() {} 114 115 /** 116 * Called when a pending app transition gets cancelled. 117 * 118 * @param transit transition type indicating what kind of transition got cancelled 119 */ onAppTransitionCancelledLocked(int transit)120 public void onAppTransitionCancelledLocked(int transit) {} 121 122 /** 123 * Called when an app transition is timed out. 124 */ onAppTransitionTimeoutLocked()125 public void onAppTransitionTimeoutLocked() {} 126 127 /** 128 * Called when an app transition gets started 129 * 130 * @param transit transition type indicating what kind of transition gets run, must be one 131 * of AppTransition.TRANSIT_* values 132 * @param duration the total duration of the transition 133 * @param statusBarAnimationStartTime the desired start time for all visual animations in 134 * the status bar caused by this app transition in uptime millis 135 * @param statusBarAnimationDuration the duration for all visual animations in the status 136 * bar caused by this app transition in millis 137 * 138 * @return Return any bit set of {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_LAYOUT}, 139 * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_CONFIG}, 140 * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_WALLPAPER}, 141 * or {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_ANIM}. 142 */ onAppTransitionStartingLocked(int transit, long duration, long statusBarAnimationStartTime, long statusBarAnimationDuration)143 public int onAppTransitionStartingLocked(int transit, long duration, 144 long statusBarAnimationStartTime, long statusBarAnimationDuration) { 145 return 0; 146 } 147 148 /** 149 * Called when an app transition is finished running. 150 * 151 * @param token the token for app whose transition has finished 152 */ onAppTransitionFinishedLocked(IBinder token)153 public void onAppTransitionFinishedLocked(IBinder token) {} 154 } 155 156 /** 157 * An interface to be notified about hardware keyboard status. 158 */ 159 public interface OnHardKeyboardStatusChangeListener { onHardKeyboardStatusChange(boolean available)160 public void onHardKeyboardStatusChange(boolean available); 161 } 162 163 /** 164 * An interface to customize drag and drop behaviors. 165 */ 166 public interface IDragDropCallback { registerInputChannel( DragState state, Display display, InputManagerService service, InputChannel source)167 default boolean registerInputChannel( 168 DragState state, Display display, InputManagerService service, 169 InputChannel source) { 170 state.register(display); 171 return service.transferTouchFocus(source, state.getInputChannel()); 172 } 173 174 /** 175 * Called when drag operation is starting. 176 */ prePerformDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data)177 default boolean prePerformDrag(IWindow window, IBinder dragToken, 178 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, 179 ClipData data) { 180 return true; 181 } 182 183 /** 184 * Called when drag operation is started. 185 */ postPerformDrag()186 default void postPerformDrag() {} 187 188 /** 189 * Called when drop result is being reported. 190 */ preReportDropResult(IWindow window, boolean consumed)191 default void preReportDropResult(IWindow window, boolean consumed) {} 192 193 /** 194 * Called when drop result was reported. 195 */ postReportDropResult()196 default void postReportDropResult() {} 197 198 /** 199 * Called when drag operation is being cancelled. 200 */ preCancelDragAndDrop(IBinder dragToken)201 default void preCancelDragAndDrop(IBinder dragToken) {} 202 203 /** 204 * Called when drag operation was cancelled. 205 */ postCancelDragAndDrop()206 default void postCancelDragAndDrop() {} 207 } 208 209 /** 210 * Request that the window manager call 211 * {@link DisplayManagerInternal#performTraversalInTransactionFromWindowManager} 212 * within a surface transaction at a later time. 213 */ requestTraversalFromDisplayManager()214 public abstract void requestTraversalFromDisplayManager(); 215 216 /** 217 * Set by the accessibility layer to observe changes in the magnified region, 218 * rotation, and other window transformations related to display magnification 219 * as the window manager is responsible for doing the actual magnification 220 * and has access to the raw window data while the accessibility layer serves 221 * as a controller. 222 * 223 * @param displayId The logical display id. 224 * @param callbacks The callbacks to invoke. 225 * @return {@code false} if display id is not valid or an embedded display. 226 */ setMagnificationCallbacks(int displayId, @Nullable MagnificationCallbacks callbacks)227 public abstract boolean setMagnificationCallbacks(int displayId, 228 @Nullable MagnificationCallbacks callbacks); 229 230 /** 231 * Set by the accessibility layer to specify the magnification and panning to 232 * be applied to all windows that should be magnified. 233 * 234 * @param displayId The logical display id. 235 * @param spec The MagnficationSpec to set. 236 * 237 * @see #setMagnificationCallbacks(int, MagnificationCallbacks) 238 */ setMagnificationSpec(int displayId, MagnificationSpec spec)239 public abstract void setMagnificationSpec(int displayId, MagnificationSpec spec); 240 241 /** 242 * Set by the accessibility framework to indicate whether the magnifiable regions of the display 243 * should be shown. 244 * 245 * @param displayId The logical display id. 246 * @param show {@code true} to show magnifiable region bounds, {@code false} to hide 247 */ setForceShowMagnifiableBounds(int displayId, boolean show)248 public abstract void setForceShowMagnifiableBounds(int displayId, boolean show); 249 250 /** 251 * Obtains the magnification regions. 252 * 253 * @param displayId The logical display id. 254 * @param magnificationRegion the current magnification region 255 */ getMagnificationRegion(int displayId, @NonNull Region magnificationRegion)256 public abstract void getMagnificationRegion(int displayId, @NonNull Region magnificationRegion); 257 258 /** 259 * Gets the magnification and translation applied to a window given its token. 260 * Not all windows are magnified and the window manager policy determines which 261 * windows are magnified. The returned result also takes into account the compat 262 * scale if necessary. 263 * 264 * @param windowToken The window's token. 265 * 266 * @return The magnification spec for the window. 267 * 268 * @see #setMagnificationCallbacks(int, MagnificationCallbacks) 269 */ getCompatibleMagnificationSpecForWindow( IBinder windowToken)270 public abstract MagnificationSpec getCompatibleMagnificationSpecForWindow( 271 IBinder windowToken); 272 273 /** 274 * Sets a callback for observing which windows are touchable for the purposes 275 * of accessibility on specified display. 276 * 277 * @param displayId The logical display id. 278 * @param callback The callback. 279 * @return {@code false} if display id is not valid. 280 */ setWindowsForAccessibilityCallback(int displayId, WindowsForAccessibilityCallback callback)281 public abstract boolean setWindowsForAccessibilityCallback(int displayId, 282 WindowsForAccessibilityCallback callback); 283 284 /** 285 * Sets a filter for manipulating the input event stream. 286 * 287 * @param filter The filter implementation. 288 */ setInputFilter(IInputFilter filter)289 public abstract void setInputFilter(IInputFilter filter); 290 291 /** 292 * Gets the token of the window that has input focus. 293 * 294 * @return The token. 295 */ getFocusedWindowToken()296 public abstract IBinder getFocusedWindowToken(); 297 298 /** 299 * @return Whether the keyguard is engaged. 300 */ isKeyguardLocked()301 public abstract boolean isKeyguardLocked(); 302 303 /** 304 * @return Whether the keyguard is showing and not occluded. 305 */ isKeyguardShowingAndNotOccluded()306 public abstract boolean isKeyguardShowingAndNotOccluded(); 307 308 /** 309 * Gets the frame of a window given its token. 310 * 311 * @param token The token. 312 * @param outBounds The frame to populate. 313 */ getWindowFrame(IBinder token, Rect outBounds)314 public abstract void getWindowFrame(IBinder token, Rect outBounds); 315 316 /** 317 * Opens the global actions dialog. 318 */ showGlobalActions()319 public abstract void showGlobalActions(); 320 321 /** 322 * Invalidate all visible windows on a given display, and report back on the callback when all 323 * windows have redrawn. 324 * 325 * @param callback reporting callback to be called when all windows have redrawn. 326 * @param timeout calls the callback anyway after the timeout. 327 * @param displayId waits for the windows on the given display, INVALID_DISPLAY to wait for all 328 * windows on all displays. 329 */ waitForAllWindowsDrawn(Runnable callback, long timeout, int displayId)330 public abstract void waitForAllWindowsDrawn(Runnable callback, long timeout, int displayId); 331 332 /** 333 * Overrides the display size. 334 * 335 * @param displayId The display to override the display size. 336 * @param width The width to override. 337 * @param height The height to override. 338 */ setForcedDisplaySize(int displayId, int width, int height)339 public abstract void setForcedDisplaySize(int displayId, int width, int height); 340 341 /** 342 * Recover the display size to real display size. 343 * 344 * @param displayId The display to recover the display size. 345 */ clearForcedDisplaySize(int displayId)346 public abstract void clearForcedDisplaySize(int displayId); 347 348 /** 349 * Adds a window token for a given window type. 350 * 351 * @param token The token to add. 352 * @param type The window type. 353 * @param displayId The display to add the token to. 354 */ addWindowToken(android.os.IBinder token, int type, int displayId)355 public abstract void addWindowToken(android.os.IBinder token, int type, int displayId); 356 357 /** 358 * Removes a window token. 359 * 360 * @param token The toke to remove. 361 * @param removeWindows Whether to also remove the windows associated with the token. 362 * @param displayId The display to remove the token from. 363 */ removeWindowToken(android.os.IBinder token, boolean removeWindows, int displayId)364 public abstract void removeWindowToken(android.os.IBinder token, boolean removeWindows, 365 int displayId); 366 367 /** 368 * Registers a listener to be notified about app transition events. 369 * 370 * @param listener The listener to register. 371 */ registerAppTransitionListener(AppTransitionListener listener)372 public abstract void registerAppTransitionListener(AppTransitionListener listener); 373 374 /** 375 * Reports that the password for the given user has changed. 376 */ reportPasswordChanged(int userId)377 public abstract void reportPasswordChanged(int userId); 378 379 /** 380 * Retrieves a height of input method window for given display. 381 */ getInputMethodWindowVisibleHeight(int displayId)382 public abstract int getInputMethodWindowVisibleHeight(int displayId); 383 384 /** 385 * Notifies WindowManagerService that the current IME window status is being changed. 386 * 387 * <p>Only {@link com.android.server.inputmethod.InputMethodManagerService} is the expected and 388 * tested caller of this method.</p> 389 * 390 * @param imeToken token to track the active input method. Corresponding IME windows can be 391 * identified by checking {@link android.view.WindowManager.LayoutParams#token}. 392 * Note that there is no guarantee that the corresponding window is already 393 * created 394 * @param imeWindowVisible whether the active IME thinks that its window should be visible or 395 * hidden, no matter how WindowManagerService will react / has reacted 396 * to corresponding API calls. Note that this state is not guaranteed 397 * to be synchronized with state in WindowManagerService. 398 * @param dismissImeOnBackKeyPressed {@code true} if the software keyboard is shown and the back 399 * key is expected to dismiss the software keyboard. 400 */ updateInputMethodWindowStatus(@onNull IBinder imeToken, boolean imeWindowVisible, boolean dismissImeOnBackKeyPressed)401 public abstract void updateInputMethodWindowStatus(@NonNull IBinder imeToken, 402 boolean imeWindowVisible, boolean dismissImeOnBackKeyPressed); 403 404 /** 405 * Notifies WindowManagerService that the current IME window status is being changed. 406 * 407 * <p>Only {@link com.android.server.inputmethod.InputMethodManagerService} is the expected and 408 * tested caller of this method.</p> 409 * 410 * @param imeToken token to track the active input method. Corresponding IME windows can be 411 * identified by checking {@link android.view.WindowManager.LayoutParams#token}. 412 * Note that there is no guarantee that the corresponding window is already 413 * created 414 * @param imeTargetWindowToken token to identify the target window that the IME is associated 415 * with 416 */ updateInputMethodTargetWindow(@onNull IBinder imeToken, @NonNull IBinder imeTargetWindowToken)417 public abstract void updateInputMethodTargetWindow(@NonNull IBinder imeToken, 418 @NonNull IBinder imeTargetWindowToken); 419 420 /** 421 * Returns true when the hardware keyboard is available. 422 */ isHardKeyboardAvailable()423 public abstract boolean isHardKeyboardAvailable(); 424 425 /** 426 * Sets the callback listener for hardware keyboard status changes. 427 * 428 * @param listener The listener to set. 429 */ setOnHardKeyboardStatusChangeListener( OnHardKeyboardStatusChangeListener listener)430 public abstract void setOnHardKeyboardStatusChangeListener( 431 OnHardKeyboardStatusChangeListener listener); 432 433 /** Returns true if a stack in the windowing mode is currently visible. */ isStackVisibleLw(int windowingMode)434 public abstract boolean isStackVisibleLw(int windowingMode); 435 436 /** 437 * Requests the window manager to resend the windows for accessibility on specified display. 438 * 439 * @param displayId Display ID to be computed its windows for accessibility 440 */ computeWindowsForAccessibility(int displayId)441 public abstract void computeWindowsForAccessibility(int displayId); 442 443 /** 444 * Called after virtual display Id is updated by 445 * {@link com.android.server.vr.Vr2dDisplay} with a specific 446 * {@param vr2dDisplayId}. 447 */ setVr2dDisplayId(int vr2dDisplayId)448 public abstract void setVr2dDisplayId(int vr2dDisplayId); 449 450 /** 451 * Sets callback to DragDropController. 452 */ registerDragDropControllerCallback(IDragDropCallback callback)453 public abstract void registerDragDropControllerCallback(IDragDropCallback callback); 454 455 /** 456 * @see android.view.IWindowManager#lockNow 457 */ lockNow()458 public abstract void lockNow(); 459 460 /** 461 * Return the user that owns the given window, {@link android.os.UserHandle#USER_NULL} if 462 * the window token is not found. 463 */ getWindowOwnerUserId(IBinder windowToken)464 public abstract int getWindowOwnerUserId(IBinder windowToken); 465 466 /** 467 * Returns {@code true} if a Window owned by {@code uid} has focus. 468 */ isUidFocused(int uid)469 public abstract boolean isUidFocused(int uid); 470 471 /** 472 * Checks whether the specified IME client has IME focus or not. 473 * 474 * @param uid UID of the process to be queried 475 * @param pid PID of the process to be queried 476 * @param displayId Display ID reported from the client. Note that this method also verifies 477 * whether the specified process is allowed to access to this display or not 478 * @return {@code true} if the IME client specified with {@code uid}, {@code pid}, and 479 * {@code displayId} has IME focus 480 */ isInputMethodClientFocus(int uid, int pid, int displayId)481 public abstract boolean isInputMethodClientFocus(int uid, int pid, int displayId); 482 483 /** 484 * Checks whether the given {@code uid} is allowed to use the given {@code displayId} or not. 485 * 486 * @param displayId Display ID to be checked 487 * @param uid UID to be checked. 488 * @return {@code true} if the given {@code uid} is allowed to use the given {@code displayId} 489 */ isUidAllowedOnDisplay(int displayId, int uid)490 public abstract boolean isUidAllowedOnDisplay(int displayId, int uid); 491 492 /** 493 * Return the display Id for given window. 494 */ getDisplayIdForWindow(IBinder windowToken)495 public abstract int getDisplayIdForWindow(IBinder windowToken); 496 497 /** 498 * @return The top focused display ID. 499 */ getTopFocusedDisplayId()500 public abstract int getTopFocusedDisplayId(); 501 502 /** 503 * @return The UI context of top focused display. 504 */ getTopFocusedDisplayUiContext()505 public abstract Context getTopFocusedDisplayUiContext(); 506 507 /** 508 * Checks if this display is configured and allowed to show system decorations. 509 */ shouldShowSystemDecorOnDisplay(int displayId)510 public abstract boolean shouldShowSystemDecorOnDisplay(int displayId); 511 512 /** 513 * Indicates that the display should show IME. 514 * 515 * @param displayId The id of the display. 516 * @return {@code true} if the display should show IME when an input field become focused on it. 517 */ shouldShowIme(int displayId)518 public abstract boolean shouldShowIme(int displayId); 519 520 /** 521 * Show IME on imeTargetWindow once IME has finished layout. 522 * 523 * @param imeTargetWindowToken token of the (IME target) window on which IME should be shown. 524 */ showImePostLayout(IBinder imeTargetWindowToken)525 public abstract void showImePostLayout(IBinder imeTargetWindowToken); 526 527 /** 528 * Hide IME using imeTargetWindow when requested. 529 * 530 * @param imeTargetWindowToken token of the (IME target) window on which IME should be hidden. 531 * @param displayId the id of the display the IME is on. 532 */ hideIme(IBinder imeTargetWindowToken, int displayId)533 public abstract void hideIme(IBinder imeTargetWindowToken, int displayId); 534 535 /** 536 * Tell window manager about a package that should not be running with high refresh rate 537 * setting until removeNonHighRefreshRatePackage is called for the same package. 538 * 539 * This must not be called again for the same package. 540 */ addNonHighRefreshRatePackage(@onNull String packageName)541 public abstract void addNonHighRefreshRatePackage(@NonNull String packageName); 542 543 /** 544 * Tell window manager to stop constraining refresh rate for the given package. 545 */ removeNonHighRefreshRatePackage(@onNull String packageName)546 public abstract void removeNonHighRefreshRatePackage(@NonNull String packageName); 547 548 /** 549 * Checks if this display is touchable. 550 */ isTouchableDisplay(int displayId)551 public abstract boolean isTouchableDisplay(int displayId); 552 553 /** 554 * Returns the info associated with the input token used to determine if a key should be 555 * intercepted. This info can be accessed without holding the global wm lock. 556 */ 557 public abstract @Nullable KeyInterceptionInfo getKeyInterceptionInfoFromToken(IBinder inputToken)558 getKeyInterceptionInfoFromToken(IBinder inputToken); 559 560 /** 561 * Clears the snapshot cache of running activities so they show the splash-screen 562 * the next time the activities are opened. 563 */ clearSnapshotCache()564 public abstract void clearSnapshotCache(); 565 566 /** 567 * Assigns accessibility ID a window surface as a layer metadata. 568 */ setAccessibilityIdToSurfaceMetadata( IBinder windowToken, int accessibilityWindowId)569 public abstract void setAccessibilityIdToSurfaceMetadata( 570 IBinder windowToken, int accessibilityWindowId); 571 572 /** 573 * 574 * Returns the window name associated to the given binder. 575 * 576 * @param binder The {@link IBinder} object 577 * @return The corresponding {@link WindowState#getName()} 578 */ getWindowName(@onNull IBinder binder)579 public abstract String getWindowName(@NonNull IBinder binder); 580 581 /** 582 * Return the window name of IME Insets control target. 583 * 584 * @param displayId The ID of the display which input method is currently focused. 585 * @return The corresponding {@link WindowState#getName()} 586 */ getImeControlTargetNameForLogging(int displayId)587 public abstract @Nullable String getImeControlTargetNameForLogging(int displayId); 588 589 /** 590 * Return the current window name of the input method is on top of. 591 * 592 * Note that the concept of this window is only reparent the target window behind the input 593 * method window, it may different with the window which reported by 594 * {@code InputMethodManagerService#reportStartInput} which has input connection. 595 * 596 * @param displayId The ID of the display which input method is currently focused. 597 * @return The corresponding {@link WindowState#getName()} 598 */ getImeTargetNameForLogging(int displayId)599 public abstract @Nullable String getImeTargetNameForLogging(int displayId); 600 } 601