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 openToken the token for the opening app
122          * @param closeToken the token for the closing app
123          * @param duration the total duration of the transition
124          * @param statusBarAnimationStartTime the desired start time for all visual animations in
125          *        the status bar caused by this app transition in uptime millis
126          * @param statusBarAnimationDuration the duration for all visual animations in the status
127          *        bar caused by this app transition in millis
128          *
129          * @return Return any bit set of {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_LAYOUT},
130          * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_CONFIG},
131          * {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_WALLPAPER},
132          * or {@link WindowManagerPolicy#FINISH_LAYOUT_REDO_ANIM}.
133          */
onAppTransitionStartingLocked(int transit, IBinder openToken, IBinder closeToken, long duration, long statusBarAnimationStartTime, long statusBarAnimationDuration)134         public int onAppTransitionStartingLocked(int transit, IBinder openToken, IBinder closeToken,
135                 long duration, long statusBarAnimationStartTime, long statusBarAnimationDuration) {
136             return 0;
137         }
138 
139         /**
140          * Called when an app transition is finished running.
141          *
142          * @param token the token for app whose transition has finished
143          */
onAppTransitionFinishedLocked(IBinder token)144         public void onAppTransitionFinishedLocked(IBinder token) {}
145     }
146 
147     /**
148       * An interface to be notified about hardware keyboard status.
149       */
150     public interface OnHardKeyboardStatusChangeListener {
onHardKeyboardStatusChange(boolean available)151         public void onHardKeyboardStatusChange(boolean available);
152     }
153 
154     /**
155      * An interface to customize drag and drop behaviors.
156      */
157     public interface IDragDropCallback {
registerInputChannel( DragState state, Display display, InputManagerService service, InputChannel source)158         default boolean registerInputChannel(
159                 DragState state, Display display, InputManagerService service,
160                 InputChannel source) {
161             state.register(display);
162             return service.transferTouchFocus(source, state.getInputChannel());
163         }
164 
165         /**
166          * Called when drag operation is starting.
167          */
prePerformDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data)168         default boolean prePerformDrag(IWindow window, IBinder dragToken,
169                 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY,
170                 ClipData data) {
171             return true;
172         }
173 
174         /**
175          * Called when drag operation is started.
176          */
postPerformDrag()177         default void postPerformDrag() {}
178 
179         /**
180          * Called when drop result is being reported.
181          */
preReportDropResult(IWindow window, boolean consumed)182         default void preReportDropResult(IWindow window, boolean consumed) {}
183 
184         /**
185          * Called when drop result was reported.
186          */
postReportDropResult()187         default void postReportDropResult() {}
188 
189         /**
190          * Called when drag operation is being cancelled.
191          */
preCancelDragAndDrop(IBinder dragToken)192         default void preCancelDragAndDrop(IBinder dragToken) {}
193 
194         /**
195          * Called when drag operation was cancelled.
196          */
postCancelDragAndDrop()197         default void postCancelDragAndDrop() {}
198     }
199 
200     /**
201      * Request that the window manager call
202      * {@link DisplayManagerInternal#performTraversalInTransactionFromWindowManager}
203      * within a surface transaction at a later time.
204      */
requestTraversalFromDisplayManager()205     public abstract void requestTraversalFromDisplayManager();
206 
207     /**
208      * Set by the accessibility layer to observe changes in the magnified region,
209      * rotation, and other window transformations related to display magnification
210      * as the window manager is responsible for doing the actual magnification
211      * and has access to the raw window data while the accessibility layer serves
212      * as a controller.
213      *
214      * @param callbacks The callbacks to invoke.
215      */
setMagnificationCallbacks(@ullable MagnificationCallbacks callbacks)216     public abstract void setMagnificationCallbacks(@Nullable MagnificationCallbacks callbacks);
217 
218     /**
219      * Set by the accessibility layer to specify the magnification and panning to
220      * be applied to all windows that should be magnified.
221      *
222      * @param spec The MagnficationSpec to set.
223      *
224      * @see #setMagnificationCallbacks(MagnificationCallbacks)
225      */
setMagnificationSpec(MagnificationSpec spec)226     public abstract void setMagnificationSpec(MagnificationSpec spec);
227 
228     /**
229      * Set by the accessibility framework to indicate whether the magnifiable regions of the display
230      * should be shown.
231      *
232      * @param show {@code true} to show magnifiable region bounds, {@code false} to hide
233      */
setForceShowMagnifiableBounds(boolean show)234     public abstract void setForceShowMagnifiableBounds(boolean show);
235 
236     /**
237      * Obtains the magnification regions.
238      *
239      * @param magnificationRegion the current magnification region
240      */
getMagnificationRegion(@onNull Region magnificationRegion)241     public abstract void getMagnificationRegion(@NonNull Region magnificationRegion);
242 
243     /**
244      * Gets the magnification and translation applied to a window given its token.
245      * Not all windows are magnified and the window manager policy determines which
246      * windows are magnified. The returned result also takes into account the compat
247      * scale if necessary.
248      *
249      * @param windowToken The window's token.
250      *
251      * @return The magnification spec for the window.
252      *
253      * @see #setMagnificationCallbacks(MagnificationCallbacks)
254      */
getCompatibleMagnificationSpecForWindow( IBinder windowToken)255     public abstract MagnificationSpec getCompatibleMagnificationSpecForWindow(
256             IBinder windowToken);
257 
258     /**
259      * Sets a callback for observing which windows are touchable for the purposes
260      * of accessibility.
261      *
262      * @param callback The callback.
263      */
setWindowsForAccessibilityCallback( WindowsForAccessibilityCallback callback)264     public abstract void setWindowsForAccessibilityCallback(
265             WindowsForAccessibilityCallback callback);
266 
267     /**
268      * Sets a filter for manipulating the input event stream.
269      *
270      * @param filter The filter implementation.
271      */
setInputFilter(IInputFilter filter)272     public abstract void setInputFilter(IInputFilter filter);
273 
274     /**
275      * Gets the token of the window that has input focus.
276      *
277      * @return The token.
278      */
getFocusedWindowToken()279     public abstract IBinder getFocusedWindowToken();
280 
281     /**
282      * @return Whether the keyguard is engaged.
283      */
isKeyguardLocked()284     public abstract boolean isKeyguardLocked();
285 
286     /**
287     * @return Whether the keyguard is showing and not occluded.
288     */
isKeyguardShowingAndNotOccluded()289     public abstract boolean isKeyguardShowingAndNotOccluded();
290 
291     /**
292      * Gets the frame of a window given its token.
293      *
294      * @param token The token.
295      * @param outBounds The frame to populate.
296      */
getWindowFrame(IBinder token, Rect outBounds)297     public abstract void getWindowFrame(IBinder token, Rect outBounds);
298 
299     /**
300      * Opens the global actions dialog.
301      */
showGlobalActions()302     public abstract void showGlobalActions();
303 
304     /**
305      * Invalidate all visible windows. Then report back on the callback once all windows have
306      * redrawn.
307      */
waitForAllWindowsDrawn(Runnable callback, long timeout)308     public abstract void waitForAllWindowsDrawn(Runnable callback, long timeout);
309 
310     /**
311      * Adds a window token for a given window type.
312      *
313      * @param token The token to add.
314      * @param type The window type.
315      * @param displayId The display to add the token to.
316      */
addWindowToken(android.os.IBinder token, int type, int displayId)317     public abstract void addWindowToken(android.os.IBinder token, int type, int displayId);
318 
319     /**
320      * Removes a window token.
321      *
322      * @param token The toke to remove.
323      * @param removeWindows Whether to also remove the windows associated with the token.
324      * @param displayId The display to remove the token from.
325      */
removeWindowToken(android.os.IBinder token, boolean removeWindows, int displayId)326     public abstract void removeWindowToken(android.os.IBinder token, boolean removeWindows,
327             int displayId);
328 
329     /**
330      * Registers a listener to be notified about app transition events.
331      *
332      * @param listener The listener to register.
333      */
registerAppTransitionListener(AppTransitionListener listener)334     public abstract void registerAppTransitionListener(AppTransitionListener listener);
335 
336     /**
337      * Retrieves a height of input method window.
338      */
getInputMethodWindowVisibleHeight()339     public abstract int getInputMethodWindowVisibleHeight();
340 
341     /**
342       * Saves last input method window for transition.
343       *
344       * Note that it is assumed that this method is called only by InputMethodManagerService.
345       */
saveLastInputMethodWindowForTransition()346     public abstract void saveLastInputMethodWindowForTransition();
347 
348     /**
349      * Clears last input method window for transition.
350      *
351      * Note that it is assumed that this method is called only by InputMethodManagerService.
352      */
clearLastInputMethodWindowForTransition()353     public abstract void clearLastInputMethodWindowForTransition();
354 
355     /**
356      * Notifies WindowManagerService that the current IME window status is being changed.
357      *
358      * <p>Only {@link com.android.server.InputMethodManagerService} is the expected and tested
359      * caller of this method.</p>
360      *
361      * @param imeToken token to track the active input method. Corresponding IME windows can be
362      *                 identified by checking {@link android.view.WindowManager.LayoutParams#token}.
363      *                 Note that there is no guarantee that the corresponding window is already
364      *                 created
365      * @param imeWindowVisible whether the active IME thinks that its window should be visible or
366      *                         hidden, no matter how WindowManagerService will react / has reacted
367      *                         to corresponding API calls.  Note that this state is not guaranteed
368      *                         to be synchronized with state in WindowManagerService.
369      * @param dismissImeOnBackKeyPressed {@code true} if the software keyboard is shown and the back
370      *                                   key is expected to dismiss the software keyboard.
371      * @param targetWindowToken token to identify the target window that the IME is associated with.
372      *                          {@code null} when application, system, or the IME itself decided to
373      *                          change its window visibility before being associated with any target
374      *                          window.
375      */
updateInputMethodWindowStatus(@onNull IBinder imeToken, boolean imeWindowVisible, boolean dismissImeOnBackKeyPressed, @Nullable IBinder targetWindowToken)376     public abstract void updateInputMethodWindowStatus(@NonNull IBinder imeToken,
377             boolean imeWindowVisible, boolean dismissImeOnBackKeyPressed,
378             @Nullable IBinder targetWindowToken);
379 
380     /**
381       * Returns true when the hardware keyboard is available.
382       */
isHardKeyboardAvailable()383     public abstract boolean isHardKeyboardAvailable();
384 
385     /**
386       * Sets the callback listener for hardware keyboard status changes.
387       *
388       * @param listener The listener to set.
389       */
setOnHardKeyboardStatusChangeListener( OnHardKeyboardStatusChangeListener listener)390     public abstract void setOnHardKeyboardStatusChangeListener(
391         OnHardKeyboardStatusChangeListener listener);
392 
393     /** Returns true if a stack in the windowing mode is currently visible. */
isStackVisible(int windowingMode)394     public abstract boolean isStackVisible(int windowingMode);
395 
396     /**
397      * @return True if and only if the docked divider is currently in resize mode.
398      */
isDockedDividerResizing()399     public abstract boolean isDockedDividerResizing();
400 
401     /**
402      * Requests the window manager to recompute the windows for accessibility.
403      */
computeWindowsForAccessibility()404     public abstract void computeWindowsForAccessibility();
405 
406     /**
407      * Called after virtual display Id is updated by
408      * {@link com.android.server.vr.Vr2dDisplay} with a specific
409      * {@param vr2dDisplayId}.
410      */
setVr2dDisplayId(int vr2dDisplayId)411     public abstract void setVr2dDisplayId(int vr2dDisplayId);
412 
413     /**
414      * Sets callback to DragDropController.
415      */
registerDragDropControllerCallback(IDragDropCallback callback)416     public abstract void registerDragDropControllerCallback(IDragDropCallback callback);
417 
418     /**
419      * @see android.view.IWindowManager#lockNow
420      */
lockNow()421     public abstract void lockNow();
422 
423     /**
424      * Return the user that owns the given window, {@link android.os.UserHandle#USER_NULL} if
425      * the window token is not found.
426      */
getWindowOwnerUserId(IBinder windowToken)427     public abstract int getWindowOwnerUserId(IBinder windowToken);
428 }
429