1/*
2** Copyright 2006, 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
17package android.view;
18
19import com.android.internal.app.IAssistScreenshotReceiver;
20import com.android.internal.os.IResultReceiver;
21import com.android.internal.view.IInputContext;
22import com.android.internal.view.IInputMethodClient;
23import com.android.internal.policy.IShortcutService;
24
25import android.content.res.CompatibilityInfo;
26import android.content.res.Configuration;
27import android.graphics.Bitmap;
28import android.graphics.Point;
29import android.graphics.Rect;
30import android.os.Bundle;
31import android.os.IRemoteCallback;
32import android.view.IApplicationToken;
33import android.view.IAppTransitionAnimationSpecsFuture;
34import android.view.IDockedStackListener;
35import android.view.IOnKeyguardExitResult;
36import android.view.IRotationWatcher;
37import android.view.IWindowSession;
38import android.view.IWindowSessionCallback;
39import android.view.KeyEvent;
40import android.view.InputEvent;
41import android.view.MagnificationSpec;
42import android.view.MotionEvent;
43import android.view.InputChannel;
44import android.view.InputDevice;
45import android.view.IInputFilter;
46import android.view.AppTransitionAnimationSpec;
47import android.view.WindowContentFrameStats;
48
49/**
50 * System private interface to the window manager.
51 *
52 * {@hide}
53 */
54interface IWindowManager
55{
56    /**
57     * ===== NOTICE =====
58     * The first three methods must remain the first three methods. Scripts
59     * and tools rely on their transaction number to work properly.
60     */
61    // This is used for debugging
62    boolean startViewServer(int port);   // Transaction #1
63    boolean stopViewServer();            // Transaction #2
64    boolean isViewServerRunning();       // Transaction #3
65
66    IWindowSession openSession(in IWindowSessionCallback callback, in IInputMethodClient client,
67            in IInputContext inputContext);
68    boolean inputMethodClientHasFocus(IInputMethodClient client);
69
70    void getInitialDisplaySize(int displayId, out Point size);
71    void getBaseDisplaySize(int displayId, out Point size);
72    void setForcedDisplaySize(int displayId, int width, int height);
73    void clearForcedDisplaySize(int displayId);
74    int getInitialDisplayDensity(int displayId);
75    int getBaseDisplayDensity(int displayId);
76    void setForcedDisplayDensity(int displayId, int density);
77    void clearForcedDisplayDensity(int displayId);
78    void setForcedDisplayScalingMode(int displayId, int mode); // 0 = auto, 1 = disable
79
80    void setOverscan(int displayId, int left, int top, int right, int bottom);
81
82    // These can only be called when holding the MANAGE_APP_TOKENS permission.
83    void pauseKeyDispatching(IBinder token);
84    void resumeKeyDispatching(IBinder token);
85    void setEventDispatching(boolean enabled);
86    void addWindowToken(IBinder token, int type);
87    void removeWindowToken(IBinder token);
88    /**
89     * Adds an application token to the specified task Id.
90     * @param addPos The position to add the token to in the task.
91     * @param token The token to add.
92     * @param taskId The Id of the task we are adding the token to.
93     * @param stackId Stack Id to create a new Task with the input task Id on
94     *                if the task doesn't exist yet.
95     * @param requestedOrientation Orientation to use.
96     * @param fullscreen True if the application token is fullscreen.
97     * @param showWhenLocked True if the application token should be shown when locked.
98     * @param userId Id of user to associate the token with.
99     * @param configChanges Input configuration changes.
100     * @param voiceInteraction True if the token is in voice interaction mode.
101     * @param launchTaskBehind True if the token is been launched from behind.
102     * @param taskBounds Bounds to use when creating a new Task with the input task Id if
103     *                   the task doesn't exist yet.
104     * @param configuration Configuration that is being used with this task.
105     * @param taskResizeMode The resize mode of the task.
106     * @param alwaysFocusable True if the app windows are always focusable regardless of the stack
107     *                        they are in.
108     * @param homeTask True if this is the task.
109     * @param targetSdkVersion The application's target SDK version
110     */
111    void addAppToken(int addPos, IApplicationToken token, int taskId, int stackId,
112            int requestedOrientation, boolean fullscreen, boolean showWhenLocked, int userId,
113            int configChanges, boolean voiceInteraction, boolean launchTaskBehind,
114            in Rect taskBounds, in Configuration configuration, int taskResizeMode,
115            boolean alwaysFocusable, boolean homeTask, int targetSdkVersion);
116    /**
117     *
118     * @param token The token we are adding to the input task Id.
119     * @param taskId The Id of the task we are adding the token to.
120     * @param stackId Stack Id to create a new Task with the input task Id on
121     *                if the task doesn't exist yet.
122     * @param taskBounds Bounds to use when creating a new Task with the input task Id if
123     *                   the task doesn't exist yet.
124     * @param config Configuration that is being used with this task.
125     * @param taskResizeMode The resize mode of the task.
126     * @param homeTask True if this is the task.
127     */
128    void setAppTask(IBinder token, int taskId, int stackId, in Rect taskBounds,
129            in Configuration config, int taskResizeMode, boolean homeTask);
130    void setAppOrientation(IApplicationToken token, int requestedOrientation);
131    int getAppOrientation(IApplicationToken token);
132    void setFocusedApp(IBinder token, boolean moveFocusNow);
133    void prepareAppTransition(int transit, boolean alwaysKeepCurrent);
134    int getPendingAppTransition();
135    void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
136            IRemoteCallback startedCallback);
137    void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
138            int startHeight);
139    void overridePendingAppTransitionClipReveal(int startX, int startY,
140            int startWidth, int startHeight);
141    void overridePendingAppTransitionThumb(in Bitmap srcThumb, int startX, int startY,
142            IRemoteCallback startedCallback, boolean scaleUp);
143    void overridePendingAppTransitionAspectScaledThumb(in Bitmap srcThumb, int startX,
144            int startY, int targetWidth, int targetHeight, IRemoteCallback startedCallback,
145            boolean scaleUp);
146    /**
147     * Overrides animation for app transition that exits from an application to a multi-window
148     * environment and allows specifying transition animation parameters for each window.
149     *
150     * @param specs Array of transition animation descriptions for entering windows.
151     *
152     * @hide
153     */
154    void overridePendingAppTransitionMultiThumb(in AppTransitionAnimationSpec[] specs,
155            IRemoteCallback startedCallback, IRemoteCallback finishedCallback, boolean scaleUp);
156    void overridePendingAppTransitionInPlace(String packageName, int anim);
157
158    /**
159     * Like overridePendingAppTransitionMultiThumb, but uses a future to supply the specs. This is
160     * used for recents, where generating the thumbnails of the specs takes a non-trivial amount of
161     * time, so we want to move that off the critical path for starting the new activity.
162     */
163    void overridePendingAppTransitionMultiThumbFuture(
164            IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback startedCallback,
165            boolean scaleUp);
166    void executeAppTransition();
167
168    /**
169     * Called to set the starting window for the input token and returns true if the starting
170     * window was set for the token.
171     */
172    boolean setAppStartingWindow(IBinder token, String pkg, int theme,
173            in CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
174            int icon, int logo, int windowFlags, IBinder transferFrom, boolean createIfNeeded);
175    void setAppVisibility(IBinder token, boolean visible);
176    void notifyAppStopped(IBinder token, boolean stopped);
177    void startAppFreezingScreen(IBinder token, int configChanges);
178    void stopAppFreezingScreen(IBinder token, boolean force);
179    void removeAppToken(IBinder token);
180
181    /** Used by system ui to report that recents has shown itself. */
182    void endProlongedAnimations();
183
184    // Re-evaluate the current orientation from the caller's state.
185    // If there is a change, the new Configuration is returned and the
186    // caller must call setNewConfiguration() sometime later.
187    Configuration updateOrientationFromAppTokens(in Configuration currentConfig,
188            IBinder freezeThisOneIfNeeded);
189    // Notify window manager of the new configuration. Returns an array of stack ids that's
190    // affected by the update, ActivityManager should resize these stacks.
191    int[] setNewConfiguration(in Configuration config);
192
193    // Retrieves the new bounds after the configuration update evaluated by window manager.
194    Rect getBoundsForNewConfiguration(int stackId);
195
196    void startFreezingScreen(int exitAnim, int enterAnim);
197    void stopFreezingScreen();
198
199    // these require DISABLE_KEYGUARD permission
200    void disableKeyguard(IBinder token, String tag);
201    void reenableKeyguard(IBinder token);
202    void exitKeyguardSecurely(IOnKeyguardExitResult callback);
203    boolean isKeyguardLocked();
204    boolean isKeyguardSecure();
205    boolean inKeyguardRestrictedInputMode();
206    void dismissKeyguard();
207    void keyguardGoingAway(int flags);
208
209    void closeSystemDialogs(String reason);
210
211    // These can only be called with the SET_ANIMATON_SCALE permission.
212    float getAnimationScale(int which);
213    float[] getAnimationScales();
214    void setAnimationScale(int which, float scale);
215    void setAnimationScales(in float[] scales);
216
217    float getCurrentAnimatorScale();
218
219    // For testing
220    void setInTouchMode(boolean showFocus);
221
222    // For StrictMode flashing a red border on violations from the UI
223    // thread.  The uid/pid is implicit from the Binder call, and the Window
224    // Manager uses that to determine whether or not the red border should
225    // actually be shown.  (it will be ignored that pid doesn't have windows
226    // on screen)
227    void showStrictModeViolation(boolean on);
228
229    // Proxy to set the system property for whether the flashing
230    // should be enabled.  The 'enabled' value is null or blank for
231    // the system default (differs per build variant) or any valid
232    // boolean string as parsed by SystemProperties.getBoolean().
233    void setStrictModeVisualIndicatorPreference(String enabled);
234
235    /**
236     * Set whether screen capture is disabled for all windows of a specific user
237     */
238    void setScreenCaptureDisabled(int userId, boolean disabled);
239
240    /**
241     * Cancels the window transitions for the given task.
242     */
243    void cancelTaskWindowTransition(int taskId);
244
245    /**
246     * Cancels the thumbnail transitions for the given task.
247     */
248    void cancelTaskThumbnailTransition(int taskId);
249
250    // These can only be called with the SET_ORIENTATION permission.
251    /**
252     * Update the current screen rotation based on the current state of
253     * the world.
254     * @param alwaysSendConfiguration Flag to force a new configuration to
255     * be evaluated.  This can be used when there are other parameters in
256     * configuration that are changing.
257     * @param forceRelayout If true, the window manager will always do a relayout
258     * of its windows even if the rotation hasn't changed.
259     */
260    void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout);
261
262    /**
263     * Retrieve the current screen orientation, constants as per
264     * {@link android.view.Surface}.
265     */
266    int getRotation();
267
268    /**
269     * Watch the rotation of the screen.  Returns the current rotation,
270     * calls back when it changes.
271     */
272    int watchRotation(IRotationWatcher watcher);
273
274    /**
275     * Remove a rotation watcher set using watchRotation.
276     * @hide
277     */
278    void removeRotationWatcher(IRotationWatcher watcher);
279
280    /**
281     * Determine the preferred edge of the screen to pin the compact options menu against.
282     * @return a Gravity value for the options menu panel
283     * @hide
284     */
285    int getPreferredOptionsPanelGravity();
286
287    /**
288     * Lock the device orientation to the specified rotation, or to the
289     * current rotation if -1.  Sensor input will be ignored until
290     * thawRotation() is called.
291     * @hide
292     */
293    void freezeRotation(int rotation);
294
295    /**
296     * Release the orientation lock imposed by freezeRotation().
297     * @hide
298     */
299    void thawRotation();
300
301    /**
302     * Gets whether the rotation is frozen.
303     *
304     * @return Whether the rotation is frozen.
305     */
306    boolean isRotationFrozen();
307
308    /**
309     * Used only for assist -- request a screenshot of the current application.
310     */
311    boolean requestAssistScreenshot(IAssistScreenshotReceiver receiver);
312
313    /**
314     * Create a screenshot of the applications currently displayed.
315     *
316     * @param frameScale the scale to apply to the frame, only used when width = -1 and
317     *                   height = -1
318     */
319    Bitmap screenshotApplications(IBinder appToken, int displayId, int maxWidth, int maxHeight,
320            float frameScale);
321
322    /**
323     * Called by the status bar to notify Views of changes to System UI visiblity.
324     */
325    oneway void statusBarVisibilityChanged(int visibility);
326
327    /**
328     * Device has a software navigation bar (separate from the status bar).
329     */
330    boolean hasNavigationBar();
331
332    /**
333     * Lock the device immediately with the specified options (can be null).
334     */
335    void lockNow(in Bundle options);
336
337    /**
338     * Device is in safe mode.
339     */
340    boolean isSafeModeEnabled();
341
342    /**
343     * Enables the screen if all conditions are met.
344     */
345    void enableScreenIfNeeded();
346
347    /**
348     * Clears the frame statistics for a given window.
349     *
350     * @param token The window token.
351     * @return Whether the frame statistics were cleared.
352     */
353    boolean clearWindowContentFrameStats(IBinder token);
354
355    /**
356     * Gets the content frame statistics for a given window.
357     *
358     * @param token The window token.
359     * @return The frame statistics or null if the window does not exist.
360     */
361    WindowContentFrameStats getWindowContentFrameStats(IBinder token);
362
363    /**
364     * @return the dock side the current docked stack is at; must be one of the
365     *         WindowManagerGlobal.DOCKED_* values
366     */
367    int getDockedStackSide();
368
369    /**
370     * Sets whether we are currently in a drag resize operation where we are changing the docked
371     * stack size.
372     */
373    void setDockedStackResizing(boolean resizing);
374
375    /**
376     * Sets the region the user can touch the divider. This region will be excluded from the region
377     * which is used to cause a focus switch when dispatching touch.
378     */
379    void setDockedStackDividerTouchRegion(in Rect touchableRegion);
380
381    /**
382     * Registers a listener that will be called when the dock divider changes its visibility or when
383     * the docked stack gets added/removed.
384     */
385    void registerDockedStackListener(IDockedStackListener listener);
386
387    /**
388     * Updates the dim layer used while resizing.
389     *
390     * @param visible Whether the dim layer should be visible.
391     * @param targetStackId The id of the task stack the dim layer should be placed on.
392     * @param alpha The translucency of the dim layer, between 0 and 1.
393     */
394    void setResizeDimLayer(boolean visible, int targetStackId, float alpha);
395
396    /**
397     * Requests Keyboard Shortcuts from the displayed window.
398     *
399     * @param receiver The receiver to deliver the results to.
400     */
401    void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId);
402
403    /**
404     * Retrieves the current stable insets from the primary display.
405     */
406    void getStableInsets(out Rect outInsets);
407
408    /**
409     * Register shortcut key. Shortcut code is packed as:
410     * (MetaState << Integer.SIZE) | KeyCode
411     * @hide
412     */
413    void registerShortcutKey(in long shortcutCode, IShortcutService keySubscriber);
414
415    /**
416     * Create the input consumer for wallpaper events.
417     */
418    void createWallpaperInputConsumer(out InputChannel inputChannel);
419
420    /**
421     * Remove the input consumer for wallpaper events.
422     */
423    void removeWallpaperInputConsumer();
424}
425