blob: 1dbb083dd58f2ed3c5c9998d001a6fb3ae04e67f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 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 android.content.Context;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070020import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.res.Configuration;
22import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070023import android.graphics.RectF;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.os.IBinder;
25import android.os.LocalPowerManager;
26import android.view.animation.Animation;
27
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080028import java.io.FileDescriptor;
29import java.io.PrintWriter;
30
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031/**
32 * This interface supplies all UI-specific behavior of the window manager. An
33 * instance of it is created by the window manager when it starts up, and allows
34 * customization of window layering, special window types, key dispatching, and
35 * layout.
36 *
37 * <p>Because this provides deep interaction with the system window manager,
38 * specific methods on this interface can be called from a variety of contexts
39 * with various restrictions on what they can do. These are encoded through
40 * a suffixes at the end of a method encoding the thread the method is called
41 * from and any locks that are held when it is being called; if no suffix
42 * is attached to a method, then it is not called with any locks and may be
43 * called from the main window manager thread or another thread calling into
44 * the window manager.
45 *
46 * <p>The current suffixes are:
47 *
48 * <dl>
49 * <dt> Ti <dd> Called from the input thread. This is the thread that
50 * collects pending input events and dispatches them to the appropriate window.
51 * It may block waiting for events to be processed, so that the input stream is
52 * properly serialized.
53 * <dt> Tq <dd> Called from the low-level input queue thread. This is the
54 * thread that reads events out of the raw input devices and places them
55 * into the global input queue that is read by the <var>Ti</var> thread.
56 * This thread should not block for a long period of time on anything but the
57 * key driver.
58 * <dt> Lw <dd> Called with the main window manager lock held. Because the
59 * window manager is a very low-level system service, there are few other
60 * system services you can call with this lock held. It is explicitly okay to
61 * make calls into the package manager and power manager; it is explicitly not
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070062 * okay to make calls into the activity manager or most other services. Note that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 * {@link android.content.Context#checkPermission(String, int, int)} and
64 * variations require calling into the activity manager.
65 * <dt> Li <dd> Called with the input thread lock held. This lock can be
66 * acquired by the window manager while it holds the window lock, so this is
67 * even more restrictive than <var>Lw</var>.
68 * </dl>
69 *
70 * @hide
71 */
72public interface WindowManagerPolicy {
Jeff Brownb6997262010-10-08 22:31:17 -070073 // Policy flags. These flags are also defined in frameworks/base/include/ui/Input.h.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 public final static int FLAG_WAKE = 0x00000001;
75 public final static int FLAG_WAKE_DROPPED = 0x00000002;
76 public final static int FLAG_SHIFT = 0x00000004;
77 public final static int FLAG_CAPS_LOCK = 0x00000008;
78 public final static int FLAG_ALT = 0x00000010;
79 public final static int FLAG_ALT_GR = 0x00000020;
80 public final static int FLAG_MENU = 0x00000040;
81 public final static int FLAG_LAUNCHER = 0x00000080;
Jeff Brown0eaf3932010-10-01 14:55:30 -070082 public final static int FLAG_VIRTUAL = 0x00000100;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
Jeff Brown85a31762010-09-01 17:01:00 -070084 public final static int FLAG_INJECTED = 0x01000000;
Jeff Browne20c9e02010-10-11 14:20:19 -070085 public final static int FLAG_TRUSTED = 0x02000000;
Jeff Brown0029c662011-03-30 02:25:18 -070086 public final static int FLAG_FILTERED = 0x04000000;
87 public final static int FLAG_DISABLE_KEY_REPEAT = 0x08000000;
Jeff Brown85a31762010-09-01 17:01:00 -070088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 public final static int FLAG_WOKE_HERE = 0x10000000;
90 public final static int FLAG_BRIGHT_HERE = 0x20000000;
Jeff Brownb6997262010-10-08 22:31:17 -070091 public final static int FLAG_PASS_TO_USER = 0x40000000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 public final static boolean WATCH_POINTER = false;
94
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080095 /**
96 * Sticky broadcast of the current HDMI plugged state.
97 */
98 public final static String ACTION_HDMI_PLUGGED = "android.intent.action.HDMI_PLUGGED";
99
100 /**
101 * Extra in {@link #ACTION_HDMI_PLUGGED} indicating the state: true if
102 * plugged in to HDMI, false if not.
103 */
104 public final static String EXTRA_HDMI_PLUGGED_STATE = "state";
105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 // flags for interceptKeyTq
107 /**
108 * Pass this event to the user / app. To be returned from {@link #interceptKeyTq}.
109 */
110 public final static int ACTION_PASS_TO_USER = 0x00000001;
111
112 /**
113 * This key event should extend the user activity timeout and turn the lights on.
114 * To be returned from {@link #interceptKeyTq}. Do not return this and
115 * {@link #ACTION_GO_TO_SLEEP} or {@link #ACTION_PASS_TO_USER}.
116 */
117 public final static int ACTION_POKE_USER_ACTIVITY = 0x00000002;
118
119 /**
120 * This key event should put the device to sleep (and engage keyguard if necessary)
121 * To be returned from {@link #interceptKeyTq}. Do not return this and
122 * {@link #ACTION_POKE_USER_ACTIVITY} or {@link #ACTION_PASS_TO_USER}.
123 */
124 public final static int ACTION_GO_TO_SLEEP = 0x00000004;
125
126 /**
127 * Interface to the Window Manager state associated with a particular
128 * window. You can hold on to an instance of this interface from the call
129 * to prepareAddWindow() until removeWindow().
130 */
131 public interface WindowState {
132 /**
133 * Perform standard frame computation. The result can be obtained with
134 * getFrame() if so desired. Must be called with the window manager
135 * lock held.
136 *
137 * @param parentFrame The frame of the parent container this window
138 * is in, used for computing its basic position.
139 * @param displayFrame The frame of the overall display in which this
140 * window can appear, used for constraining the overall dimensions
141 * of the window.
142 * @param contentFrame The frame within the display in which we would
143 * like active content to appear. This will cause windows behind to
144 * be resized to match the given content frame.
145 * @param visibleFrame The frame within the display that the window
146 * is actually visible, used for computing its visible insets to be
147 * given to windows behind.
148 * This can be used as a hint for scrolling (avoiding resizing)
149 * the window to make certain that parts of its content
150 * are visible.
151 */
152 public void computeFrameLw(Rect parentFrame, Rect displayFrame,
153 Rect contentFrame, Rect visibleFrame);
154
155 /**
156 * Retrieve the current frame of the window that has been assigned by
157 * the window manager. Must be called with the window manager lock held.
158 *
159 * @return Rect The rectangle holding the window frame.
160 */
161 public Rect getFrameLw();
162
163 /**
164 * Retrieve the current frame of the window that is actually shown.
165 * Must be called with the window manager lock held.
166 *
167 * @return Rect The rectangle holding the shown window frame.
168 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700169 public RectF getShownFrameLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170
171 /**
172 * Retrieve the frame of the display that this window was last
173 * laid out in. Must be called with the
174 * window manager lock held.
175 *
176 * @return Rect The rectangle holding the display frame.
177 */
178 public Rect getDisplayFrameLw();
179
180 /**
181 * Retrieve the frame of the content area that this window was last
182 * laid out in. This is the area in which the content of the window
183 * should be placed. It will be smaller than the display frame to
184 * account for screen decorations such as a status bar or soft
185 * keyboard. Must be called with the
186 * window manager lock held.
187 *
188 * @return Rect The rectangle holding the content frame.
189 */
190 public Rect getContentFrameLw();
191
192 /**
193 * Retrieve the frame of the visible area that this window was last
194 * laid out in. This is the area of the screen in which the window
195 * will actually be fully visible. It will be smaller than the
196 * content frame to account for transient UI elements blocking it
197 * such as an input method's candidates UI. Must be called with the
198 * window manager lock held.
199 *
200 * @return Rect The rectangle holding the visible frame.
201 */
202 public Rect getVisibleFrameLw();
203
204 /**
205 * Returns true if this window is waiting to receive its given
206 * internal insets from the client app, and so should not impact the
207 * layout of other windows.
208 */
209 public boolean getGivenInsetsPendingLw();
210
211 /**
212 * Retrieve the insets given by this window's client for the content
213 * area of windows behind it. Must be called with the
214 * window manager lock held.
215 *
216 * @return Rect The left, top, right, and bottom insets, relative
217 * to the window's frame, of the actual contents.
218 */
219 public Rect getGivenContentInsetsLw();
220
221 /**
222 * Retrieve the insets given by this window's client for the visible
223 * area of windows behind it. Must be called with the
224 * window manager lock held.
225 *
226 * @return Rect The left, top, right, and bottom insets, relative
227 * to the window's frame, of the actual visible area.
228 */
229 public Rect getGivenVisibleInsetsLw();
230
231 /**
232 * Retrieve the current LayoutParams of the window.
233 *
234 * @return WindowManager.LayoutParams The window's internal LayoutParams
235 * instance.
236 */
237 public WindowManager.LayoutParams getAttrs();
238
239 /**
240 * Get the layer at which this window's surface will be Z-ordered.
241 */
242 public int getSurfaceLayer();
243
244 /**
245 * Return the token for the application (actually activity) that owns
246 * this window. May return null for system windows.
247 *
248 * @return An IApplicationToken identifying the owning activity.
249 */
250 public IApplicationToken getAppToken();
251
252 /**
253 * Return true if, at any point, the application token associated with
254 * this window has actually displayed any windows. This is most useful
255 * with the "starting up" window to determine if any windows were
256 * displayed when it is closed.
257 *
258 * @return Returns true if one or more windows have been displayed,
259 * else false.
260 */
261 public boolean hasAppShownWindows();
262
263 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 * Is this window visible? It is not visible if there is no
265 * surface, or we are in the process of running an exit animation
266 * that will remove the surface.
267 */
268 boolean isVisibleLw();
269
270 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -0700271 * Like {@link #isVisibleLw}, but also counts a window that is currently
272 * "hidden" behind the keyguard as visible. This allows us to apply
273 * things like window flags that impact the keyguard.
274 */
275 boolean isVisibleOrBehindKeyguardLw();
276
277 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 * Is this window currently visible to the user on-screen? It is
279 * displayed either if it is visible or it is currently running an
280 * animation before no longer being visible. Must be called with the
281 * window manager lock held.
282 */
283 boolean isDisplayedLw();
284
285 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 * Returns true if this window has been shown on screen at some time in
287 * the past. Must be called with the window manager lock held.
288 *
289 * @return boolean
290 */
291 public boolean hasDrawnLw();
292
293 /**
294 * Can be called by the policy to force a window to be hidden,
295 * regardless of whether the client or window manager would like
296 * it shown. Must be called with the window manager lock held.
297 * Returns true if {@link #showLw} was last called for the window.
298 */
299 public boolean hideLw(boolean doAnimation);
300
301 /**
302 * Can be called to undo the effect of {@link #hideLw}, allowing a
303 * window to be shown as long as the window manager and client would
304 * also like it to be shown. Must be called with the window manager
305 * lock held.
306 * Returns true if {@link #hideLw} was last called for the window.
307 */
308 public boolean showLw(boolean doAnimation);
309 }
310
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700311 /**
312 * Bit mask that is set for all enter transition.
313 */
314 public final int TRANSIT_ENTER_MASK = 0x1000;
315
316 /**
317 * Bit mask that is set for all exit transitions.
318 */
319 public final int TRANSIT_EXIT_MASK = 0x2000;
320
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700321 /** Not set up for a transition. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700322 public final int TRANSIT_UNSET = -1;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700323 /** No animation for transition. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 public final int TRANSIT_NONE = 0;
325 /** Window has been added to the screen. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700326 public final int TRANSIT_ENTER = 1 | TRANSIT_ENTER_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 /** Window has been removed from the screen. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700328 public final int TRANSIT_EXIT = 2 | TRANSIT_EXIT_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 /** Window has been made visible. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700330 public final int TRANSIT_SHOW = 3 | TRANSIT_ENTER_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 /** Window has been made invisible. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700332 public final int TRANSIT_HIDE = 4 | TRANSIT_EXIT_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 /** The "application starting" preview window is no longer needed, and will
334 * animate away to show the real window. */
335 public final int TRANSIT_PREVIEW_DONE = 5;
336 /** A window in a new activity is being opened on top of an existing one
337 * in the same task. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700338 public final int TRANSIT_ACTIVITY_OPEN = 6 | TRANSIT_ENTER_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 /** The window in the top-most activity is being closed to reveal the
340 * previous activity in the same task. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700341 public final int TRANSIT_ACTIVITY_CLOSE = 7 | TRANSIT_EXIT_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 /** A window in a new task is being opened on top of an existing one
343 * in another activity's task. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700344 public final int TRANSIT_TASK_OPEN = 8 | TRANSIT_ENTER_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 /** A window in the top-most activity is being closed to reveal the
346 * previous activity in a different task. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700347 public final int TRANSIT_TASK_CLOSE = 9 | TRANSIT_EXIT_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 /** A window in an existing task is being displayed on top of an existing one
349 * in another activity's task. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700350 public final int TRANSIT_TASK_TO_FRONT = 10 | TRANSIT_ENTER_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 /** A window in an existing task is being put below all other tasks. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700352 public final int TRANSIT_TASK_TO_BACK = 11 | TRANSIT_EXIT_MASK;
Dianne Hackborn25994b42009-09-04 14:21:19 -0700353 /** A window in a new activity that doesn't have a wallpaper is being
354 * opened on top of one that does, effectively closing the wallpaper. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700355 public final int TRANSIT_WALLPAPER_CLOSE = 12 | TRANSIT_EXIT_MASK;
Dianne Hackborn25994b42009-09-04 14:21:19 -0700356 /** A window in a new activity that does have a wallpaper is being
357 * opened on one that didn't, effectively opening the wallpaper. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700358 public final int TRANSIT_WALLPAPER_OPEN = 13 | TRANSIT_ENTER_MASK;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -0700359 /** A window in a new activity is being opened on top of an existing one,
360 * and both are on top of the wallpaper. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700361 public final int TRANSIT_WALLPAPER_INTRA_OPEN = 14 | TRANSIT_ENTER_MASK;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -0700362 /** The window in the top-most activity is being closed to reveal the
363 * previous activity, and both are on top of he wallpaper. */
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700364 public final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15 | TRANSIT_EXIT_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365
Dianne Hackborn254cb442010-01-27 19:23:59 -0800366 // NOTE: screen off reasons are in order of significance, with more
367 // important ones lower than less important ones.
368
369 /** Screen turned off because of a device admin */
370 public final int OFF_BECAUSE_OF_ADMIN = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 /** Screen turned off because of power button */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800372 public final int OFF_BECAUSE_OF_USER = 2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 /** Screen turned off because of timeout */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800374 public final int OFF_BECAUSE_OF_TIMEOUT = 3;
Mike Lockwood435eb642009-12-03 08:40:18 -0500375 /** Screen turned off because of proximity sensor */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800376 public final int OFF_BECAUSE_OF_PROX_SENSOR = 4;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400378 /** When not otherwise specified by the activity's screenOrientation, rotation should be
379 * determined by the system (that is, using sensors). */
380 public final int USER_ROTATION_FREE = 0;
381 /** When not otherwise specified by the activity's screenOrientation, rotation is set by
382 * the user. */
383 public final int USER_ROTATION_LOCKED = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384
385 /**
386 * Perform initialization of the policy.
387 *
388 * @param context The system context we are running in.
389 * @param powerManager
390 */
391 public void init(Context context, IWindowManager windowManager,
392 LocalPowerManager powerManager);
393
394 /**
Dianne Hackborn9d132642011-04-21 17:26:39 -0700395 * Called by window manager once it has the initial, default native
396 * display dimensions.
397 */
398 public void setInitialDisplaySize(int width, int height);
Dianne Hackborndacea8c2011-04-21 17:26:39 -0700399
Dianne Hackborn9d132642011-04-21 17:26:39 -0700400 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 * Check permissions when adding a window.
402 *
403 * @param attrs The window's LayoutParams.
404 *
405 * @return {@link WindowManagerImpl#ADD_OKAY} if the add can proceed;
406 * else an error code, usually
407 * {@link WindowManagerImpl#ADD_PERMISSION_DENIED}, to abort the add.
408 */
409 public int checkAddPermission(WindowManager.LayoutParams attrs);
410
411 /**
412 * Sanitize the layout parameters coming from a client. Allows the policy
413 * to do things like ensure that windows of a specific type can't take
414 * input focus.
415 *
416 * @param attrs The window layout parameters to be modified. These values
417 * are modified in-place.
418 */
419 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs);
420
421 /**
422 * After the window manager has computed the current configuration based
423 * on its knowledge of the display and input devices, it gives the policy
424 * a chance to adjust the information contained in it. If you want to
425 * leave it as-is, simply do nothing.
426 *
427 * <p>This method may be called by any thread in the window manager, but
428 * no internal locks in the window manager will be held.
429 *
430 * @param config The Configuration being computed, for you to change as
431 * desired.
432 */
433 public void adjustConfigurationLw(Configuration config);
434
435 /**
436 * Assign a window type to a layer. Allows you to control how different
437 * kinds of windows are ordered on-screen.
438 *
439 * @param type The type of window being assigned.
440 *
441 * @return int An arbitrary integer used to order windows, with lower
442 * numbers below higher ones.
443 */
444 public int windowTypeToLayerLw(int type);
445
446 /**
447 * Return how to Z-order sub-windows in relation to the window they are
448 * attached to. Return positive to have them ordered in front, negative for
449 * behind.
450 *
451 * @param type The sub-window type code.
452 *
453 * @return int Layer in relation to the attached window, where positive is
454 * above and negative is below.
455 */
456 public int subWindowTypeToLayerLw(int type);
457
458 /**
Dianne Hackborn6136b7e2009-09-18 01:53:49 -0700459 * Get the highest layer (actually one more than) that the wallpaper is
460 * allowed to be in.
461 */
462 public int getMaxWallpaperLayer();
463
464 /**
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700465 * Return true if the policy allows the status bar to hide. Otherwise,
466 * it is a tablet-style system bar.
467 */
468 public boolean canStatusBarHide();
469
470 /**
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700471 * Return the display width available after excluding any screen
472 * decorations that can never be removed. That is, system bar or
473 * button bar.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400474 */
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700475 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400476
477 /**
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700478 * Return the display height available after excluding any screen
479 * decorations that can never be removed. That is, system bar or
480 * button bar.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400481 */
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700482 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700483
484 /**
485 * Return the available screen width that we should report for the
486 * configuration. This must be no larger than
487 * {@link #getNonDecorDisplayWidth(int, int)}; it may be smaller than
488 * that to account for more transient decoration like a status bar.
489 */
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700490 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700491
492 /**
493 * Return the available screen height that we should report for the
494 * configuration. This must be no larger than
495 * {@link #getNonDecorDisplayHeight(int, int)}; it may be smaller than
496 * that to account for more transient decoration like a status bar.
497 */
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700498 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400499
500 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700501 * Return whether the given window should forcibly hide everything
502 * behind it. Typically returns true for the keyguard.
503 */
504 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs);
505
506 /**
507 * Determine if a window that is behind one that is force hiding
508 * (as determined by {@link #doesForceHide}) should actually be hidden.
509 * For example, typically returns false for the status bar. Be careful
510 * to return false for any window that you may hide yourself, since this
511 * will conflict with what you set.
512 */
513 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs);
514
515 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 * Called when the system would like to show a UI to indicate that an
517 * application is starting. You can use this to add a
518 * APPLICATION_STARTING_TYPE window with the given appToken to the window
519 * manager (using the normal window manager APIs) that will be shown until
520 * the application displays its own window. This is called without the
521 * window manager locked so that you can call back into it.
522 *
523 * @param appToken Token of the application being started.
524 * @param packageName The name of the application package being started.
525 * @param theme Resource defining the application's overall visual theme.
526 * @param nonLocalizedLabel The default title label of the application if
527 * no data is found in the resource.
528 * @param labelRes The resource ID the application would like to use as its name.
529 * @param icon The resource ID the application would like to use as its icon.
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800530 * @param windowFlags Window layout flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 *
532 * @return Optionally you can return the View that was used to create the
533 * window, for easy removal in removeStartingWindow.
534 *
535 * @see #removeStartingWindow
536 */
537 public View addStartingWindow(IBinder appToken, String packageName,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700538 int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -0800539 int labelRes, int icon, int windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540
541 /**
542 * Called when the first window of an application has been displayed, while
543 * {@link #addStartingWindow} has created a temporary initial window for
544 * that application. You should at this point remove the window from the
545 * window manager. This is called without the window manager locked so
546 * that you can call back into it.
547 *
548 * <p>Note: due to the nature of these functions not being called with the
549 * window manager locked, you must be prepared for this function to be
550 * called multiple times and/or an initial time with a null View window
551 * even if you previously returned one.
552 *
553 * @param appToken Token of the application that has started.
554 * @param window Window View that was returned by createStartingWindow.
555 *
556 * @see #addStartingWindow
557 */
558 public void removeStartingWindow(IBinder appToken, View window);
559
560 /**
561 * Prepare for a window being added to the window manager. You can throw an
562 * exception here to prevent the window being added, or do whatever setup
563 * you need to keep track of the window.
564 *
565 * @param win The window being added.
566 * @param attrs The window's LayoutParams.
567 *
568 * @return {@link WindowManagerImpl#ADD_OKAY} if the add can proceed, else an
569 * error code to abort the add.
570 */
571 public int prepareAddWindowLw(WindowState win,
572 WindowManager.LayoutParams attrs);
573
574 /**
575 * Called when a window is being removed from a window manager. Must not
576 * throw an exception -- clean up as much as possible.
577 *
578 * @param win The window being removed.
579 */
580 public void removeWindowLw(WindowState win);
581
582 /**
583 * Control the animation to run when a window's state changes. Return a
584 * non-0 number to force the animation to a specific resource ID, or 0
585 * to use the default animation.
586 *
587 * @param win The window that is changing.
588 * @param transit What is happening to the window: {@link #TRANSIT_ENTER},
589 * {@link #TRANSIT_EXIT}, {@link #TRANSIT_SHOW}, or
590 * {@link #TRANSIT_HIDE}.
591 *
592 * @return Resource ID of the actual animation to use, or 0 for none.
593 */
594 public int selectAnimationLw(WindowState win, int transit);
595
596 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700597 * Create and return an animation to re-display a force hidden window.
598 */
599 public Animation createForceHideEnterAnimation();
600
601 /**
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700602 * Called from the input reader thread before a key is enqueued.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 *
604 * <p>There are some actions that need to be handled here because they
605 * affect the power state of the device, for example, the power keys.
606 * Generally, it's best to keep as little as possible in the queue thread
607 * because it's the most fragile.
Jeff Brown1f245102010-11-18 20:53:46 -0800608 * @param event The key event.
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700609 * @param policyFlags The policy flags associated with the key.
610 * @param isScreenOn True if the screen is already on
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 * @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
613 * {@link #ACTION_POKE_USER_ACTIVITY} and {@link #ACTION_GO_TO_SLEEP} flags.
614 */
Jeff Brown1f245102010-11-18 20:53:46 -0800615 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn);
Jeff Brown56194eb2011-03-02 19:23:13 -0800616
617 /**
618 * Called from the input reader thread before a motion is enqueued when the screen is off.
619 *
620 * <p>There are some actions that need to be handled here because they
621 * affect the power state of the device, for example, waking on motions.
622 * Generally, it's best to keep as little as possible in the queue thread
623 * because it's the most fragile.
624 * @param policyFlags The policy flags associated with the motion.
625 *
626 * @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
627 * {@link #ACTION_POKE_USER_ACTIVITY} and {@link #ACTION_GO_TO_SLEEP} flags.
628 */
629 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags);
630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 /**
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700632 * Called from the input dispatcher thread before a key is dispatched to a window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 *
634 * <p>Allows you to define
Jeff Brown3915bb82010-11-05 15:02:16 -0700635 * behavior for keys that can not be overridden by applications.
636 * This method is called from the input thread, with no locks held.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 *
638 * @param win The window that currently has focus. This is where the key
639 * event will normally go.
Jeff Brown1f245102010-11-18 20:53:46 -0800640 * @param event The key event.
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700641 * @param policyFlags The policy flags associated with the key.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 * @return Returns true if the policy consumed the event and it should
643 * not be further dispatched.
644 */
Jeff Brown1f245102010-11-18 20:53:46 -0800645 public boolean interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646
647 /**
Jeff Brown3915bb82010-11-05 15:02:16 -0700648 * Called from the input dispatcher thread when an application did not handle
649 * a key that was dispatched to it.
650 *
651 * <p>Allows you to define default global behavior for keys that were not handled
652 * by applications. This method is called from the input thread, with no locks held.
653 *
654 * @param win The window that currently has focus. This is where the key
655 * event will normally go.
Jeff Brown1f245102010-11-18 20:53:46 -0800656 * @param event The key event.
Jeff Brown3915bb82010-11-05 15:02:16 -0700657 * @param policyFlags The policy flags associated with the key.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800658 * @return Returns an alternate key event to redispatch as a fallback, or null to give up.
659 * The caller is responsible for recycling the key event.
Jeff Brown3915bb82010-11-05 15:02:16 -0700660 */
Jeff Brown49ed71d2010-12-06 17:13:33 -0800661 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -0700662
663 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 * Called when layout of the windows is about to start.
665 *
666 * @param displayWidth The current full width of the screen.
667 * @param displayHeight The current full height of the screen.
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700668 * @param displayRotation The current rotation being applied to the base
669 * window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 */
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700671 public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672
673 /**
674 * Called for each window attached to the window manager as layout is
675 * proceeding. The implementation of this function must take care of
676 * setting the window's frame, either here or in finishLayout().
677 *
678 * @param win The window being positioned.
679 * @param attrs The LayoutParams of the window.
680 * @param attached For sub-windows, the window it is attached to; this
681 * window will already have had layoutWindow() called on it
682 * so you can use its Rect. Otherwise null.
683 */
684 public void layoutWindowLw(WindowState win,
685 WindowManager.LayoutParams attrs, WindowState attached);
686
687
688 /**
689 * Return the insets for the areas covered by system windows. These values
690 * are computed on the most recent layout, so they are not guaranteed to
691 * be correct.
692 *
693 * @param attrs The LayoutParams of the window.
694 * @param contentInset The areas covered by system windows, expressed as positive insets
695 *
696 */
697 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset);
698
699 /**
700 * Called when layout of the windows is finished. After this function has
701 * returned, all windows given to layoutWindow() <em>must</em> have had a
702 * frame assigned.
Dianne Hackborn7ac3f672009-03-31 18:00:53 -0700703 *
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800704 * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT},
705 * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER},
706 * or {@link #FINISH_LAYOUT_REDO_ANIM}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 */
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700708 public int finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700710 /** Layout state may have changed (so another layout will be performed) */
711 static final int FINISH_LAYOUT_REDO_LAYOUT = 0x0001;
712 /** Configuration state may have changed */
713 static final int FINISH_LAYOUT_REDO_CONFIG = 0x0002;
714 /** Wallpaper may need to move */
715 static final int FINISH_LAYOUT_REDO_WALLPAPER = 0x0004;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800716 /** Need to recompute animations */
717 static final int FINISH_LAYOUT_REDO_ANIM = 0x0008;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 /**
720 * Called when animation of the windows is about to start.
721 *
722 * @param displayWidth The current full width of the screen.
723 * @param displayHeight The current full height of the screen.
724 */
725 public void beginAnimationLw(int displayWidth, int displayHeight);
726
727 /**
728 * Called each time a window is animating.
729 *
730 * @param win The window being positioned.
731 * @param attrs The LayoutParams of the window.
732 */
733 public void animatingWindowLw(WindowState win,
734 WindowManager.LayoutParams attrs);
735
736 /**
737 * Called when animation of the windows is finished. If in this function you do
738 * something that may have modified the animation state of another window,
739 * be sure to return true in order to perform another animation frame.
740 *
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800741 * @return Return any bit set of {@link #FINISH_LAYOUT_REDO_LAYOUT},
742 * {@link #FINISH_LAYOUT_REDO_CONFIG}, {@link #FINISH_LAYOUT_REDO_WALLPAPER},
743 * or {@link #FINISH_LAYOUT_REDO_ANIM}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 */
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800745 public int finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746
747 /**
Dianne Hackbornde2606d2009-12-18 16:53:55 -0800748 * Return true if it is okay to perform animations for an app transition
749 * that is about to occur. You may return false for this if, for example,
750 * the lock screen is currently displayed so the switch should happen
751 * immediately.
752 */
753 public boolean allowAppAnimationsLw();
Joe Onorato664644d2011-01-23 17:53:23 -0800754
755
756 /**
757 * A new window has been focused.
758 */
759 public void focusChanged(WindowState lastFocus, WindowState newFocus);
Dianne Hackbornde2606d2009-12-18 16:53:55 -0800760
761 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 * Called after the screen turns off.
763 *
764 * @param why {@link #OFF_BECAUSE_OF_USER} or
765 * {@link #OFF_BECAUSE_OF_TIMEOUT}.
766 */
767 public void screenTurnedOff(int why);
768
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700769 public interface ScreenOnListener {
770 void onScreenOn();
771 };
772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 /**
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700774 * Called when the power manager would like to turn the screen on.
775 * Must call back on the listener to tell it when the higher-level system
776 * is ready for the screen to go on (i.e. the lock screen is shown).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 */
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700778 public void screenTurningOn(ScreenOnListener screenOnListener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779
780 /**
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700781 * Return whether the screen is about to turn on or is currently on.
Dianne Hackbornde2606d2009-12-18 16:53:55 -0800782 */
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700783 public boolean isScreenOnEarly();
784
785 /**
786 * Return whether the screen is fully turned on.
787 */
788 public boolean isScreenOnFully();
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700789
Dianne Hackbornde2606d2009-12-18 16:53:55 -0800790 /**
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700791 * Tell the policy that the lid switch has changed state.
792 * @param whenNanos The time when the change occurred in uptime nanoseconds.
793 * @param lidOpen True if the lid is now open.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700795 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 * Tell the policy if anyone is requesting that keyguard not come on.
799 *
800 * @param enabled Whether keyguard can be on or not. does not actually
801 * turn it on, unless it was previously disabled with this function.
802 *
803 * @see android.app.KeyguardManager.KeyguardLock#disableKeyguard()
804 * @see android.app.KeyguardManager.KeyguardLock#reenableKeyguard()
805 */
806 public void enableKeyguard(boolean enabled);
807
808 /**
809 * Callback used by {@link WindowManagerPolicy#exitKeyguardSecurely}
810 */
811 interface OnKeyguardExitResult {
812 void onKeyguardExitResult(boolean success);
813 }
814
815 /**
816 * Tell the policy if anyone is requesting the keyguard to exit securely
817 * (this would be called after the keyguard was disabled)
818 * @param callback Callback to send the result back.
819 * @see android.app.KeyguardManager#exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult)
820 */
821 void exitKeyguardSecurely(OnKeyguardExitResult callback);
822
823 /**
Mike Lockwood520d8bc2011-02-18 13:23:13 -0500824 * isKeyguardLocked
825 *
826 * Return whether the keyguard is currently locked.
827 *
828 * @return true if in keyguard is locked.
829 */
830 public boolean isKeyguardLocked();
831
832 /**
833 * isKeyguardSecure
834 *
835 * Return whether the keyguard requires a password to unlock.
836 *
837 * @return true if in keyguard is secure.
838 */
839 public boolean isKeyguardSecure();
840
841 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 * inKeyguardRestrictedKeyInputMode
843 *
844 * if keyguard screen is showing or in restricted key input mode (i.e. in
845 * keyguard password emergency screen). When in such mode, certain keys,
846 * such as the Home key and the right soft keys, don't work.
847 *
848 * @return true if in keyguard restricted input mode.
849 */
850 public boolean inKeyguardRestrictedKeyInputMode();
851
852 /**
Jeff Brown01a98dd2011-09-20 15:08:29 -0700853 * Given an orientation constant, returns the appropriate surface rotation,
854 * taking into account sensors, docking mode, rotation lock, and other factors.
855 *
856 * @param orientation An orientation constant, such as
857 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
858 * @param lastRotation The most recently used rotation.
859 * @return The surface rotation to use.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 */
Jeff Brown01a98dd2011-09-20 15:08:29 -0700861 public int rotationForOrientationLw(int orientation, int lastRotation);
862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 /**
Jeff Brown01a98dd2011-09-20 15:08:29 -0700864 * Given an orientation constant and a rotation, returns true if the rotation
865 * has compatible metrics to the requested orientation. For example, if
866 * the application requested landscape and got seascape, then the rotation
867 * has compatible metrics; if the application requested portrait and got landscape,
868 * then the rotation has incompatible metrics; if the application did not specify
869 * a preference, then anything goes.
870 *
871 * @param orientation An orientation constant, such as
872 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
873 * @param rotation The rotation to check.
874 * @return True if the rotation is compatible with the requested orientation.
Dianne Hackborndacea8c2011-04-21 17:26:39 -0700875 */
Jeff Brown01a98dd2011-09-20 15:08:29 -0700876 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation);
Dianne Hackborndacea8c2011-04-21 17:26:39 -0700877
878 /**
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700879 * Called when the system is mostly done booting to determine whether
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 * the system should go into safe mode.
881 */
882 public boolean detectSafeMode();
883
884 /**
885 * Called when the system is mostly done booting.
886 */
887 public void systemReady();
888
889 /**
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700890 * Called when the system is done booting to the point where the
891 * user can start interacting with it.
892 */
893 public void systemBooted();
894
895 /**
Dianne Hackborn661cd522011-08-22 00:26:20 -0700896 * Show boot time message to the user.
897 */
898 public void showBootMessage(final CharSequence msg, final boolean always);
899
900 /**
901 * Hide the UI for showing boot messages, never to be displayed again.
902 */
903 public void hideBootMessages();
904
905 /**
Mike Lockwoodef731622010-01-27 17:51:34 -0500906 * Called when userActivity is signalled in the power manager.
907 * This is safe to call from any thread, with any window manager locks held or not.
908 */
909 public void userActivity();
910
911 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 * Called when we have finished booting and can now display the home
913 * screen to the user. This wilWl happen after systemReady(), and at
914 * this point the display is active.
915 */
916 public void enableScreenAfterBoot();
917
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700918 public void setCurrentOrientationLw(int newOrientation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919
920 /**
921 * Call from application to perform haptic feedback on its window.
922 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700923 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924
925 /**
Daniel Sandler0601eb72011-04-13 01:01:32 -0400926 * Called when we have started keeping the screen on because a window
927 * requesting this has become visible.
928 */
929 public void screenOnStartedLw();
930
931 /**
932 * Called when we have stopped keeping the screen on because the last window
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 * requesting this is no longer visible.
934 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700935 public void screenOnStoppedLw();
Mike Lockwood3d0ea722009-10-21 22:58:29 -0400936
937 /**
938 * Return false to disable key repeat events from being generated.
939 */
940 public boolean allowKeyRepeat();
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400941
942 /**
943 * Inform the policy that the user has chosen a preferred orientation ("rotation lock").
944 *
945 * @param mode One of {@link WindowManagerPolicy#USER_ROTATION_LOCKED} or
946 * {@link * WindowManagerPolicy#USER_ROTATION_FREE}.
947 * @param rotation One of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90},
948 * {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270}.
949 */
950 public void setUserRotationMode(int mode, int rotation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800951
952 /**
953 * Print the WindowManagerPolicy's state into the given stream.
954 *
955 * @param prefix Text to print at the front of each line.
956 * @param fd The raw file descriptor that the dump is being sent to.
957 * @param writer The PrintWriter to which you should dump your state. This will be
958 * closed for you after you return.
959 * @param args additional arguments to the dump request.
960 */
961 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962}