• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.mTransferTouchFromToken = source.getToken();
160             state.register(display);
161             return true;
162         }
163 
164         /**
165          * Called when drag operation is starting.
166          */
prePerformDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data)167         default boolean prePerformDrag(IWindow window, IBinder dragToken,
168                 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY,
169                 ClipData data) {
170             return true;
171         }
172 
173         /**
174          * Called when drag operation is started.
175          */
postPerformDrag()176         default void postPerformDrag() {}
177 
178         /**
179          * Called when drop result is being reported.
180          */
preReportDropResult(IWindow window, boolean consumed)181         default void preReportDropResult(IWindow window, boolean consumed) {}
182 
183         /**
184          * Called when drop result was reported.
185          */
postReportDropResult()186         default void postReportDropResult() {}
187 
188         /**
189          * Called when drag operation is being cancelled.
190          */
preCancelDragAndDrop(IBinder dragToken)191         default void preCancelDragAndDrop(IBinder dragToken) {}
192 
193         /**
194          * Called when drag operation was cancelled.
195          */
postCancelDragAndDrop()196         default void postCancelDragAndDrop() {}
197     }
198 
199     /**
200      * Request that the window manager call
201      * {@link DisplayManagerInternal#performTraversalInTransactionFromWindowManager}
202      * within a surface transaction at a later time.
203      */
requestTraversalFromDisplayManager()204     public abstract void requestTraversalFromDisplayManager();
205 
206     /**
207      * Set by the accessibility layer to observe changes in the magnified region,
208      * rotation, and other window transformations related to display magnification
209      * as the window manager is responsible for doing the actual magnification
210      * and has access to the raw window data while the accessibility layer serves
211      * as a controller.
212      *
213      * @param displayId The logical display id.
214      * @param callbacks The callbacks to invoke.
215      * @return {@code false} if display id is not valid.
216      */
setMagnificationCallbacks(int displayId, @Nullable MagnificationCallbacks callbacks)217     public abstract boolean setMagnificationCallbacks(int displayId,
218             @Nullable MagnificationCallbacks callbacks);
219 
220     /**
221      * Set by the accessibility layer to specify the magnification and panning to
222      * be applied to all windows that should be magnified.
223      *
224      * @param displayId The logical display id.
225      * @param spec The MagnficationSpec to set.
226      *
227      * @see #setMagnificationCallbacks(int, MagnificationCallbacks)
228      */
setMagnificationSpec(int displayId, MagnificationSpec spec)229     public abstract void setMagnificationSpec(int displayId, MagnificationSpec spec);
230 
231     /**
232      * Set by the accessibility framework to indicate whether the magnifiable regions of the display
233      * should be shown.
234      *
235      * @param displayId The logical display id.
236      * @param show {@code true} to show magnifiable region bounds, {@code false} to hide
237      */
setForceShowMagnifiableBounds(int displayId, boolean show)238     public abstract void setForceShowMagnifiableBounds(int displayId, boolean show);
239 
240     /**
241      * Obtains the magnification regions.
242      *
243      * @param displayId The logical display id.
244      * @param magnificationRegion the current magnification region
245      */
getMagnificationRegion(int displayId, @NonNull Region magnificationRegion)246     public abstract void getMagnificationRegion(int displayId, @NonNull Region magnificationRegion);
247 
248     /**
249      * Gets the magnification and translation applied to a window given its token.
250      * Not all windows are magnified and the window manager policy determines which
251      * windows are magnified. The returned result also takes into account the compat
252      * scale if necessary.
253      *
254      * @param windowToken The window's token.
255      *
256      * @return The magnification spec for the window.
257      *
258      * @see #setMagnificationCallbacks(int, MagnificationCallbacks)
259      */
getCompatibleMagnificationSpecForWindow( IBinder windowToken)260     public abstract MagnificationSpec getCompatibleMagnificationSpecForWindow(
261             IBinder windowToken);
262 
263     /**
264      * Sets a callback for observing which windows are touchable for the purposes
265      * of accessibility.
266      *
267      * @param callback The callback.
268      */
setWindowsForAccessibilityCallback( WindowsForAccessibilityCallback callback)269     public abstract void setWindowsForAccessibilityCallback(
270             WindowsForAccessibilityCallback callback);
271 
272     /**
273      * Sets a filter for manipulating the input event stream.
274      *
275      * @param filter The filter implementation.
276      */
setInputFilter(IInputFilter filter)277     public abstract void setInputFilter(IInputFilter filter);
278 
279     /**
280      * Gets the token of the window that has input focus.
281      *
282      * @return The token.
283      */
getFocusedWindowToken()284     public abstract IBinder getFocusedWindowToken();
285 
286     /**
287      * @return Whether the keyguard is engaged.
288      */
isKeyguardLocked()289     public abstract boolean isKeyguardLocked();
290 
291     /**
292     * @return Whether the keyguard is showing and not occluded.
293     */
isKeyguardShowingAndNotOccluded()294     public abstract boolean isKeyguardShowingAndNotOccluded();
295 
296     /**
297      * Gets the frame of a window given its token.
298      *
299      * @param token The token.
300      * @param outBounds The frame to populate.
301      */
getWindowFrame(IBinder token, Rect outBounds)302     public abstract void getWindowFrame(IBinder token, Rect outBounds);
303 
304     /**
305      * Opens the global actions dialog.
306      */
showGlobalActions()307     public abstract void showGlobalActions();
308 
309     /**
310      * Invalidate all visible windows. Then report back on the callback once all windows have
311      * redrawn.
312      */
waitForAllWindowsDrawn(Runnable callback, long timeout)313     public abstract void waitForAllWindowsDrawn(Runnable callback, long timeout);
314 
315     /**
316      * Overrides the display size.
317      *
318      * @param displayId The display to override the display size.
319      * @param width The width to override.
320      * @param height The height to override.
321      */
setForcedDisplaySize(int displayId, int width, int height)322     public abstract void setForcedDisplaySize(int displayId, int width, int height);
323 
324     /**
325      * Recover the display size to real display size.
326      *
327      * @param displayId The display to recover the display size.
328      */
clearForcedDisplaySize(int displayId)329     public abstract void clearForcedDisplaySize(int displayId);
330 
331     /**
332      * Adds a window token for a given window type.
333      *
334      * @param token The token to add.
335      * @param type The window type.
336      * @param displayId The display to add the token to.
337      */
addWindowToken(android.os.IBinder token, int type, int displayId)338     public abstract void addWindowToken(android.os.IBinder token, int type, int displayId);
339 
340     /**
341      * Removes a window token.
342      *
343      * @param token The toke to remove.
344      * @param removeWindows Whether to also remove the windows associated with the token.
345      * @param displayId The display to remove the token from.
346      */
removeWindowToken(android.os.IBinder token, boolean removeWindows, int displayId)347     public abstract void removeWindowToken(android.os.IBinder token, boolean removeWindows,
348             int displayId);
349 
350     /**
351      * Registers a listener to be notified about app transition events.
352      *
353      * @param listener The listener to register.
354      */
registerAppTransitionListener(AppTransitionListener listener)355     public abstract void registerAppTransitionListener(AppTransitionListener listener);
356 
357     /**
358      * Reports that the password for the given user has changed.
359      */
reportPasswordChanged(int userId)360     public abstract void reportPasswordChanged(int userId);
361 
362     /**
363      * Retrieves a height of input method window for given display.
364      */
getInputMethodWindowVisibleHeight(int displayId)365     public abstract int getInputMethodWindowVisibleHeight(int displayId);
366 
367     /**
368      * Notifies WindowManagerService that the current IME window status is being changed.
369      *
370      * <p>Only {@link com.android.server.inputmethod.InputMethodManagerService} is the expected and
371      * tested caller of this method.</p>
372      *
373      * @param imeToken token to track the active input method. Corresponding IME windows can be
374      *                 identified by checking {@link android.view.WindowManager.LayoutParams#token}.
375      *                 Note that there is no guarantee that the corresponding window is already
376      *                 created
377      * @param imeWindowVisible whether the active IME thinks that its window should be visible or
378      *                         hidden, no matter how WindowManagerService will react / has reacted
379      *                         to corresponding API calls.  Note that this state is not guaranteed
380      *                         to be synchronized with state in WindowManagerService.
381      * @param dismissImeOnBackKeyPressed {@code true} if the software keyboard is shown and the back
382      *                                   key is expected to dismiss the software keyboard.
383      */
updateInputMethodWindowStatus(@onNull IBinder imeToken, boolean imeWindowVisible, boolean dismissImeOnBackKeyPressed)384     public abstract void updateInputMethodWindowStatus(@NonNull IBinder imeToken,
385             boolean imeWindowVisible, boolean dismissImeOnBackKeyPressed);
386 
387     /**
388      * Notifies WindowManagerService that the current IME window status is being changed.
389      *
390      * <p>Only {@link com.android.server.inputmethod.InputMethodManagerService} is the expected and
391      * tested caller of this method.</p>
392      *
393      * @param imeToken token to track the active input method. Corresponding IME windows can be
394      *                 identified by checking {@link android.view.WindowManager.LayoutParams#token}.
395      *                 Note that there is no guarantee that the corresponding window is already
396      *                 created
397      * @param imeTargetWindowToken token to identify the target window that the IME is associated
398      *                             with
399      */
updateInputMethodTargetWindow(@onNull IBinder imeToken, @NonNull IBinder imeTargetWindowToken)400     public abstract void updateInputMethodTargetWindow(@NonNull IBinder imeToken,
401             @NonNull IBinder imeTargetWindowToken);
402 
403     /**
404       * Returns true when the hardware keyboard is available.
405       */
isHardKeyboardAvailable()406     public abstract boolean isHardKeyboardAvailable();
407 
408     /**
409       * Sets the callback listener for hardware keyboard status changes.
410       *
411       * @param listener The listener to set.
412       */
setOnHardKeyboardStatusChangeListener( OnHardKeyboardStatusChangeListener listener)413     public abstract void setOnHardKeyboardStatusChangeListener(
414         OnHardKeyboardStatusChangeListener listener);
415 
416     /** Returns true if a stack in the windowing mode is currently visible. */
isStackVisibleLw(int windowingMode)417     public abstract boolean isStackVisibleLw(int windowingMode);
418 
419     /**
420      * Requests the window manager to resend the windows for accessibility.
421      */
computeWindowsForAccessibility()422     public abstract void computeWindowsForAccessibility();
423 
424     /**
425      * Called after virtual display Id is updated by
426      * {@link com.android.server.vr.Vr2dDisplay} with a specific
427      * {@param vr2dDisplayId}.
428      */
setVr2dDisplayId(int vr2dDisplayId)429     public abstract void setVr2dDisplayId(int vr2dDisplayId);
430 
431     /**
432      * Sets callback to DragDropController.
433      */
registerDragDropControllerCallback(IDragDropCallback callback)434     public abstract void registerDragDropControllerCallback(IDragDropCallback callback);
435 
436     /**
437      * @see android.view.IWindowManager#lockNow
438      */
lockNow()439     public abstract void lockNow();
440 
441     /**
442      * Return the user that owns the given window, {@link android.os.UserHandle#USER_NULL} if
443      * the window token is not found.
444      */
getWindowOwnerUserId(IBinder windowToken)445     public abstract int getWindowOwnerUserId(IBinder windowToken);
446 
447     /**
448      * Returns {@code true} if a Window owned by {@code uid} has focus.
449      */
isUidFocused(int uid)450     public abstract boolean isUidFocused(int uid);
451 
452     /**
453      * Checks whether the specified IME client has IME focus or not.
454      *
455      * @param uid UID of the process to be queried
456      * @param pid PID of the process to be queried
457      * @param displayId Display ID reported from the client. Note that this method also verifies
458      *                  whether the specified process is allowed to access to this display or not
459      * @return {@code true} if the IME client specified with {@code uid}, {@code pid}, and
460      *         {@code displayId} has IME focus
461      */
isInputMethodClientFocus(int uid, int pid, int displayId)462     public abstract boolean isInputMethodClientFocus(int uid, int pid, int displayId);
463 
464     /**
465      * Checks whether the given {@code uid} is allowed to use the given {@code displayId} or not.
466      *
467      * @param displayId Display ID to be checked
468      * @param uid UID to be checked.
469      * @return {@code true} if the given {@code uid} is allowed to use the given {@code displayId}
470      */
isUidAllowedOnDisplay(int displayId, int uid)471     public abstract boolean isUidAllowedOnDisplay(int displayId, int uid);
472 
473     /**
474      * Return the display Id for given window.
475      */
getDisplayIdForWindow(IBinder windowToken)476     public abstract int getDisplayIdForWindow(IBinder windowToken);
477 
478     /**
479      * @return The top focused display ID.
480      */
getTopFocusedDisplayId()481     public abstract int getTopFocusedDisplayId();
482 
483     /**
484      * Checks if this display is configured and allowed to show system decorations.
485      */
shouldShowSystemDecorOnDisplay(int displayId)486     public abstract boolean shouldShowSystemDecorOnDisplay(int displayId);
487 
488     /**
489      * Indicates that the display should show IME.
490      *
491      * @param displayId The id of the display.
492      * @return {@code true} if the display should show IME when an input field become focused on it.
493      */
shouldShowIme(int displayId)494     public abstract boolean shouldShowIme(int displayId);
495 
496     /**
497      * Tell window manager about a package that should not be running with high refresh rate
498      * setting until removeNonHighRefreshRatePackage is called for the same package.
499      *
500      * This must not be called again for the same package.
501      */
addNonHighRefreshRatePackage(@onNull String packageName)502     public abstract void addNonHighRefreshRatePackage(@NonNull String packageName);
503 
504     /**
505      * Tell window manager to stop constraining refresh rate for the given package.
506      */
removeNonHighRefreshRatePackage(@onNull String packageName)507     public abstract void removeNonHighRefreshRatePackage(@NonNull String packageName);
508 
509 }
510