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