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