blob: b27736a3147e31ca4f4c67da1a46d528dd25890d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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 com.android.server;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.KeyInputQueue.QueuedEvent;
52import com.android.server.am.BatteryStatsService;
53
54import android.Manifest;
55import android.app.ActivityManagerNative;
56import android.app.IActivityManager;
57import android.content.Context;
58import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
62import android.graphics.Matrix;
63import android.graphics.PixelFormat;
64import android.graphics.Rect;
65import android.graphics.Region;
66import android.os.BatteryStats;
67import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070068import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.os.Debug;
70import android.os.Handler;
71import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070072import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.LocalPowerManager;
74import android.os.Looper;
75import android.os.Message;
76import android.os.Parcel;
77import android.os.ParcelFileDescriptor;
78import android.os.Power;
79import android.os.PowerManager;
80import android.os.Process;
81import android.os.RemoteException;
82import android.os.ServiceManager;
83import android.os.SystemClock;
84import android.os.SystemProperties;
85import android.os.TokenWatcher;
86import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070087import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080089import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.util.SparseIntArray;
91import android.view.Display;
92import android.view.Gravity;
93import android.view.IApplicationToken;
94import android.view.IOnKeyguardExitResult;
95import android.view.IRotationWatcher;
96import android.view.IWindow;
97import android.view.IWindowManager;
98import android.view.IWindowSession;
99import android.view.KeyEvent;
100import android.view.MotionEvent;
101import android.view.RawInputEvent;
102import android.view.Surface;
103import android.view.SurfaceSession;
104import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700105import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106import android.view.ViewTreeObserver;
107import android.view.WindowManager;
108import android.view.WindowManagerImpl;
109import android.view.WindowManagerPolicy;
110import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700111import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112import android.view.animation.Animation;
113import android.view.animation.AnimationUtils;
114import android.view.animation.Transformation;
115
116import java.io.BufferedWriter;
117import java.io.File;
118import java.io.FileDescriptor;
119import java.io.IOException;
120import java.io.OutputStream;
121import java.io.OutputStreamWriter;
122import java.io.PrintWriter;
123import java.io.StringWriter;
124import java.net.Socket;
125import java.util.ArrayList;
126import java.util.HashMap;
127import java.util.HashSet;
128import java.util.Iterator;
129import java.util.List;
130
131/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700132public class WindowManagerService extends IWindowManager.Stub
133 implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 static final String TAG = "WindowManager";
135 static final boolean DEBUG = false;
136 static final boolean DEBUG_FOCUS = false;
137 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800138 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800139 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 static final boolean DEBUG_LAYERS = false;
141 static final boolean DEBUG_INPUT = false;
142 static final boolean DEBUG_INPUT_METHOD = false;
143 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700144 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 static final boolean DEBUG_ORIENTATION = false;
146 static final boolean DEBUG_APP_TRANSITIONS = false;
147 static final boolean DEBUG_STARTING_WINDOW = false;
148 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700149 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700151 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700152 static final boolean MEASURE_LATENCY = false;
153 static private LatencyTimer lt;
154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean PROFILE_ORIENTATION = false;
156 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700157 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 /** How long to wait for subsequent key repeats, in milliseconds */
160 static final int KEY_REPEAT_DELAY = 50;
161
162 /** How much to multiply the policy's type layer, to reserve room
163 * for multiple windows of the same type and Z-ordering adjustment
164 * with TYPE_LAYER_OFFSET. */
165 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
168 * or below others in the same layer. */
169 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 /** How much to increment the layer for each window, to reserve room
172 * for effect surfaces between them.
173 */
174 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** The maximum length we will accept for a loaded animation duration:
177 * this is 10 seconds.
178 */
179 static final int MAX_ANIMATION_DURATION = 10*1000;
180
181 /** Amount of time (in milliseconds) to animate the dim surface from one
182 * value to another, when no window animation is driving it.
183 */
184 static final int DEFAULT_DIM_DURATION = 200;
185
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700186 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
187 * compatible windows.
188 */
189 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /** Adjustment to time to perform a dim, to make it more dramatic.
192 */
193 static final int DIM_DURATION_MULTIPLIER = 6;
Romain Guy06882f82009-06-10 13:36:04 -0700194
Dianne Hackborncfaef692009-06-15 14:24:44 -0700195 static final int INJECT_FAILED = 0;
196 static final int INJECT_SUCCEEDED = 1;
197 static final int INJECT_NO_PERMISSION = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 static final int UPDATE_FOCUS_NORMAL = 0;
200 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
201 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
202 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700203
Michael Chane96440f2009-05-06 10:27:36 -0700204 /** The minimum time between dispatching touch events. */
205 int mMinWaitTimeBetweenTouchEvents = 1000 / 35;
206
207 // Last touch event time
208 long mLastTouchEventTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700209
Michael Chane96440f2009-05-06 10:27:36 -0700210 // Last touch event type
211 int mLastTouchEventType = OTHER_EVENT;
Romain Guy06882f82009-06-10 13:36:04 -0700212
Michael Chane96440f2009-05-06 10:27:36 -0700213 // Time to wait before calling useractivity again. This saves CPU usage
214 // when we get a flood of touch events.
215 static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000;
216
217 // Last time we call user activity
218 long mLastUserActivityCallTime = 0;
219
Romain Guy06882f82009-06-10 13:36:04 -0700220 // Last time we updated battery stats
Michael Chane96440f2009-05-06 10:27:36 -0700221 long mLastBatteryStatsCallTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700224 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225
226 /**
227 * Condition waited on by {@link #reenableKeyguard} to know the call to
228 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 * This is set to true only if mKeyguardTokenWatcher.acquired() has
230 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500232 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233
Mike Lockwood983ee092009-11-22 01:42:24 -0500234 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
235 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 public void acquired() {
237 mPolicy.enableKeyguard(false);
Mike Lockwood983ee092009-11-22 01:42:24 -0500238 mKeyguardDisabled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 }
240 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700241 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500242 synchronized (mKeyguardTokenWatcher) {
243 mKeyguardDisabled = false;
244 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 }
246 }
247 };
248
249 final Context mContext;
250
251 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
256
257 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 /**
262 * All currently active sessions with clients.
263 */
264 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 /**
267 * Mapping from an IWindow IBinder to the server's Window object.
268 * This is also used as the lock for all of our state.
269 */
270 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
271
272 /**
273 * Mapping from a token IBinder to a WindowToken object.
274 */
275 final HashMap<IBinder, WindowToken> mTokenMap =
276 new HashMap<IBinder, WindowToken>();
277
278 /**
279 * The same tokens as mTokenMap, stored in a list for efficient iteration
280 * over them.
281 */
282 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 /**
285 * Window tokens that are in the process of exiting, but still
286 * on screen for animations.
287 */
288 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
289
290 /**
291 * Z-ordered (bottom-most first) list of all application tokens, for
292 * controlling the ordering of windows in different applications. This
293 * contains WindowToken objects.
294 */
295 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
296
297 /**
298 * Application tokens that are in the process of exiting, but still
299 * on screen for animations.
300 */
301 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
302
303 /**
304 * List of window tokens that have finished starting their application,
305 * and now need to have the policy remove their windows.
306 */
307 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
308
309 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700310 * This was the app token that was used to retrieve the last enter
311 * animation. It will be used for the next exit animation.
312 */
313 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800314
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700315 /**
316 * These were the layout params used to retrieve the last enter animation.
317 * They will be used for the next exit animation.
318 */
319 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800320
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700321 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 * Z-ordered (bottom-most first) list of all Window objects.
323 */
324 final ArrayList mWindows = new ArrayList();
325
326 /**
327 * Windows that are being resized. Used so we can tell the client about
328 * the resize after closing the transaction in which we resized the
329 * underlying surface.
330 */
331 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
332
333 /**
334 * Windows whose animations have ended and now must be removed.
335 */
336 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
337
338 /**
339 * Windows whose surface should be destroyed.
340 */
341 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
342
343 /**
344 * Windows that have lost input focus and are waiting for the new
345 * focus window to be displayed before they are told about this.
346 */
347 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
348
349 /**
350 * This is set when we have run out of memory, and will either be an empty
351 * list or contain windows that need to be force removed.
352 */
353 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700358 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 Surface mBlurSurface;
360 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 final float[] mTmpFloats = new float[9];
365
366 boolean mSafeMode;
367 boolean mDisplayEnabled = false;
368 boolean mSystemBooted = false;
369 int mRotation = 0;
370 int mRequestedRotation = 0;
371 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700372 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 ArrayList<IRotationWatcher> mRotationWatchers
374 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 boolean mLayoutNeeded = true;
377 boolean mAnimationPending = false;
378 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800379 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 boolean mWindowsFreezingScreen = false;
381 long mFreezeGcPending = 0;
382 int mAppsFreezingScreen = 0;
383
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800384 int mLayoutSeq = 0;
385
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800386 // State while inside of layoutAndPlaceSurfacesLocked().
387 boolean mFocusMayChange;
388
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800389 Configuration mCurConfiguration = new Configuration();
390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 // This is held as long as we have the screen frozen, to give us time to
392 // perform a rotation animation when turning off shows the lock screen which
393 // changes the orientation.
394 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 // State management of app transitions. When we are preparing for a
397 // transition, mNextAppTransition will be the kind of transition to
398 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
399 // mOpeningApps and mClosingApps are the lists of tokens that will be
400 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700401 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700402 String mNextAppTransitionPackage;
403 int mNextAppTransitionEnter;
404 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700406 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 boolean mAppTransitionTimeout = false;
408 boolean mStartingIconInTransition = false;
409 boolean mSkipAppTransitionAnimation = false;
410 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
411 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700412 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
413 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 //flag to detect fat touch events
416 boolean mFatTouch = false;
417 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 H mH = new H();
420
421 WindowState mCurrentFocus = null;
422 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 // This just indicates the window the input method is on top of, not
425 // necessarily the window its input is going to.
426 WindowState mInputMethodTarget = null;
427 WindowState mUpcomingInputMethodTarget = null;
428 boolean mInputMethodTargetWaitingAnim;
429 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 WindowState mInputMethodWindow = null;
432 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
433
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700434 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800435
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700436 // If non-null, this is the currently visible window that is associated
437 // with the wallpaper.
438 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700439 // If non-null, we are in the middle of animating from one wallpaper target
440 // to another, and this is the lower one in Z-order.
441 WindowState mLowerWallpaperTarget = null;
442 // If non-null, we are in the middle of animating from one wallpaper target
443 // to another, and this is the higher one in Z-order.
444 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700445 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700446 float mLastWallpaperX = -1;
447 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800448 float mLastWallpaperXStep = -1;
449 float mLastWallpaperYStep = -1;
Dianne Hackborn6adba242009-11-10 11:10:09 -0800450 boolean mSendingPointersToWallpaper = false;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700451 // This is set when we are waiting for a wallpaper to tell us it is done
452 // changing its scroll position.
453 WindowState mWaitingOnWallpaper;
454 // The last time we had a timeout when waiting for a wallpaper.
455 long mLastWallpaperTimeoutTime;
456 // We give a wallpaper up to 150ms to finish scrolling.
457 static final long WALLPAPER_TIMEOUT = 150;
458 // Time we wait after a timeout before trying to wait again.
459 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 AppWindowToken mFocusedApp = null;
462
463 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 float mWindowAnimationScale = 1.0f;
466 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 final KeyWaiter mKeyWaiter = new KeyWaiter();
469 final KeyQ mQueue;
470 final InputDispatcherThread mInputThread;
471
472 // Who is holding the screen on.
473 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700474
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700475 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 /**
478 * Whether the UI is currently running in touch mode (not showing
479 * navigational focus because the user is directly pressing the screen).
480 */
481 boolean mInTouchMode = false;
482
483 private ViewServer mViewServer;
484
485 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700486
Dianne Hackbornc485a602009-03-24 22:39:49 -0700487 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700488 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700489
490 // The frame use to limit the size of the app running in compatibility mode.
491 Rect mCompatibleScreenFrame = new Rect();
492 // The surface used to fill the outer rim of the app running in compatibility mode.
493 Surface mBackgroundFillerSurface = null;
494 boolean mBackgroundFillerShown = false;
495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 public static WindowManagerService main(Context context,
497 PowerManagerService pm, boolean haveInputMethods) {
498 WMThread thr = new WMThread(context, pm, haveInputMethods);
499 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 synchronized (thr) {
502 while (thr.mService == null) {
503 try {
504 thr.wait();
505 } catch (InterruptedException e) {
506 }
507 }
508 }
Romain Guy06882f82009-06-10 13:36:04 -0700509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 return thr.mService;
511 }
Romain Guy06882f82009-06-10 13:36:04 -0700512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 static class WMThread extends Thread {
514 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 private final Context mContext;
517 private final PowerManagerService mPM;
518 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 public WMThread(Context context, PowerManagerService pm,
521 boolean haveInputMethods) {
522 super("WindowManager");
523 mContext = context;
524 mPM = pm;
525 mHaveInputMethods = haveInputMethods;
526 }
Romain Guy06882f82009-06-10 13:36:04 -0700527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 public void run() {
529 Looper.prepare();
530 WindowManagerService s = new WindowManagerService(mContext, mPM,
531 mHaveInputMethods);
532 android.os.Process.setThreadPriority(
533 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 synchronized (this) {
536 mService = s;
537 notifyAll();
538 }
Romain Guy06882f82009-06-10 13:36:04 -0700539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 Looper.loop();
541 }
542 }
543
544 static class PolicyThread extends Thread {
545 private final WindowManagerPolicy mPolicy;
546 private final WindowManagerService mService;
547 private final Context mContext;
548 private final PowerManagerService mPM;
549 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 public PolicyThread(WindowManagerPolicy policy,
552 WindowManagerService service, Context context,
553 PowerManagerService pm) {
554 super("WindowManagerPolicy");
555 mPolicy = policy;
556 mService = service;
557 mContext = context;
558 mPM = pm;
559 }
Romain Guy06882f82009-06-10 13:36:04 -0700560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 public void run() {
562 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800563 WindowManagerPolicyThread.set(this, Looper.myLooper());
564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800566 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 android.os.Process.setThreadPriority(
568 android.os.Process.THREAD_PRIORITY_FOREGROUND);
569 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 synchronized (this) {
572 mRunning = true;
573 notifyAll();
574 }
Romain Guy06882f82009-06-10 13:36:04 -0700575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 Looper.loop();
577 }
578 }
579
580 private WindowManagerService(Context context, PowerManagerService pm,
581 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700582 if (MEASURE_LATENCY) {
583 lt = new LatencyTimer(100, 1000);
584 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 mContext = context;
587 mHaveInputMethods = haveInputMethods;
588 mLimitedAlphaCompositing = context.getResources().getBoolean(
589 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 mPowerManager = pm;
592 mPowerManager.setPolicy(mPolicy);
593 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
594 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
595 "SCREEN_FROZEN");
596 mScreenFrozenLock.setReferenceCounted(false);
597
598 mActivityManager = ActivityManagerNative.getDefault();
599 mBatteryStats = BatteryStatsService.getService();
600
601 // Get persisted window scale setting
602 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
603 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
604 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
605 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700606
Michael Chan9f028e62009-08-04 17:37:46 -0700607 int max_events_per_sec = 35;
608 try {
609 max_events_per_sec = Integer.parseInt(SystemProperties
610 .get("windowsmgr.max_events_per_sec"));
611 if (max_events_per_sec < 1) {
612 max_events_per_sec = 35;
613 }
614 } catch (NumberFormatException e) {
615 }
616 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 mQueue = new KeyQ();
619
620 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
623 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 synchronized (thr) {
626 while (!thr.mRunning) {
627 try {
628 thr.wait();
629 } catch (InterruptedException e) {
630 }
631 }
632 }
Romain Guy06882f82009-06-10 13:36:04 -0700633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 // Add ourself to the Watchdog monitors.
637 Watchdog.getInstance().addMonitor(this);
638 }
639
640 @Override
641 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
642 throws RemoteException {
643 try {
644 return super.onTransact(code, data, reply, flags);
645 } catch (RuntimeException e) {
646 // The window manager only throws security exceptions, so let's
647 // log all others.
648 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800649 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 }
651 throw e;
652 }
653 }
654
655 private void placeWindowAfter(Object pos, WindowState window) {
656 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800657 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 TAG, "Adding window " + window + " at "
659 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
660 mWindows.add(i+1, window);
661 }
662
663 private void placeWindowBefore(Object pos, WindowState window) {
664 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800665 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 TAG, "Adding window " + window + " at "
667 + i + " of " + mWindows.size() + " (before " + pos + ")");
668 mWindows.add(i, window);
669 }
670
671 //This method finds out the index of a window that has the same app token as
672 //win. used for z ordering the windows in mWindows
673 private int findIdxBasedOnAppTokens(WindowState win) {
674 //use a local variable to cache mWindows
675 ArrayList localmWindows = mWindows;
676 int jmax = localmWindows.size();
677 if(jmax == 0) {
678 return -1;
679 }
680 for(int j = (jmax-1); j >= 0; j--) {
681 WindowState wentry = (WindowState)localmWindows.get(j);
682 if(wentry.mAppToken == win.mAppToken) {
683 return j;
684 }
685 }
686 return -1;
687 }
Romain Guy06882f82009-06-10 13:36:04 -0700688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
690 final IWindow client = win.mClient;
691 final WindowToken token = win.mToken;
692 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 final int N = localmWindows.size();
695 final WindowState attached = win.mAttachedWindow;
696 int i;
697 if (attached == null) {
698 int tokenWindowsPos = token.windows.size();
699 if (token.appWindowToken != null) {
700 int index = tokenWindowsPos-1;
701 if (index >= 0) {
702 // If this application has existing windows, we
703 // simply place the new window on top of them... but
704 // keep the starting window on top.
705 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
706 // Base windows go behind everything else.
707 placeWindowBefore(token.windows.get(0), win);
708 tokenWindowsPos = 0;
709 } else {
710 AppWindowToken atoken = win.mAppToken;
711 if (atoken != null &&
712 token.windows.get(index) == atoken.startingWindow) {
713 placeWindowBefore(token.windows.get(index), win);
714 tokenWindowsPos--;
715 } else {
716 int newIdx = findIdxBasedOnAppTokens(win);
717 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700718 //there is a window above this one associated with the same
719 //apptoken note that the window could be a floating window
720 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800722 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700723 TAG, "Adding window " + win + " at "
724 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700726 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 }
728 }
729 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800730 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 TAG, "Figuring out where to add app window "
732 + client.asBinder() + " (token=" + token + ")");
733 // Figure out where the window should go, based on the
734 // order of applications.
735 final int NA = mAppTokens.size();
736 Object pos = null;
737 for (i=NA-1; i>=0; i--) {
738 AppWindowToken t = mAppTokens.get(i);
739 if (t == token) {
740 i--;
741 break;
742 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800743
Dianne Hackborna8f60182009-09-01 19:01:50 -0700744 // We haven't reached the token yet; if this token
745 // is not going to the bottom and has windows, we can
746 // use it as an anchor for when we do reach the token.
747 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 pos = t.windows.get(0);
749 }
750 }
751 // We now know the index into the apps. If we found
752 // an app window above, that gives us the position; else
753 // we need to look some more.
754 if (pos != null) {
755 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700756 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 mTokenMap.get(((WindowState)pos).mClient.asBinder());
758 if (atoken != null) {
759 final int NC = atoken.windows.size();
760 if (NC > 0) {
761 WindowState bottom = atoken.windows.get(0);
762 if (bottom.mSubLayer < 0) {
763 pos = bottom;
764 }
765 }
766 }
767 placeWindowBefore(pos, win);
768 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700769 // Continue looking down until we find the first
770 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 while (i >= 0) {
772 AppWindowToken t = mAppTokens.get(i);
773 final int NW = t.windows.size();
774 if (NW > 0) {
775 pos = t.windows.get(NW-1);
776 break;
777 }
778 i--;
779 }
780 if (pos != null) {
781 // Move in front of any windows attached to this
782 // one.
783 WindowToken atoken =
784 mTokenMap.get(((WindowState)pos).mClient.asBinder());
785 if (atoken != null) {
786 final int NC = atoken.windows.size();
787 if (NC > 0) {
788 WindowState top = atoken.windows.get(NC-1);
789 if (top.mSubLayer >= 0) {
790 pos = top;
791 }
792 }
793 }
794 placeWindowAfter(pos, win);
795 } else {
796 // Just search for the start of this layer.
797 final int myLayer = win.mBaseLayer;
798 for (i=0; i<N; i++) {
799 WindowState w = (WindowState)localmWindows.get(i);
800 if (w.mBaseLayer > myLayer) {
801 break;
802 }
803 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800804 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700805 TAG, "Adding window " + win + " at "
806 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 localmWindows.add(i, win);
808 }
809 }
810 }
811 } else {
812 // Figure out where window should go, based on layer.
813 final int myLayer = win.mBaseLayer;
814 for (i=N-1; i>=0; i--) {
815 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
816 i++;
817 break;
818 }
819 }
820 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800821 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700822 TAG, "Adding window " + win + " at "
823 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 localmWindows.add(i, win);
825 }
826 if (addToToken) {
827 token.windows.add(tokenWindowsPos, win);
828 }
829
830 } else {
831 // Figure out this window's ordering relative to the window
832 // it is attached to.
833 final int NA = token.windows.size();
834 final int sublayer = win.mSubLayer;
835 int largestSublayer = Integer.MIN_VALUE;
836 WindowState windowWithLargestSublayer = null;
837 for (i=0; i<NA; i++) {
838 WindowState w = token.windows.get(i);
839 final int wSublayer = w.mSubLayer;
840 if (wSublayer >= largestSublayer) {
841 largestSublayer = wSublayer;
842 windowWithLargestSublayer = w;
843 }
844 if (sublayer < 0) {
845 // For negative sublayers, we go below all windows
846 // in the same sublayer.
847 if (wSublayer >= sublayer) {
848 if (addToToken) {
849 token.windows.add(i, win);
850 }
851 placeWindowBefore(
852 wSublayer >= 0 ? attached : w, win);
853 break;
854 }
855 } else {
856 // For positive sublayers, we go above all windows
857 // in the same sublayer.
858 if (wSublayer > sublayer) {
859 if (addToToken) {
860 token.windows.add(i, win);
861 }
862 placeWindowBefore(w, win);
863 break;
864 }
865 }
866 }
867 if (i >= NA) {
868 if (addToToken) {
869 token.windows.add(win);
870 }
871 if (sublayer < 0) {
872 placeWindowBefore(attached, win);
873 } else {
874 placeWindowAfter(largestSublayer >= 0
875 ? windowWithLargestSublayer
876 : attached,
877 win);
878 }
879 }
880 }
Romain Guy06882f82009-06-10 13:36:04 -0700881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 if (win.mAppToken != null && addToToken) {
883 win.mAppToken.allAppWindows.add(win);
884 }
885 }
Romain Guy06882f82009-06-10 13:36:04 -0700886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 static boolean canBeImeTarget(WindowState w) {
888 final int fl = w.mAttrs.flags
889 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
890 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
891 return w.isVisibleOrAdding();
892 }
893 return false;
894 }
Romain Guy06882f82009-06-10 13:36:04 -0700895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
897 final ArrayList localmWindows = mWindows;
898 final int N = localmWindows.size();
899 WindowState w = null;
900 int i = N;
901 while (i > 0) {
902 i--;
903 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700904
Joe Onorato8a9b2202010-02-26 18:56:32 -0800905 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 // + Integer.toHexString(w.mAttrs.flags));
907 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800908 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 // Yet more tricksyness! If this window is a "starting"
911 // window, we do actually want to be on top of it, but
912 // it is not -really- where input will go. So if the caller
913 // is not actually looking to move the IME, look down below
914 // for a real window to target...
915 if (!willMove
916 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
917 && i > 0) {
918 WindowState wb = (WindowState)localmWindows.get(i-1);
919 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
920 i--;
921 w = wb;
922 }
923 }
924 break;
925 }
926 }
Romain Guy06882f82009-06-10 13:36:04 -0700927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700929
Joe Onorato8a9b2202010-02-26 18:56:32 -0800930 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 if (willMove && w != null) {
934 final WindowState curTarget = mInputMethodTarget;
935 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 // Now some fun for dealing with window animations that
938 // modify the Z order. We need to look at all windows below
939 // the current target that are in this app, finding the highest
940 // visible one in layering.
941 AppWindowToken token = curTarget.mAppToken;
942 WindowState highestTarget = null;
943 int highestPos = 0;
944 if (token.animating || token.animation != null) {
945 int pos = 0;
946 pos = localmWindows.indexOf(curTarget);
947 while (pos >= 0) {
948 WindowState win = (WindowState)localmWindows.get(pos);
949 if (win.mAppToken != token) {
950 break;
951 }
952 if (!win.mRemoved) {
953 if (highestTarget == null || win.mAnimLayer >
954 highestTarget.mAnimLayer) {
955 highestTarget = win;
956 highestPos = pos;
957 }
958 }
959 pos--;
960 }
961 }
Romain Guy06882f82009-06-10 13:36:04 -0700962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800964 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 + mNextAppTransition + " " + highestTarget
966 + " animating=" + highestTarget.isAnimating()
967 + " layer=" + highestTarget.mAnimLayer
968 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700969
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700970 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 // If we are currently setting up for an animation,
972 // hold everything until we can find out what will happen.
973 mInputMethodTargetWaitingAnim = true;
974 mInputMethodTarget = highestTarget;
975 return highestPos + 1;
976 } else if (highestTarget.isAnimating() &&
977 highestTarget.mAnimLayer > w.mAnimLayer) {
978 // If the window we are currently targeting is involved
979 // with an animation, and it is on top of the next target
980 // we will be over, then hold off on moving until
981 // that is done.
982 mInputMethodTarget = highestTarget;
983 return highestPos + 1;
984 }
985 }
986 }
987 }
Romain Guy06882f82009-06-10 13:36:04 -0700988
Joe Onorato8a9b2202010-02-26 18:56:32 -0800989 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 if (w != null) {
991 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800992 if (DEBUG_INPUT_METHOD) {
993 RuntimeException e = null;
994 if (!HIDE_STACK_CRAWLS) {
995 e = new RuntimeException();
996 e.fillInStackTrace();
997 }
998 Slog.w(TAG, "Moving IM target from "
999 + mInputMethodTarget + " to " + w, e);
1000 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 mInputMethodTarget = w;
1002 if (w.mAppToken != null) {
1003 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1004 } else {
1005 setInputMethodAnimLayerAdjustment(0);
1006 }
1007 }
1008 return i+1;
1009 }
1010 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001011 if (DEBUG_INPUT_METHOD) {
1012 RuntimeException e = null;
1013 if (!HIDE_STACK_CRAWLS) {
1014 e = new RuntimeException();
1015 e.fillInStackTrace();
1016 }
1017 Slog.w(TAG, "Moving IM target from "
1018 + mInputMethodTarget + " to null", e);
1019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 mInputMethodTarget = null;
1021 setInputMethodAnimLayerAdjustment(0);
1022 }
1023 return -1;
1024 }
Romain Guy06882f82009-06-10 13:36:04 -07001025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 void addInputMethodWindowToListLocked(WindowState win) {
1027 int pos = findDesiredInputMethodWindowIndexLocked(true);
1028 if (pos >= 0) {
1029 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001030 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001031 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 mWindows.add(pos, win);
1033 moveInputMethodDialogsLocked(pos+1);
1034 return;
1035 }
1036 win.mTargetAppToken = null;
1037 addWindowToListInOrderLocked(win, true);
1038 moveInputMethodDialogsLocked(pos);
1039 }
Romain Guy06882f82009-06-10 13:36:04 -07001040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001042 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 mInputMethodAnimLayerAdjustment = adj;
1044 WindowState imw = mInputMethodWindow;
1045 if (imw != null) {
1046 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001047 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 + " anim layer: " + imw.mAnimLayer);
1049 int wi = imw.mChildWindows.size();
1050 while (wi > 0) {
1051 wi--;
1052 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1053 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001054 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 + " anim layer: " + cw.mAnimLayer);
1056 }
1057 }
1058 int di = mInputMethodDialogs.size();
1059 while (di > 0) {
1060 di --;
1061 imw = mInputMethodDialogs.get(di);
1062 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001063 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 + " anim layer: " + imw.mAnimLayer);
1065 }
1066 }
Romain Guy06882f82009-06-10 13:36:04 -07001067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1069 int wpos = mWindows.indexOf(win);
1070 if (wpos >= 0) {
1071 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001072 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 mWindows.remove(wpos);
1074 int NC = win.mChildWindows.size();
1075 while (NC > 0) {
1076 NC--;
1077 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1078 int cpos = mWindows.indexOf(cw);
1079 if (cpos >= 0) {
1080 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001081 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001082 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 mWindows.remove(cpos);
1084 }
1085 }
1086 }
1087 return interestingPos;
1088 }
Romain Guy06882f82009-06-10 13:36:04 -07001089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 private void reAddWindowToListInOrderLocked(WindowState win) {
1091 addWindowToListInOrderLocked(win, false);
1092 // This is a hack to get all of the child windows added as well
1093 // at the right position. Child windows should be rare and
1094 // this case should be rare, so it shouldn't be that big a deal.
1095 int wpos = mWindows.indexOf(win);
1096 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001097 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001098 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 mWindows.remove(wpos);
1100 reAddWindowLocked(wpos, win);
1101 }
1102 }
Romain Guy06882f82009-06-10 13:36:04 -07001103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 void logWindowList(String prefix) {
1105 int N = mWindows.size();
1106 while (N > 0) {
1107 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001108 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 }
1110 }
Romain Guy06882f82009-06-10 13:36:04 -07001111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 void moveInputMethodDialogsLocked(int pos) {
1113 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001116 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 for (int i=0; i<N; i++) {
1118 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1119 }
1120 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001121 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 logWindowList(" ");
1123 }
Romain Guy06882f82009-06-10 13:36:04 -07001124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 if (pos >= 0) {
1126 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1127 if (pos < mWindows.size()) {
1128 WindowState wp = (WindowState)mWindows.get(pos);
1129 if (wp == mInputMethodWindow) {
1130 pos++;
1131 }
1132 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001133 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 for (int i=0; i<N; i++) {
1135 WindowState win = dialogs.get(i);
1136 win.mTargetAppToken = targetAppToken;
1137 pos = reAddWindowLocked(pos, win);
1138 }
1139 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001140 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 logWindowList(" ");
1142 }
1143 return;
1144 }
1145 for (int i=0; i<N; i++) {
1146 WindowState win = dialogs.get(i);
1147 win.mTargetAppToken = null;
1148 reAddWindowToListInOrderLocked(win);
1149 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001150 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 logWindowList(" ");
1152 }
1153 }
1154 }
Romain Guy06882f82009-06-10 13:36:04 -07001155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1157 final WindowState imWin = mInputMethodWindow;
1158 final int DN = mInputMethodDialogs.size();
1159 if (imWin == null && DN == 0) {
1160 return false;
1161 }
Romain Guy06882f82009-06-10 13:36:04 -07001162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1164 if (imPos >= 0) {
1165 // In this case, the input method windows are to be placed
1166 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 // First check to see if the input method windows are already
1169 // located here, and contiguous.
1170 final int N = mWindows.size();
1171 WindowState firstImWin = imPos < N
1172 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 // Figure out the actual input method window that should be
1175 // at the bottom of their stack.
1176 WindowState baseImWin = imWin != null
1177 ? imWin : mInputMethodDialogs.get(0);
1178 if (baseImWin.mChildWindows.size() > 0) {
1179 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1180 if (cw.mSubLayer < 0) baseImWin = cw;
1181 }
Romain Guy06882f82009-06-10 13:36:04 -07001182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 if (firstImWin == baseImWin) {
1184 // The windows haven't moved... but are they still contiguous?
1185 // First find the top IM window.
1186 int pos = imPos+1;
1187 while (pos < N) {
1188 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1189 break;
1190 }
1191 pos++;
1192 }
1193 pos++;
1194 // Now there should be no more input method windows above.
1195 while (pos < N) {
1196 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1197 break;
1198 }
1199 pos++;
1200 }
1201 if (pos >= N) {
1202 // All is good!
1203 return false;
1204 }
1205 }
Romain Guy06882f82009-06-10 13:36:04 -07001206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 if (imWin != null) {
1208 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001209 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 logWindowList(" ");
1211 }
1212 imPos = tmpRemoveWindowLocked(imPos, imWin);
1213 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001214 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 logWindowList(" ");
1216 }
1217 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1218 reAddWindowLocked(imPos, imWin);
1219 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001220 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 logWindowList(" ");
1222 }
1223 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1224 } else {
1225 moveInputMethodDialogsLocked(imPos);
1226 }
Romain Guy06882f82009-06-10 13:36:04 -07001227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 } else {
1229 // In this case, the input method windows go in a fixed layer,
1230 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001233 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 tmpRemoveWindowLocked(0, imWin);
1235 imWin.mTargetAppToken = null;
1236 reAddWindowToListInOrderLocked(imWin);
1237 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001238 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 logWindowList(" ");
1240 }
1241 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1242 } else {
1243 moveInputMethodDialogsLocked(-1);;
1244 }
Romain Guy06882f82009-06-10 13:36:04 -07001245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 }
Romain Guy06882f82009-06-10 13:36:04 -07001247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 if (needAssignLayers) {
1249 assignLayersLocked();
1250 }
Romain Guy06882f82009-06-10 13:36:04 -07001251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 return true;
1253 }
Romain Guy06882f82009-06-10 13:36:04 -07001254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 void adjustInputMethodDialogsLocked() {
1256 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1257 }
Romain Guy06882f82009-06-10 13:36:04 -07001258
Dianne Hackborn25994b42009-09-04 14:21:19 -07001259 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001260 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001261 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1262 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1263 ? wallpaperTarget.mAppToken.animation : null)
1264 + " upper=" + mUpperWallpaperTarget
1265 + " lower=" + mLowerWallpaperTarget);
1266 return (wallpaperTarget != null
1267 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1268 && wallpaperTarget.mAppToken.animation != null)))
1269 || mUpperWallpaperTarget != null
1270 || mLowerWallpaperTarget != null;
1271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001272
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001273 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1274 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001275
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001276 int adjustWallpaperWindowsLocked() {
1277 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001278
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001279 final int dw = mDisplay.getWidth();
1280 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001281
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001282 // First find top-most window that has asked to be on top of the
1283 // wallpaper; all wallpapers go behind it.
1284 final ArrayList localmWindows = mWindows;
1285 int N = localmWindows.size();
1286 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001287 WindowState foundW = null;
1288 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001289 WindowState topCurW = null;
1290 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001291 int i = N;
1292 while (i > 0) {
1293 i--;
1294 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001295 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1296 if (topCurW == null) {
1297 topCurW = w;
1298 topCurI = i;
1299 }
1300 continue;
1301 }
1302 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001303 if (w.mAppToken != null) {
1304 // If this window's app token is hidden and not animating,
1305 // it is of no interest to us.
1306 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001307 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001308 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001309 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001310 continue;
1311 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001312 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001313 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001314 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1315 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001316 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001317 && (mWallpaperTarget == w
1318 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001319 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001320 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001321 foundW = w;
1322 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001323 if (w == mWallpaperTarget && ((w.mAppToken != null
1324 && w.mAppToken.animation != null)
1325 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001326 // The current wallpaper target is animating, so we'll
1327 // look behind it for another possible target and figure
1328 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001329 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001330 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001331 continue;
1332 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001333 break;
1334 }
1335 }
1336
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001337 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001338 // If we are currently waiting for an app transition, and either
1339 // the current target or the next target are involved with it,
1340 // then hold off on doing anything with the wallpaper.
1341 // Note that we are checking here for just whether the target
1342 // is part of an app token... which is potentially overly aggressive
1343 // (the app token may not be involved in the transition), but good
1344 // enough (we'll just wait until whatever transition is pending
1345 // executes).
1346 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001347 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001348 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001349 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001350 }
1351 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001352 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001353 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001354 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001355 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001356 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001357
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001358 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001359 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001360 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001361 + " oldTarget: " + mWallpaperTarget);
1362 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001363
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001364 mLowerWallpaperTarget = null;
1365 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001366
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001367 WindowState oldW = mWallpaperTarget;
1368 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001369
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001370 // Now what is happening... if the current and new targets are
1371 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001372 if (foundW != null && oldW != null) {
1373 boolean oldAnim = oldW.mAnimation != null
1374 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1375 boolean foundAnim = foundW.mAnimation != null
1376 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001377 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001378 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001379 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001380 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001381 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001382 int oldI = localmWindows.indexOf(oldW);
1383 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001384 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001385 }
1386 if (oldI >= 0) {
1387 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001388 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001389 + "=" + oldW + "; new#" + foundI
1390 + "=" + foundW);
1391 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001392
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001394 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001395 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001396 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 }
1398 mWallpaperTarget = oldW;
1399 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001400
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 // Now set the upper and lower wallpaper targets
1402 // correctly, and make sure that we are positioning
1403 // the wallpaper below the lower.
1404 if (foundI > oldI) {
1405 // The new target is on top of the old one.
1406 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001407 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001408 }
1409 mUpperWallpaperTarget = foundW;
1410 mLowerWallpaperTarget = oldW;
1411 foundW = oldW;
1412 foundI = oldI;
1413 } else {
1414 // The new target is below the old one.
1415 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001416 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001417 }
1418 mUpperWallpaperTarget = oldW;
1419 mLowerWallpaperTarget = foundW;
1420 }
1421 }
1422 }
1423 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001424
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001425 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001426 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001427 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1428 || (mLowerWallpaperTarget.mAppToken != null
1429 && mLowerWallpaperTarget.mAppToken.animation != null);
1430 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1431 || (mUpperWallpaperTarget.mAppToken != null
1432 && mUpperWallpaperTarget.mAppToken.animation != null);
1433 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001434 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001435 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001436 }
1437 mLowerWallpaperTarget = null;
1438 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001439 }
1440 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001441
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001442 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001443 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001444 // The window is visible to the compositor... but is it visible
1445 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001446 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001447 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001448
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001449 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001450 // its layer adjustment. Only do this if we are not transfering
1451 // between two wallpaper targets.
1452 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001453 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001454 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001455
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001456 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1457 * TYPE_LAYER_MULTIPLIER
1458 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001459
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001460 // Now w is the window we are supposed to be behind... but we
1461 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001462 // AND any starting window associated with it, AND below the
1463 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001464 while (foundI > 0) {
1465 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001466 if (wb.mBaseLayer < maxLayer &&
1467 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001468 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001469 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001470 // This window is not related to the previous one in any
1471 // interesting way, so stop here.
1472 break;
1473 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001474 foundW = wb;
1475 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001476 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001477 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001478 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001479 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001480
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001481 if (foundW == null && topCurW != null) {
1482 // There is no wallpaper target, so it goes at the bottom.
1483 // We will assume it is the same place as last time, if known.
1484 foundW = topCurW;
1485 foundI = topCurI+1;
1486 } else {
1487 // Okay i is the position immediately above the wallpaper. Look at
1488 // what is below it for later.
1489 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1490 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001491
Dianne Hackborn284ac932009-08-28 10:34:25 -07001492 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001493 if (mWallpaperTarget.mWallpaperX >= 0) {
1494 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001495 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001496 }
1497 if (mWallpaperTarget.mWallpaperY >= 0) {
1498 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001499 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001500 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001501 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001502
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001503 // Start stepping backwards from here, ensuring that our wallpaper windows
1504 // are correctly placed.
1505 int curTokenIndex = mWallpaperTokens.size();
1506 while (curTokenIndex > 0) {
1507 curTokenIndex--;
1508 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001509 if (token.hidden == visible) {
1510 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1511 token.hidden = !visible;
1512 // Need to do a layout to ensure the wallpaper now has the
1513 // correct size.
1514 mLayoutNeeded = true;
1515 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001516
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001517 int curWallpaperIndex = token.windows.size();
1518 while (curWallpaperIndex > 0) {
1519 curWallpaperIndex--;
1520 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001521
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001522 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001523 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001524 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001525
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001526 // First, make sure the client has the current visibility
1527 // state.
1528 if (wallpaper.mWallpaperVisible != visible) {
1529 wallpaper.mWallpaperVisible = visible;
1530 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001531 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001532 "Setting visibility of wallpaper " + wallpaper
1533 + ": " + visible);
1534 wallpaper.mClient.dispatchAppVisibility(visible);
1535 } catch (RemoteException e) {
1536 }
1537 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001538
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001539 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001540 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001541 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001543 // First, if this window is at the current index, then all
1544 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001545 if (wallpaper == foundW) {
1546 foundI--;
1547 foundW = foundI > 0
1548 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001549 continue;
1550 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001551
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001552 // The window didn't match... the current wallpaper window,
1553 // wherever it is, is in the wrong place, so make sure it is
1554 // not in the list.
1555 int oldIndex = localmWindows.indexOf(wallpaper);
1556 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001557 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001558 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001559 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001560 if (oldIndex < foundI) {
1561 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001562 }
1563 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001564
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001565 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001566 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001567 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001568 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001569
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001570 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001571 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001572 }
1573 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001574
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001575 return changed;
1576 }
1577
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001578 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001579 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001580 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001581 mWallpaperAnimLayerAdjustment = adj;
1582 int curTokenIndex = mWallpaperTokens.size();
1583 while (curTokenIndex > 0) {
1584 curTokenIndex--;
1585 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1586 int curWallpaperIndex = token.windows.size();
1587 while (curWallpaperIndex > 0) {
1588 curWallpaperIndex--;
1589 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1590 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001591 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001592 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001593 }
1594 }
1595 }
1596
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001597 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1598 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001599 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001600 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001601 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001602 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001603 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1604 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1605 changed = wallpaperWin.mXOffset != offset;
1606 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001607 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001608 + wallpaperWin + " x: " + offset);
1609 wallpaperWin.mXOffset = offset;
1610 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001611 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001612 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001613 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001614 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001615 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001616
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001617 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001618 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001619 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1620 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1621 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001622 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 + wallpaperWin + " y: " + offset);
1624 changed = true;
1625 wallpaperWin.mYOffset = offset;
1626 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001627 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001628 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001629 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001630 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001631 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001632
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001633 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001634 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001635 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001636 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1637 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001638 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001639 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001640 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001641 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001642 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1643 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001644 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001645 if (mWaitingOnWallpaper != null) {
1646 long start = SystemClock.uptimeMillis();
1647 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1648 < start) {
1649 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001650 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001651 "Waiting for offset complete...");
1652 mWindowMap.wait(WALLPAPER_TIMEOUT);
1653 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001654 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001656 if ((start+WALLPAPER_TIMEOUT)
1657 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001658 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001659 + wallpaperWin);
1660 mLastWallpaperTimeoutTime = start;
1661 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001662 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001663 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001664 }
1665 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001666 } catch (RemoteException e) {
1667 }
1668 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001669
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001670 return changed;
1671 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001672
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001673 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001674 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001675 if (mWaitingOnWallpaper != null &&
1676 mWaitingOnWallpaper.mClient.asBinder() == window) {
1677 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001679 }
1680 }
1681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001682
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001683 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001684 final int dw = mDisplay.getWidth();
1685 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001686
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001687 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001688
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001689 WindowState target = mWallpaperTarget;
1690 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001691 if (target.mWallpaperX >= 0) {
1692 mLastWallpaperX = target.mWallpaperX;
1693 } else if (changingTarget.mWallpaperX >= 0) {
1694 mLastWallpaperX = changingTarget.mWallpaperX;
1695 }
1696 if (target.mWallpaperY >= 0) {
1697 mLastWallpaperY = target.mWallpaperY;
1698 } else if (changingTarget.mWallpaperY >= 0) {
1699 mLastWallpaperY = changingTarget.mWallpaperY;
1700 }
1701 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001702
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001703 int curTokenIndex = mWallpaperTokens.size();
1704 while (curTokenIndex > 0) {
1705 curTokenIndex--;
1706 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1707 int curWallpaperIndex = token.windows.size();
1708 while (curWallpaperIndex > 0) {
1709 curWallpaperIndex--;
1710 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1711 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1712 wallpaper.computeShownFrameLocked();
1713 changed = true;
1714 // We only want to be synchronous with one wallpaper.
1715 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001716 }
1717 }
1718 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001719
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001720 return changed;
1721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001723 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001724 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001725 final int dw = mDisplay.getWidth();
1726 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001727
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001728 int curTokenIndex = mWallpaperTokens.size();
1729 while (curTokenIndex > 0) {
1730 curTokenIndex--;
1731 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001732 if (token.hidden == visible) {
1733 token.hidden = !visible;
1734 // Need to do a layout to ensure the wallpaper now has the
1735 // correct size.
1736 mLayoutNeeded = true;
1737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001738
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001739 int curWallpaperIndex = token.windows.size();
1740 while (curWallpaperIndex > 0) {
1741 curWallpaperIndex--;
1742 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1743 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001744 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001746
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001747 if (wallpaper.mWallpaperVisible != visible) {
1748 wallpaper.mWallpaperVisible = visible;
1749 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001750 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001751 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001752 + ": " + visible);
1753 wallpaper.mClient.dispatchAppVisibility(visible);
1754 } catch (RemoteException e) {
1755 }
1756 }
1757 }
1758 }
1759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001760
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001761 void sendPointerToWallpaperLocked(WindowState srcWin,
1762 MotionEvent pointer, long eventTime) {
1763 int curTokenIndex = mWallpaperTokens.size();
1764 while (curTokenIndex > 0) {
1765 curTokenIndex--;
1766 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1767 int curWallpaperIndex = token.windows.size();
1768 while (curWallpaperIndex > 0) {
1769 curWallpaperIndex--;
1770 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1771 if ((wallpaper.mAttrs.flags &
1772 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1773 continue;
1774 }
1775 try {
1776 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
Dianne Hackborn6adba242009-11-10 11:10:09 -08001777 if (srcWin != null) {
1778 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1779 srcWin.mFrame.top-wallpaper.mFrame.top);
1780 } else {
1781 ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top);
1782 }
1783 switch (pointer.getAction()) {
1784 case MotionEvent.ACTION_DOWN:
1785 mSendingPointersToWallpaper = true;
1786 break;
1787 case MotionEvent.ACTION_UP:
1788 mSendingPointersToWallpaper = false;
1789 break;
1790 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001791 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1792 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001793 Slog.w(TAG, "Failure sending pointer to wallpaper", e);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001794 }
1795 }
1796 }
1797 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001798
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001799 void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin,
1800 MotionEvent pointer, long eventTime, boolean skipped) {
1801 if (relWin != null) {
1802 mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top);
1803 } else {
1804 mPolicy.dispatchedPointerEventLw(pointer, 0, 0);
1805 }
1806
1807 // If we sent an initial down to the wallpaper, then continue
1808 // sending events until the final up.
1809 if (mSendingPointersToWallpaper) {
1810 if (skipped) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001811 Slog.i(TAG, "Sending skipped pointer to wallpaper!");
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001812 }
1813 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1814
1815 // If we are on top of the wallpaper, then the wallpaper also
1816 // gets to see this movement.
1817 } else if (srcWin != null
1818 && pointer.getAction() == MotionEvent.ACTION_DOWN
1819 && mWallpaperTarget == srcWin
1820 && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
1821 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1822 }
1823 }
1824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001825 public int addWindow(Session session, IWindow client,
1826 WindowManager.LayoutParams attrs, int viewVisibility,
1827 Rect outContentInsets) {
1828 int res = mPolicy.checkAddPermission(attrs);
1829 if (res != WindowManagerImpl.ADD_OKAY) {
1830 return res;
1831 }
Romain Guy06882f82009-06-10 13:36:04 -07001832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 boolean reportNewConfig = false;
1834 WindowState attachedWindow = null;
1835 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001837 synchronized(mWindowMap) {
1838 // Instantiating a Display requires talking with the simulator,
1839 // so don't do it until we know the system is mostly up and
1840 // running.
1841 if (mDisplay == null) {
1842 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1843 mDisplay = wm.getDefaultDisplay();
1844 mQueue.setDisplay(mDisplay);
1845 reportNewConfig = true;
1846 }
Romain Guy06882f82009-06-10 13:36:04 -07001847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001849 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1851 }
1852
1853 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001854 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001856 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 + attrs.token + ". Aborting.");
1858 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1859 }
1860 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1861 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001862 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 + attrs.token + ". Aborting.");
1864 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1865 }
1866 }
1867
1868 boolean addToken = false;
1869 WindowToken token = mTokenMap.get(attrs.token);
1870 if (token == null) {
1871 if (attrs.type >= FIRST_APPLICATION_WINDOW
1872 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001873 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 + attrs.token + ". Aborting.");
1875 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1876 }
1877 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001878 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 + attrs.token + ". Aborting.");
1880 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1881 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001882 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001884 + attrs.token + ". Aborting.");
1885 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1886 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 token = new WindowToken(attrs.token, -1, false);
1888 addToken = true;
1889 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1890 && attrs.type <= LAST_APPLICATION_WINDOW) {
1891 AppWindowToken atoken = token.appWindowToken;
1892 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001893 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894 + token + ". Aborting.");
1895 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1896 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001897 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898 + token + ". Aborting.");
1899 return WindowManagerImpl.ADD_APP_EXITING;
1900 }
1901 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1902 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001903 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1905 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1906 }
1907 } else if (attrs.type == TYPE_INPUT_METHOD) {
1908 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001909 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 + attrs.token + ". Aborting.");
1911 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1912 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001913 } else if (attrs.type == TYPE_WALLPAPER) {
1914 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001915 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001916 + attrs.token + ". Aborting.");
1917 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919 }
1920
1921 win = new WindowState(session, client, token,
1922 attachedWindow, attrs, viewVisibility);
1923 if (win.mDeathRecipient == null) {
1924 // Client has apparently died, so there is no reason to
1925 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001926 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 + " that is dead, aborting.");
1928 return WindowManagerImpl.ADD_APP_EXITING;
1929 }
1930
1931 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001933 res = mPolicy.prepareAddWindowLw(win, attrs);
1934 if (res != WindowManagerImpl.ADD_OKAY) {
1935 return res;
1936 }
1937
1938 // From now on, no exceptions or errors allowed!
1939
1940 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 if (addToken) {
1945 mTokenMap.put(attrs.token, token);
1946 mTokenList.add(token);
1947 }
1948 win.attach();
1949 mWindowMap.put(client.asBinder(), win);
1950
1951 if (attrs.type == TYPE_APPLICATION_STARTING &&
1952 token.appWindowToken != null) {
1953 token.appWindowToken.startingWindow = win;
1954 }
1955
1956 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 if (attrs.type == TYPE_INPUT_METHOD) {
1959 mInputMethodWindow = win;
1960 addInputMethodWindowToListLocked(win);
1961 imMayMove = false;
1962 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1963 mInputMethodDialogs.add(win);
1964 addWindowToListInOrderLocked(win, true);
1965 adjustInputMethodDialogsLocked();
1966 imMayMove = false;
1967 } else {
1968 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001969 if (attrs.type == TYPE_WALLPAPER) {
1970 mLastWallpaperTimeoutTime = 0;
1971 adjustWallpaperWindowsLocked();
1972 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001973 adjustWallpaperWindowsLocked();
1974 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001975 }
Romain Guy06882f82009-06-10 13:36:04 -07001976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 if (mInTouchMode) {
1982 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1983 }
1984 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1985 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1986 }
Romain Guy06882f82009-06-10 13:36:04 -07001987
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001988 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001990 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1991 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 imMayMove = false;
1993 }
1994 }
Romain Guy06882f82009-06-10 13:36:04 -07001995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001997 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 }
Romain Guy06882f82009-06-10 13:36:04 -07001999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 assignLayersLocked();
2001 // Don't do layout here, the window must call
2002 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 //dump();
2005
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002006 if (focusChanged) {
2007 if (mCurrentFocus != null) {
2008 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
2009 }
2010 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 TAG, "New client " + client.asBinder()
2013 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002014
2015 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2016 reportNewConfig = true;
2017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 }
2019
2020 // sendNewConfiguration() checks caller permissions so we must call it with
2021 // privilege. updateOrientationFromAppTokens() clears and resets the caller
2022 // identity anyway, so it's safe to just clear & restore around this whole
2023 // block.
2024 final long origId = Binder.clearCallingIdentity();
2025 if (reportNewConfig) {
2026 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 }
2028 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 return res;
2031 }
Romain Guy06882f82009-06-10 13:36:04 -07002032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 public void removeWindow(Session session, IWindow client) {
2034 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002035 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 if (win == null) {
2037 return;
2038 }
2039 removeWindowLocked(session, win);
2040 }
2041 }
Romain Guy06882f82009-06-10 13:36:04 -07002042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 public void removeWindowLocked(Session session, WindowState win) {
2044
Joe Onorato8a9b2202010-02-26 18:56:32 -08002045 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 TAG, "Remove " + win + " client="
2047 + Integer.toHexString(System.identityHashCode(
2048 win.mClient.asBinder()))
2049 + ", surface=" + win.mSurface);
2050
2051 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002052
Joe Onorato8a9b2202010-02-26 18:56:32 -08002053 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002054 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2055 + " mExiting=" + win.mExiting
2056 + " isAnimating=" + win.isAnimating()
2057 + " app-animation="
2058 + (win.mAppToken != null ? win.mAppToken.animation : null)
2059 + " inPendingTransaction="
2060 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2061 + " mDisplayFrozen=" + mDisplayFrozen);
2062 // Visibility of the removed window. Will be used later to update orientation later on.
2063 boolean wasVisible = false;
2064 // First, see if we need to run an animation. If we do, we have
2065 // to hold off on removing the window until the animation is done.
2066 // If the display is frozen, just remove immediately, since the
2067 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002068 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 // If we are not currently running the exit animation, we
2070 // need to see about starting one.
2071 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2074 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2075 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2076 }
2077 // Try starting an animation.
2078 if (applyAnimationLocked(win, transit, false)) {
2079 win.mExiting = true;
2080 }
2081 }
2082 if (win.mExiting || win.isAnimating()) {
2083 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002084 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002085 win.mExiting = true;
2086 win.mRemoveOnExit = true;
2087 mLayoutNeeded = true;
2088 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2089 performLayoutAndPlaceSurfacesLocked();
2090 if (win.mAppToken != null) {
2091 win.mAppToken.updateReportedVisibilityLocked();
2092 }
2093 //dump();
2094 Binder.restoreCallingIdentity(origId);
2095 return;
2096 }
2097 }
2098
2099 removeWindowInnerLocked(session, win);
2100 // Removing a visible window will effect the computed orientation
2101 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002102 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002103 != mForcedAppOrientation
2104 && updateOrientationFromAppTokensLocked()) {
2105 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 }
2107 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2108 Binder.restoreCallingIdentity(origId);
2109 }
Romain Guy06882f82009-06-10 13:36:04 -07002110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002111 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07002112 mKeyWaiter.finishedKey(session, win.mClient, true,
2113 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002114 mKeyWaiter.releasePendingPointerLocked(win.mSession);
2115 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07002116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002119 if (mInputMethodTarget == win) {
2120 moveInputMethodWindowsIfNeededLocked(false);
2121 }
Romain Guy06882f82009-06-10 13:36:04 -07002122
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002123 if (false) {
2124 RuntimeException e = new RuntimeException("here");
2125 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002126 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002127 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002129 mPolicy.removeWindowLw(win);
2130 win.removeLocked();
2131
2132 mWindowMap.remove(win.mClient.asBinder());
2133 mWindows.remove(win);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002134 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135
2136 if (mInputMethodWindow == win) {
2137 mInputMethodWindow = null;
2138 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2139 mInputMethodDialogs.remove(win);
2140 }
Romain Guy06882f82009-06-10 13:36:04 -07002141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 final WindowToken token = win.mToken;
2143 final AppWindowToken atoken = win.mAppToken;
2144 token.windows.remove(win);
2145 if (atoken != null) {
2146 atoken.allAppWindows.remove(win);
2147 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002148 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 TAG, "**** Removing window " + win + ": count="
2150 + token.windows.size());
2151 if (token.windows.size() == 0) {
2152 if (!token.explicit) {
2153 mTokenMap.remove(token.token);
2154 mTokenList.remove(token);
2155 } else if (atoken != null) {
2156 atoken.firstWindowDrawn = false;
2157 }
2158 }
2159
2160 if (atoken != null) {
2161 if (atoken.startingWindow == win) {
2162 atoken.startingWindow = null;
2163 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2164 // If this is the last window and we had requested a starting
2165 // transition window, well there is no point now.
2166 atoken.startingData = null;
2167 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2168 // If this is the last window except for a starting transition
2169 // window, we need to get rid of the starting transition.
2170 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002171 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 + ": no more real windows");
2173 }
2174 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2175 mH.sendMessage(m);
2176 }
2177 }
Romain Guy06882f82009-06-10 13:36:04 -07002178
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002179 if (win.mAttrs.type == TYPE_WALLPAPER) {
2180 mLastWallpaperTimeoutTime = 0;
2181 adjustWallpaperWindowsLocked();
2182 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002183 adjustWallpaperWindowsLocked();
2184 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 if (!mInLayout) {
2187 assignLayersLocked();
2188 mLayoutNeeded = true;
2189 performLayoutAndPlaceSurfacesLocked();
2190 if (win.mAppToken != null) {
2191 win.mAppToken.updateReportedVisibilityLocked();
2192 }
2193 }
2194 }
2195
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002196 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2197 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2198 + ": " + msg + " / " + w.mAttrs.getTitle();
2199 if (where != null) {
2200 Slog.i(TAG, str, where);
2201 } else {
2202 Slog.i(TAG, str);
2203 }
2204 }
2205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2207 long origId = Binder.clearCallingIdentity();
2208 try {
2209 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002210 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002212 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 Surface.openTransaction();
2214 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002215 if (SHOW_TRANSACTIONS) logSurface(w,
2216 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 w.mSurface.setTransparentRegionHint(region);
2218 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002219 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 Surface.closeTransaction();
2221 }
2222 }
2223 }
2224 } finally {
2225 Binder.restoreCallingIdentity(origId);
2226 }
2227 }
2228
2229 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002230 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002231 Rect visibleInsets) {
2232 long origId = Binder.clearCallingIdentity();
2233 try {
2234 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002235 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 if (w != null) {
2237 w.mGivenInsetsPending = false;
2238 w.mGivenContentInsets.set(contentInsets);
2239 w.mGivenVisibleInsets.set(visibleInsets);
2240 w.mTouchableInsets = touchableInsets;
2241 mLayoutNeeded = true;
2242 performLayoutAndPlaceSurfacesLocked();
2243 }
2244 }
2245 } finally {
2246 Binder.restoreCallingIdentity(origId);
2247 }
2248 }
Romain Guy06882f82009-06-10 13:36:04 -07002249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 public void getWindowDisplayFrame(Session session, IWindow client,
2251 Rect outDisplayFrame) {
2252 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002253 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 if (win == null) {
2255 outDisplayFrame.setEmpty();
2256 return;
2257 }
2258 outDisplayFrame.set(win.mDisplayFrame);
2259 }
2260 }
2261
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002262 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2263 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002264 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2265 window.mWallpaperX = x;
2266 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002267 window.mWallpaperXStep = xStep;
2268 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002269 if (updateWallpaperOffsetLocked(window, true)) {
2270 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002271 }
2272 }
2273 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002274
Dianne Hackborn75804932009-10-20 20:15:20 -07002275 void wallpaperCommandComplete(IBinder window, Bundle result) {
2276 synchronized (mWindowMap) {
2277 if (mWaitingOnWallpaper != null &&
2278 mWaitingOnWallpaper.mClient.asBinder() == window) {
2279 mWaitingOnWallpaper = null;
2280 mWindowMap.notifyAll();
2281 }
2282 }
2283 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002284
Dianne Hackborn75804932009-10-20 20:15:20 -07002285 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2286 String action, int x, int y, int z, Bundle extras, boolean sync) {
2287 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2288 || window == mUpperWallpaperTarget) {
2289 boolean doWait = sync;
2290 int curTokenIndex = mWallpaperTokens.size();
2291 while (curTokenIndex > 0) {
2292 curTokenIndex--;
2293 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2294 int curWallpaperIndex = token.windows.size();
2295 while (curWallpaperIndex > 0) {
2296 curWallpaperIndex--;
2297 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2298 try {
2299 wallpaper.mClient.dispatchWallpaperCommand(action,
2300 x, y, z, extras, sync);
2301 // We only want to be synchronous with one wallpaper.
2302 sync = false;
2303 } catch (RemoteException e) {
2304 }
2305 }
2306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002307
Dianne Hackborn75804932009-10-20 20:15:20 -07002308 if (doWait) {
2309 // XXX Need to wait for result.
2310 }
2311 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002312
Dianne Hackborn75804932009-10-20 20:15:20 -07002313 return null;
2314 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 public int relayoutWindow(Session session, IWindow client,
2317 WindowManager.LayoutParams attrs, int requestedWidth,
2318 int requestedHeight, int viewVisibility, boolean insetsPending,
2319 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
2320 Surface outSurface) {
2321 boolean displayed = false;
2322 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002323 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002327 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 if (win == null) {
2329 return 0;
2330 }
2331 win.mRequestedWidth = requestedWidth;
2332 win.mRequestedHeight = requestedHeight;
2333
2334 if (attrs != null) {
2335 mPolicy.adjustWindowParamsLw(attrs);
2336 }
Romain Guy06882f82009-06-10 13:36:04 -07002337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 int attrChanges = 0;
2339 int flagChanges = 0;
2340 if (attrs != null) {
2341 flagChanges = win.mAttrs.flags ^= attrs.flags;
2342 attrChanges = win.mAttrs.copyFrom(attrs);
2343 }
2344
Joe Onorato8a9b2202010-02-26 18:56:32 -08002345 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346
2347 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2348 win.mAlpha = attrs.alpha;
2349 }
2350
2351 final boolean scaledWindow =
2352 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2353
2354 if (scaledWindow) {
2355 // requested{Width|Height} Surface's physical size
2356 // attrs.{width|height} Size on screen
2357 win.mHScale = (attrs.width != requestedWidth) ?
2358 (attrs.width / (float)requestedWidth) : 1.0f;
2359 win.mVScale = (attrs.height != requestedHeight) ?
2360 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002361 } else {
2362 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 }
2364
2365 boolean imMayMove = (flagChanges&(
2366 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2367 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 boolean focusMayChange = win.mViewVisibility != viewVisibility
2370 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2371 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002372
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002373 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2374 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 win.mRelayoutCalled = true;
2377 final int oldVisibility = win.mViewVisibility;
2378 win.mViewVisibility = viewVisibility;
2379 if (viewVisibility == View.VISIBLE &&
2380 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2381 displayed = !win.isVisibleLw();
2382 if (win.mExiting) {
2383 win.mExiting = false;
2384 win.mAnimation = null;
2385 }
2386 if (win.mDestroying) {
2387 win.mDestroying = false;
2388 mDestroySurface.remove(win);
2389 }
2390 if (oldVisibility == View.GONE) {
2391 win.mEnterAnimationPending = true;
2392 }
2393 if (displayed && win.mSurface != null && !win.mDrawPending
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002394 && !win.mCommitDrawPending && !mDisplayFrozen
2395 && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 applyEnterAnimationLocked(win);
2397 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002398 if (displayed && (win.mAttrs.flags
2399 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08002400 if (DEBUG_VISIBILITY) Slog.v(TAG,
2401 "Relayout window turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002402 win.mTurnOnScreen = true;
2403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2405 // To change the format, we need to re-build the surface.
2406 win.destroySurfaceLocked();
2407 displayed = true;
2408 }
2409 try {
2410 Surface surface = win.createSurfaceLocked();
2411 if (surface != null) {
2412 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002413 win.mReportDestroySurface = false;
2414 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002415 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002416 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002418 // For some reason there isn't a surface. Clear the
2419 // caller's object so they see the same state.
2420 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 }
2422 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002423 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002424 + client + " (" + win.mAttrs.getTitle() + ")",
2425 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 Binder.restoreCallingIdentity(origId);
2427 return 0;
2428 }
2429 if (displayed) {
2430 focusMayChange = true;
2431 }
2432 if (win.mAttrs.type == TYPE_INPUT_METHOD
2433 && mInputMethodWindow == null) {
2434 mInputMethodWindow = win;
2435 imMayMove = true;
2436 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002437 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2438 && win.mAppToken != null
2439 && win.mAppToken.startingWindow != null) {
2440 // Special handling of starting window over the base
2441 // window of the app: propagate lock screen flags to it,
2442 // to provide the correct semantics while starting.
2443 final int mask =
2444 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002445 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2446 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002447 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2448 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 } else {
2451 win.mEnterAnimationPending = false;
2452 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002453 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002454 + ": mExiting=" + win.mExiting
2455 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 // If we are not currently running the exit animation, we
2457 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002458 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 // Try starting an animation; if there isn't one, we
2460 // can destroy the surface right away.
2461 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2462 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2463 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2464 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002465 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002467 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 win.mExiting = true;
2469 mKeyWaiter.finishedKey(session, client, true,
2470 KeyWaiter.RETURN_NOTHING);
2471 } else if (win.isAnimating()) {
2472 // Currently in a hide animation... turn this into
2473 // an exit.
2474 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002475 } else if (win == mWallpaperTarget) {
2476 // If the wallpaper is currently behind this
2477 // window, we need to change both of them inside
2478 // of a transaction to avoid artifacts.
2479 win.mExiting = true;
2480 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 } else {
2482 if (mInputMethodWindow == win) {
2483 mInputMethodWindow = null;
2484 }
2485 win.destroySurfaceLocked();
2486 }
2487 }
2488 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002489
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002490 if (win.mSurface == null || (win.getAttrs().flags
2491 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2492 || win.mSurfacePendingDestroy) {
2493 // We are being called from a local process, which
2494 // means outSurface holds its current surface. Ensure the
2495 // surface object is cleared, but we don't want it actually
2496 // destroyed at this point.
2497 win.mSurfacePendingDestroy = false;
2498 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002499 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002500 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002501 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002502 "Keeping surface, will report destroy: " + win);
2503 win.mReportDestroySurface = true;
2504 outSurface.copyFrom(win.mSurface);
2505 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 }
2507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 if (focusMayChange) {
2509 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2510 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 imMayMove = false;
2512 }
2513 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2514 }
Romain Guy06882f82009-06-10 13:36:04 -07002515
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002516 // updateFocusedWindowLocked() already assigned layers so we only need to
2517 // reassign them at this point if the IM window state gets shuffled
2518 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002520 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002521 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2522 // Little hack here -- we -should- be able to rely on the
2523 // function to return true if the IME has moved and needs
2524 // its layer recomputed. However, if the IME was hidden
2525 // and isn't actually moved in the list, its layer may be
2526 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 assignLayers = true;
2528 }
2529 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002530 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002531 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002532 assignLayers = true;
2533 }
2534 }
Romain Guy06882f82009-06-10 13:36:04 -07002535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 mLayoutNeeded = true;
2537 win.mGivenInsetsPending = insetsPending;
2538 if (assignLayers) {
2539 assignLayersLocked();
2540 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002541 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002543 if (displayed && win.mIsWallpaper) {
2544 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002545 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 if (win.mAppToken != null) {
2548 win.mAppToken.updateReportedVisibilityLocked();
2549 }
2550 outFrame.set(win.mFrame);
2551 outContentInsets.set(win.mContentInsets);
2552 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002553 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002555 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 + ", requestedHeight=" + requestedHeight
2557 + ", viewVisibility=" + viewVisibility
2558 + "\nRelayout returning frame=" + outFrame
2559 + ", surface=" + outSurface);
2560
Joe Onorato8a9b2202010-02-26 18:56:32 -08002561 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2563
2564 inTouchMode = mInTouchMode;
2565 }
2566
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002567 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 sendNewConfiguration();
2569 }
Romain Guy06882f82009-06-10 13:36:04 -07002570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2574 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2575 }
2576
2577 public void finishDrawingWindow(Session session, IWindow client) {
2578 final long origId = Binder.clearCallingIdentity();
2579 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002580 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002582 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2583 adjustWallpaperWindowsLocked();
2584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 mLayoutNeeded = true;
2586 performLayoutAndPlaceSurfacesLocked();
2587 }
2588 }
2589 Binder.restoreCallingIdentity(origId);
2590 }
2591
2592 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002593 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 + (lp != null ? lp.packageName : null)
2595 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2596 if (lp != null && lp.windowAnimations != 0) {
2597 // If this is a system resource, don't try to load it from the
2598 // application resources. It is nice to avoid loading application
2599 // resources if we can.
2600 String packageName = lp.packageName != null ? lp.packageName : "android";
2601 int resId = lp.windowAnimations;
2602 if ((resId&0xFF000000) == 0x01000000) {
2603 packageName = "android";
2604 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002605 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 + packageName);
2607 return AttributeCache.instance().get(packageName, resId,
2608 com.android.internal.R.styleable.WindowAnimation);
2609 }
2610 return null;
2611 }
Romain Guy06882f82009-06-10 13:36:04 -07002612
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002613 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002614 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002615 + packageName + " resId=0x" + Integer.toHexString(resId));
2616 if (packageName != null) {
2617 if ((resId&0xFF000000) == 0x01000000) {
2618 packageName = "android";
2619 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002620 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002621 + packageName);
2622 return AttributeCache.instance().get(packageName, resId,
2623 com.android.internal.R.styleable.WindowAnimation);
2624 }
2625 return null;
2626 }
2627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 private void applyEnterAnimationLocked(WindowState win) {
2629 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2630 if (win.mEnterAnimationPending) {
2631 win.mEnterAnimationPending = false;
2632 transit = WindowManagerPolicy.TRANSIT_ENTER;
2633 }
2634
2635 applyAnimationLocked(win, transit, true);
2636 }
2637
2638 private boolean applyAnimationLocked(WindowState win,
2639 int transit, boolean isEntrance) {
2640 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2641 // If we are trying to apply an animation, but already running
2642 // an animation of the same type, then just leave that one alone.
2643 return true;
2644 }
Romain Guy06882f82009-06-10 13:36:04 -07002645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 // Only apply an animation if the display isn't frozen. If it is
2647 // frozen, there is no reason to animate and it can cause strange
2648 // artifacts when we unfreeze the display if some different animation
2649 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002650 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 int anim = mPolicy.selectAnimationLw(win, transit);
2652 int attr = -1;
2653 Animation a = null;
2654 if (anim != 0) {
2655 a = AnimationUtils.loadAnimation(mContext, anim);
2656 } else {
2657 switch (transit) {
2658 case WindowManagerPolicy.TRANSIT_ENTER:
2659 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2660 break;
2661 case WindowManagerPolicy.TRANSIT_EXIT:
2662 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2663 break;
2664 case WindowManagerPolicy.TRANSIT_SHOW:
2665 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2666 break;
2667 case WindowManagerPolicy.TRANSIT_HIDE:
2668 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2669 break;
2670 }
2671 if (attr >= 0) {
2672 a = loadAnimation(win.mAttrs, attr);
2673 }
2674 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002675 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2677 + " mAnimation=" + win.mAnimation
2678 + " isEntrance=" + isEntrance);
2679 if (a != null) {
2680 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002681 RuntimeException e = null;
2682 if (!HIDE_STACK_CRAWLS) {
2683 e = new RuntimeException();
2684 e.fillInStackTrace();
2685 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002686 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 }
2688 win.setAnimation(a);
2689 win.mAnimationIsEntrance = isEntrance;
2690 }
2691 } else {
2692 win.clearAnimation();
2693 }
2694
2695 return win.mAnimation != null;
2696 }
2697
2698 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2699 int anim = 0;
2700 Context context = mContext;
2701 if (animAttr >= 0) {
2702 AttributeCache.Entry ent = getCachedAnimations(lp);
2703 if (ent != null) {
2704 context = ent.context;
2705 anim = ent.array.getResourceId(animAttr, 0);
2706 }
2707 }
2708 if (anim != 0) {
2709 return AnimationUtils.loadAnimation(context, anim);
2710 }
2711 return null;
2712 }
Romain Guy06882f82009-06-10 13:36:04 -07002713
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002714 private Animation loadAnimation(String packageName, int resId) {
2715 int anim = 0;
2716 Context context = mContext;
2717 if (resId >= 0) {
2718 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2719 if (ent != null) {
2720 context = ent.context;
2721 anim = resId;
2722 }
2723 }
2724 if (anim != 0) {
2725 return AnimationUtils.loadAnimation(context, anim);
2726 }
2727 return null;
2728 }
2729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 private boolean applyAnimationLocked(AppWindowToken wtoken,
2731 WindowManager.LayoutParams lp, int transit, boolean enter) {
2732 // Only apply an animation if the display isn't frozen. If it is
2733 // frozen, there is no reason to animate and it can cause strange
2734 // artifacts when we unfreeze the display if some different animation
2735 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002736 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002737 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002738 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002739 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002740 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002741 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002742 } else if (mNextAppTransitionPackage != null) {
2743 a = loadAnimation(mNextAppTransitionPackage, enter ?
2744 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002745 } else {
2746 int animAttr = 0;
2747 switch (transit) {
2748 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2749 animAttr = enter
2750 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2751 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2752 break;
2753 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2754 animAttr = enter
2755 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2756 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2757 break;
2758 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2759 animAttr = enter
2760 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2761 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2762 break;
2763 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2764 animAttr = enter
2765 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2766 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2767 break;
2768 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2769 animAttr = enter
2770 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2771 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2772 break;
2773 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2774 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002775 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002776 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2777 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002778 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002779 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002780 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2781 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002782 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002783 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002784 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002785 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2786 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2787 break;
2788 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2789 animAttr = enter
2790 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2791 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2792 break;
2793 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2794 animAttr = enter
2795 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2796 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002797 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002798 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002799 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002800 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002801 + " anim=" + a
2802 + " animAttr=0x" + Integer.toHexString(animAttr)
2803 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 if (a != null) {
2806 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002807 RuntimeException e = null;
2808 if (!HIDE_STACK_CRAWLS) {
2809 e = new RuntimeException();
2810 e.fillInStackTrace();
2811 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002812 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 }
2814 wtoken.setAnimation(a);
2815 }
2816 } else {
2817 wtoken.clearAnimation();
2818 }
2819
2820 return wtoken.animation != null;
2821 }
2822
2823 // -------------------------------------------------------------
2824 // Application Window Tokens
2825 // -------------------------------------------------------------
2826
2827 public void validateAppTokens(List tokens) {
2828 int v = tokens.size()-1;
2829 int m = mAppTokens.size()-1;
2830 while (v >= 0 && m >= 0) {
2831 AppWindowToken wtoken = mAppTokens.get(m);
2832 if (wtoken.removed) {
2833 m--;
2834 continue;
2835 }
2836 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002837 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2839 }
2840 v--;
2841 m--;
2842 }
2843 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002844 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 v--;
2846 }
2847 while (m >= 0) {
2848 AppWindowToken wtoken = mAppTokens.get(m);
2849 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002850 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002851 }
2852 m--;
2853 }
2854 }
2855
2856 boolean checkCallingPermission(String permission, String func) {
2857 // Quick check: if the calling permission is me, it's all okay.
2858 if (Binder.getCallingPid() == Process.myPid()) {
2859 return true;
2860 }
Romain Guy06882f82009-06-10 13:36:04 -07002861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 if (mContext.checkCallingPermission(permission)
2863 == PackageManager.PERMISSION_GRANTED) {
2864 return true;
2865 }
2866 String msg = "Permission Denial: " + func + " from pid="
2867 + Binder.getCallingPid()
2868 + ", uid=" + Binder.getCallingUid()
2869 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002870 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 return false;
2872 }
Romain Guy06882f82009-06-10 13:36:04 -07002873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 AppWindowToken findAppWindowToken(IBinder token) {
2875 WindowToken wtoken = mTokenMap.get(token);
2876 if (wtoken == null) {
2877 return null;
2878 }
2879 return wtoken.appWindowToken;
2880 }
Romain Guy06882f82009-06-10 13:36:04 -07002881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 public void addWindowToken(IBinder token, int type) {
2883 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2884 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002885 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 }
Romain Guy06882f82009-06-10 13:36:04 -07002887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 synchronized(mWindowMap) {
2889 WindowToken wtoken = mTokenMap.get(token);
2890 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002891 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 return;
2893 }
2894 wtoken = new WindowToken(token, type, true);
2895 mTokenMap.put(token, wtoken);
2896 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002897 if (type == TYPE_WALLPAPER) {
2898 mWallpaperTokens.add(wtoken);
2899 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 }
2901 }
Romain Guy06882f82009-06-10 13:36:04 -07002902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 public void removeWindowToken(IBinder token) {
2904 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2905 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002906 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 }
2908
2909 final long origId = Binder.clearCallingIdentity();
2910 synchronized(mWindowMap) {
2911 WindowToken wtoken = mTokenMap.remove(token);
2912 mTokenList.remove(wtoken);
2913 if (wtoken != null) {
2914 boolean delayed = false;
2915 if (!wtoken.hidden) {
2916 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 final int N = wtoken.windows.size();
2919 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 for (int i=0; i<N; i++) {
2922 WindowState win = wtoken.windows.get(i);
2923
2924 if (win.isAnimating()) {
2925 delayed = true;
2926 }
Romain Guy06882f82009-06-10 13:36:04 -07002927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 if (win.isVisibleNow()) {
2929 applyAnimationLocked(win,
2930 WindowManagerPolicy.TRANSIT_EXIT, false);
2931 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2932 KeyWaiter.RETURN_NOTHING);
2933 changed = true;
2934 }
2935 }
2936
2937 if (changed) {
2938 mLayoutNeeded = true;
2939 performLayoutAndPlaceSurfacesLocked();
2940 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2941 }
Romain Guy06882f82009-06-10 13:36:04 -07002942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 if (delayed) {
2944 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002945 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2946 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 }
2948 }
Romain Guy06882f82009-06-10 13:36:04 -07002949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002951 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 }
2953 }
2954 Binder.restoreCallingIdentity(origId);
2955 }
2956
2957 public void addAppToken(int addPos, IApplicationToken token,
2958 int groupId, int requestedOrientation, boolean fullscreen) {
2959 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2960 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002961 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 }
Romain Guy06882f82009-06-10 13:36:04 -07002963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 synchronized(mWindowMap) {
2965 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2966 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002967 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 return;
2969 }
2970 wtoken = new AppWindowToken(token);
2971 wtoken.groupId = groupId;
2972 wtoken.appFullscreen = fullscreen;
2973 wtoken.requestedOrientation = requestedOrientation;
2974 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002975 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 mTokenMap.put(token.asBinder(), wtoken);
2977 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 // Application tokens start out hidden.
2980 wtoken.hidden = true;
2981 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 //dump();
2984 }
2985 }
Romain Guy06882f82009-06-10 13:36:04 -07002986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 public void setAppGroupId(IBinder token, int groupId) {
2988 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2989 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002990 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 }
2992
2993 synchronized(mWindowMap) {
2994 AppWindowToken wtoken = findAppWindowToken(token);
2995 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002996 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 return;
2998 }
2999 wtoken.groupId = groupId;
3000 }
3001 }
Romain Guy06882f82009-06-10 13:36:04 -07003002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003 public int getOrientationFromWindowsLocked() {
3004 int pos = mWindows.size() - 1;
3005 while (pos >= 0) {
3006 WindowState wtoken = (WindowState) mWindows.get(pos);
3007 pos--;
3008 if (wtoken.mAppToken != null) {
3009 // We hit an application window. so the orientation will be determined by the
3010 // app window. No point in continuing further.
3011 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3012 }
3013 if (!wtoken.isVisibleLw()) {
3014 continue;
3015 }
3016 int req = wtoken.mAttrs.screenOrientation;
3017 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3018 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3019 continue;
3020 } else {
3021 return req;
3022 }
3023 }
3024 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3025 }
Romain Guy06882f82009-06-10 13:36:04 -07003026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003028 int pos = mAppTokens.size() - 1;
3029 int curGroup = 0;
3030 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3031 boolean findingBehind = false;
3032 boolean haveGroup = false;
3033 boolean lastFullscreen = false;
3034 while (pos >= 0) {
3035 AppWindowToken wtoken = mAppTokens.get(pos);
3036 pos--;
3037 // if we're about to tear down this window and not seek for
3038 // the behind activity, don't use it for orientation
3039 if (!findingBehind
3040 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3041 continue;
3042 }
3043
3044 if (!haveGroup) {
3045 // We ignore any hidden applications on the top.
3046 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003047 continue;
3048 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003049 haveGroup = true;
3050 curGroup = wtoken.groupId;
3051 lastOrientation = wtoken.requestedOrientation;
3052 } else if (curGroup != wtoken.groupId) {
3053 // If we have hit a new application group, and the bottom
3054 // of the previous group didn't explicitly say to use
3055 // the orientation behind it, and the last app was
3056 // full screen, then we'll stick with the
3057 // user's orientation.
3058 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3059 && lastFullscreen) {
3060 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003062 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003063 int or = wtoken.requestedOrientation;
3064 // If this application is fullscreen, and didn't explicitly say
3065 // to use the orientation behind it, then just take whatever
3066 // orientation it has and ignores whatever is under it.
3067 lastFullscreen = wtoken.appFullscreen;
3068 if (lastFullscreen
3069 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3070 return or;
3071 }
3072 // If this application has requested an explicit orientation,
3073 // then use it.
3074 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3075 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3076 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3077 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3078 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3079 return or;
3080 }
3081 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3082 }
3083 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 }
Romain Guy06882f82009-06-10 13:36:04 -07003085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003086 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003087 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003088 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3089 "updateOrientationFromAppTokens()")) {
3090 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003092
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003093 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003094 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003095
3096 synchronized(mWindowMap) {
3097 if (updateOrientationFromAppTokensLocked()) {
3098 if (freezeThisOneIfNeeded != null) {
3099 AppWindowToken wtoken = findAppWindowToken(
3100 freezeThisOneIfNeeded);
3101 if (wtoken != null) {
3102 startAppFreezingScreenLocked(wtoken,
3103 ActivityInfo.CONFIG_ORIENTATION);
3104 }
3105 }
3106 config = computeNewConfigurationLocked();
3107
3108 } else if (currentConfig != null) {
3109 // No obvious action we need to take, but if our current
3110 // state mismatches the activity maanager's, update it
3111 mTempConfiguration.setToDefaults();
3112 if (computeNewConfigurationLocked(mTempConfiguration)) {
3113 if (currentConfig.diff(mTempConfiguration) != 0) {
3114 mWaitingForConfig = true;
3115 mLayoutNeeded = true;
3116 startFreezingDisplayLocked();
3117 config = new Configuration(mTempConfiguration);
3118 }
3119 }
3120 }
3121 }
3122
Dianne Hackborncfaef692009-06-15 14:24:44 -07003123 Binder.restoreCallingIdentity(ident);
3124 return config;
3125 }
3126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003127 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003128 * Determine the new desired orientation of the display, returning
3129 * a non-null new Configuration if it has changed from the current
3130 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3131 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3132 * SCREEN. This will typically be done for you if you call
3133 * sendNewConfiguration().
3134 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 * The orientation is computed from non-application windows first. If none of
3136 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003137 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3139 * android.os.IBinder)
3140 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003141 boolean updateOrientationFromAppTokensLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003142 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 long ident = Binder.clearCallingIdentity();
3144 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003145 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 mForcedAppOrientation = req;
3149 //send a message to Policy indicating orientation change to take
3150 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003151 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003152 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3153 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3154 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 }
3156 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003157
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003158 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 } finally {
3160 Binder.restoreCallingIdentity(ident);
3161 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 }
Romain Guy06882f82009-06-10 13:36:04 -07003163
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003164 int computeForcedAppOrientationLocked() {
3165 int req = getOrientationFromWindowsLocked();
3166 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3167 req = getOrientationFromAppTokensLocked();
3168 }
3169 return req;
3170 }
Romain Guy06882f82009-06-10 13:36:04 -07003171
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003172 public void setNewConfiguration(Configuration config) {
3173 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3174 "setNewConfiguration()")) {
3175 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3176 }
3177
3178 synchronized(mWindowMap) {
3179 mCurConfiguration = new Configuration(config);
3180 mWaitingForConfig = false;
3181 performLayoutAndPlaceSurfacesLocked();
3182 }
3183 }
3184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3186 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3187 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003188 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 }
Romain Guy06882f82009-06-10 13:36:04 -07003190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 synchronized(mWindowMap) {
3192 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3193 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003194 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 return;
3196 }
Romain Guy06882f82009-06-10 13:36:04 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 wtoken.requestedOrientation = requestedOrientation;
3199 }
3200 }
Romain Guy06882f82009-06-10 13:36:04 -07003201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 public int getAppOrientation(IApplicationToken token) {
3203 synchronized(mWindowMap) {
3204 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3205 if (wtoken == null) {
3206 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3207 }
Romain Guy06882f82009-06-10 13:36:04 -07003208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 return wtoken.requestedOrientation;
3210 }
3211 }
Romain Guy06882f82009-06-10 13:36:04 -07003212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3214 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3215 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003216 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 }
3218
3219 synchronized(mWindowMap) {
3220 boolean changed = false;
3221 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003222 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 changed = mFocusedApp != null;
3224 mFocusedApp = null;
3225 mKeyWaiter.tickle();
3226 } else {
3227 AppWindowToken newFocus = findAppWindowToken(token);
3228 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003229 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 return;
3231 }
3232 changed = mFocusedApp != newFocus;
3233 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003234 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 mKeyWaiter.tickle();
3236 }
3237
3238 if (moveFocusNow && changed) {
3239 final long origId = Binder.clearCallingIdentity();
3240 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3241 Binder.restoreCallingIdentity(origId);
3242 }
3243 }
3244 }
3245
3246 public void prepareAppTransition(int transit) {
3247 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3248 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003249 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 }
Romain Guy06882f82009-06-10 13:36:04 -07003251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003253 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 TAG, "Prepare app transition: transit=" + transit
3255 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003256 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003257 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3258 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003260 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3261 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3262 // Opening a new task always supersedes a close for the anim.
3263 mNextAppTransition = transit;
3264 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3265 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3266 // Opening a new activity always supersedes a close for the anim.
3267 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 }
3269 mAppTransitionReady = false;
3270 mAppTransitionTimeout = false;
3271 mStartingIconInTransition = false;
3272 mSkipAppTransitionAnimation = false;
3273 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3274 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3275 5000);
3276 }
3277 }
3278 }
3279
3280 public int getPendingAppTransition() {
3281 return mNextAppTransition;
3282 }
Romain Guy06882f82009-06-10 13:36:04 -07003283
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003284 public void overridePendingAppTransition(String packageName,
3285 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003286 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003287 mNextAppTransitionPackage = packageName;
3288 mNextAppTransitionEnter = enterAnim;
3289 mNextAppTransitionExit = exitAnim;
3290 }
3291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 public void executeAppTransition() {
3294 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3295 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003296 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 }
Romain Guy06882f82009-06-10 13:36:04 -07003298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003300 if (DEBUG_APP_TRANSITIONS) {
3301 RuntimeException e = new RuntimeException("here");
3302 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003303 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003304 + mNextAppTransition, e);
3305 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003306 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 mAppTransitionReady = true;
3308 final long origId = Binder.clearCallingIdentity();
3309 performLayoutAndPlaceSurfacesLocked();
3310 Binder.restoreCallingIdentity(origId);
3311 }
3312 }
3313 }
3314
3315 public void setAppStartingWindow(IBinder token, String pkg,
3316 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3317 IBinder transferFrom, boolean createIfNeeded) {
3318 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3319 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003320 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 }
3322
3323 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003324 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3326 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 AppWindowToken wtoken = findAppWindowToken(token);
3329 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003330 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 return;
3332 }
3333
3334 // If the display is frozen, we won't do anything until the
3335 // actual window is displayed so there is no reason to put in
3336 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003337 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 return;
3339 }
Romain Guy06882f82009-06-10 13:36:04 -07003340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 if (wtoken.startingData != null) {
3342 return;
3343 }
Romain Guy06882f82009-06-10 13:36:04 -07003344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 if (transferFrom != null) {
3346 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3347 if (ttoken != null) {
3348 WindowState startingWindow = ttoken.startingWindow;
3349 if (startingWindow != null) {
3350 if (mStartingIconInTransition) {
3351 // In this case, the starting icon has already
3352 // been displayed, so start letting windows get
3353 // shown immediately without any more transitions.
3354 mSkipAppTransitionAnimation = true;
3355 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003356 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 "Moving existing starting from " + ttoken
3358 + " to " + wtoken);
3359 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003361 // Transfer the starting window over to the new
3362 // token.
3363 wtoken.startingData = ttoken.startingData;
3364 wtoken.startingView = ttoken.startingView;
3365 wtoken.startingWindow = startingWindow;
3366 ttoken.startingData = null;
3367 ttoken.startingView = null;
3368 ttoken.startingWindow = null;
3369 ttoken.startingMoved = true;
3370 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003371 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003373 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003374 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 mWindows.remove(startingWindow);
3376 ttoken.windows.remove(startingWindow);
3377 ttoken.allAppWindows.remove(startingWindow);
3378 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 // Propagate other interesting state between the
3381 // tokens. If the old token is displayed, we should
3382 // immediately force the new one to be displayed. If
3383 // it is animating, we need to move that animation to
3384 // the new one.
3385 if (ttoken.allDrawn) {
3386 wtoken.allDrawn = true;
3387 }
3388 if (ttoken.firstWindowDrawn) {
3389 wtoken.firstWindowDrawn = true;
3390 }
3391 if (!ttoken.hidden) {
3392 wtoken.hidden = false;
3393 wtoken.hiddenRequested = false;
3394 wtoken.willBeHidden = false;
3395 }
3396 if (wtoken.clientHidden != ttoken.clientHidden) {
3397 wtoken.clientHidden = ttoken.clientHidden;
3398 wtoken.sendAppVisibilityToClients();
3399 }
3400 if (ttoken.animation != null) {
3401 wtoken.animation = ttoken.animation;
3402 wtoken.animating = ttoken.animating;
3403 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3404 ttoken.animation = null;
3405 ttoken.animLayerAdjustment = 0;
3406 wtoken.updateLayers();
3407 ttoken.updateLayers();
3408 }
Romain Guy06882f82009-06-10 13:36:04 -07003409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 mLayoutNeeded = true;
3412 performLayoutAndPlaceSurfacesLocked();
3413 Binder.restoreCallingIdentity(origId);
3414 return;
3415 } else if (ttoken.startingData != null) {
3416 // The previous app was getting ready to show a
3417 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003418 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 "Moving pending starting from " + ttoken
3420 + " to " + wtoken);
3421 wtoken.startingData = ttoken.startingData;
3422 ttoken.startingData = null;
3423 ttoken.startingMoved = true;
3424 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3425 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3426 // want to process the message ASAP, before any other queued
3427 // messages.
3428 mH.sendMessageAtFrontOfQueue(m);
3429 return;
3430 }
3431 }
3432 }
3433
3434 // There is no existing starting window, and the caller doesn't
3435 // want us to create one, so that's it!
3436 if (!createIfNeeded) {
3437 return;
3438 }
Romain Guy06882f82009-06-10 13:36:04 -07003439
Dianne Hackborn284ac932009-08-28 10:34:25 -07003440 // If this is a translucent or wallpaper window, then don't
3441 // show a starting window -- the current effect (a full-screen
3442 // opaque starting window that fades away to the real contents
3443 // when it is ready) does not work for this.
3444 if (theme != 0) {
3445 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3446 com.android.internal.R.styleable.Window);
3447 if (ent.array.getBoolean(
3448 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3449 return;
3450 }
3451 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003452 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3453 return;
3454 }
3455 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003456 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3457 return;
3458 }
3459 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003461 mStartingIconInTransition = true;
3462 wtoken.startingData = new StartingData(
3463 pkg, theme, nonLocalizedLabel,
3464 labelRes, icon);
3465 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3466 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3467 // want to process the message ASAP, before any other queued
3468 // messages.
3469 mH.sendMessageAtFrontOfQueue(m);
3470 }
3471 }
3472
3473 public void setAppWillBeHidden(IBinder token) {
3474 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3475 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003476 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003477 }
3478
3479 AppWindowToken wtoken;
3480
3481 synchronized(mWindowMap) {
3482 wtoken = findAppWindowToken(token);
3483 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003484 Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 return;
3486 }
3487 wtoken.willBeHidden = true;
3488 }
3489 }
Romain Guy06882f82009-06-10 13:36:04 -07003490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003491 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3492 boolean visible, int transit, boolean performLayout) {
3493 boolean delayed = false;
3494
3495 if (wtoken.clientHidden == visible) {
3496 wtoken.clientHidden = !visible;
3497 wtoken.sendAppVisibilityToClients();
3498 }
Romain Guy06882f82009-06-10 13:36:04 -07003499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 wtoken.willBeHidden = false;
3501 if (wtoken.hidden == visible) {
3502 final int N = wtoken.allAppWindows.size();
3503 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003504 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003505 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3506 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003509
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003510 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 if (wtoken.animation == sDummyAnimation) {
3512 wtoken.animation = null;
3513 }
3514 applyAnimationLocked(wtoken, lp, transit, visible);
3515 changed = true;
3516 if (wtoken.animation != null) {
3517 delayed = runningAppAnimation = true;
3518 }
3519 }
Romain Guy06882f82009-06-10 13:36:04 -07003520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 for (int i=0; i<N; i++) {
3522 WindowState win = wtoken.allAppWindows.get(i);
3523 if (win == wtoken.startingWindow) {
3524 continue;
3525 }
3526
3527 if (win.isAnimating()) {
3528 delayed = true;
3529 }
Romain Guy06882f82009-06-10 13:36:04 -07003530
Joe Onorato8a9b2202010-02-26 18:56:32 -08003531 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 //win.dump(" ");
3533 if (visible) {
3534 if (!win.isVisibleNow()) {
3535 if (!runningAppAnimation) {
3536 applyAnimationLocked(win,
3537 WindowManagerPolicy.TRANSIT_ENTER, true);
3538 }
3539 changed = true;
3540 }
3541 } else if (win.isVisibleNow()) {
3542 if (!runningAppAnimation) {
3543 applyAnimationLocked(win,
3544 WindowManagerPolicy.TRANSIT_EXIT, false);
3545 }
3546 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3547 KeyWaiter.RETURN_NOTHING);
3548 changed = true;
3549 }
3550 }
3551
3552 wtoken.hidden = wtoken.hiddenRequested = !visible;
3553 if (!visible) {
3554 unsetAppFreezingScreenLocked(wtoken, true, true);
3555 } else {
3556 // If we are being set visible, and the starting window is
3557 // not yet displayed, then make sure it doesn't get displayed.
3558 WindowState swin = wtoken.startingWindow;
3559 if (swin != null && (swin.mDrawPending
3560 || swin.mCommitDrawPending)) {
3561 swin.mPolicyVisibility = false;
3562 swin.mPolicyVisibilityAfterAnim = false;
3563 }
3564 }
Romain Guy06882f82009-06-10 13:36:04 -07003565
Joe Onorato8a9b2202010-02-26 18:56:32 -08003566 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3568 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003569
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003570 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003572 if (performLayout) {
3573 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3574 performLayoutAndPlaceSurfacesLocked();
3575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 }
3577 }
3578
3579 if (wtoken.animation != null) {
3580 delayed = true;
3581 }
Romain Guy06882f82009-06-10 13:36:04 -07003582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 return delayed;
3584 }
3585
3586 public void setAppVisibility(IBinder token, boolean visible) {
3587 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3588 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003589 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 }
3591
3592 AppWindowToken wtoken;
3593
3594 synchronized(mWindowMap) {
3595 wtoken = findAppWindowToken(token);
3596 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003597 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 return;
3599 }
3600
3601 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003602 RuntimeException e = null;
3603 if (!HIDE_STACK_CRAWLS) {
3604 e = new RuntimeException();
3605 e.fillInStackTrace();
3606 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003607 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 + "): mNextAppTransition=" + mNextAppTransition
3609 + " hidden=" + wtoken.hidden
3610 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3611 }
Romain Guy06882f82009-06-10 13:36:04 -07003612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 // If we are preparing an app transition, then delay changing
3614 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003615 if (!mDisplayFrozen && mPolicy.isScreenOn()
3616 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 // Already in requested state, don't do anything more.
3618 if (wtoken.hiddenRequested != visible) {
3619 return;
3620 }
3621 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003622
Joe Onorato8a9b2202010-02-26 18:56:32 -08003623 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 TAG, "Setting dummy animation on: " + wtoken);
3625 wtoken.setDummyAnimation();
3626 mOpeningApps.remove(wtoken);
3627 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003628 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 wtoken.inPendingTransaction = true;
3630 if (visible) {
3631 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 wtoken.startingDisplayed = false;
3633 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003634
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003635 // If the token is currently hidden (should be the
3636 // common case), then we need to set up to wait for
3637 // its windows to be ready.
3638 if (wtoken.hidden) {
3639 wtoken.allDrawn = false;
3640 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003641
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003642 if (wtoken.clientHidden) {
3643 // In the case where we are making an app visible
3644 // but holding off for a transition, we still need
3645 // to tell the client to make its windows visible so
3646 // they get drawn. Otherwise, we will wait on
3647 // performing the transition until all windows have
3648 // been drawn, they never will be, and we are sad.
3649 wtoken.clientHidden = false;
3650 wtoken.sendAppVisibilityToClients();
3651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003652 }
3653 } else {
3654 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003655
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003656 // If the token is currently visible (should be the
3657 // common case), then set up to wait for it to be hidden.
3658 if (!wtoken.hidden) {
3659 wtoken.waitingToHide = true;
3660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 }
3662 return;
3663 }
Romain Guy06882f82009-06-10 13:36:04 -07003664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003666 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 wtoken.updateReportedVisibilityLocked();
3668 Binder.restoreCallingIdentity(origId);
3669 }
3670 }
3671
3672 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3673 boolean unfreezeSurfaceNow, boolean force) {
3674 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003675 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676 + " force=" + force);
3677 final int N = wtoken.allAppWindows.size();
3678 boolean unfrozeWindows = false;
3679 for (int i=0; i<N; i++) {
3680 WindowState w = wtoken.allAppWindows.get(i);
3681 if (w.mAppFreezing) {
3682 w.mAppFreezing = false;
3683 if (w.mSurface != null && !w.mOrientationChanging) {
3684 w.mOrientationChanging = true;
3685 }
3686 unfrozeWindows = true;
3687 }
3688 }
3689 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003690 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 wtoken.freezingScreen = false;
3692 mAppsFreezingScreen--;
3693 }
3694 if (unfreezeSurfaceNow) {
3695 if (unfrozeWindows) {
3696 mLayoutNeeded = true;
3697 performLayoutAndPlaceSurfacesLocked();
3698 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003699 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003700 }
3701 }
3702 }
Romain Guy06882f82009-06-10 13:36:04 -07003703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3705 int configChanges) {
3706 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003707 RuntimeException e = null;
3708 if (!HIDE_STACK_CRAWLS) {
3709 e = new RuntimeException();
3710 e.fillInStackTrace();
3711 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003712 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 + ": hidden=" + wtoken.hidden + " freezing="
3714 + wtoken.freezingScreen, e);
3715 }
3716 if (!wtoken.hiddenRequested) {
3717 if (!wtoken.freezingScreen) {
3718 wtoken.freezingScreen = true;
3719 mAppsFreezingScreen++;
3720 if (mAppsFreezingScreen == 1) {
3721 startFreezingDisplayLocked();
3722 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3723 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3724 5000);
3725 }
3726 }
3727 final int N = wtoken.allAppWindows.size();
3728 for (int i=0; i<N; i++) {
3729 WindowState w = wtoken.allAppWindows.get(i);
3730 w.mAppFreezing = true;
3731 }
3732 }
3733 }
Romain Guy06882f82009-06-10 13:36:04 -07003734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 public void startAppFreezingScreen(IBinder token, int configChanges) {
3736 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3737 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003738 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 }
3740
3741 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003742 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003743 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 return;
3745 }
Romain Guy06882f82009-06-10 13:36:04 -07003746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 AppWindowToken wtoken = findAppWindowToken(token);
3748 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003749 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 return;
3751 }
3752 final long origId = Binder.clearCallingIdentity();
3753 startAppFreezingScreenLocked(wtoken, configChanges);
3754 Binder.restoreCallingIdentity(origId);
3755 }
3756 }
Romain Guy06882f82009-06-10 13:36:04 -07003757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 public void stopAppFreezingScreen(IBinder token, boolean force) {
3759 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3760 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003761 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 }
3763
3764 synchronized(mWindowMap) {
3765 AppWindowToken wtoken = findAppWindowToken(token);
3766 if (wtoken == null || wtoken.appToken == null) {
3767 return;
3768 }
3769 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003770 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3772 unsetAppFreezingScreenLocked(wtoken, true, force);
3773 Binder.restoreCallingIdentity(origId);
3774 }
3775 }
Romain Guy06882f82009-06-10 13:36:04 -07003776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 public void removeAppToken(IBinder token) {
3778 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3779 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003780 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 }
3782
3783 AppWindowToken wtoken = null;
3784 AppWindowToken startingToken = null;
3785 boolean delayed = false;
3786
3787 final long origId = Binder.clearCallingIdentity();
3788 synchronized(mWindowMap) {
3789 WindowToken basewtoken = mTokenMap.remove(token);
3790 mTokenList.remove(basewtoken);
3791 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003792 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003793 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 wtoken.inPendingTransaction = false;
3795 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003796 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 if (mClosingApps.contains(wtoken)) {
3798 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003799 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003801 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 delayed = true;
3803 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003804 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 TAG, "Removing app " + wtoken + " delayed=" + delayed
3806 + " animation=" + wtoken.animation
3807 + " animating=" + wtoken.animating);
3808 if (delayed) {
3809 // set the token aside because it has an active animation to be finished
3810 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003811 } else {
3812 // Make sure there is no animation running on this token,
3813 // so any windows associated with it will be removed as
3814 // soon as their animations are complete
3815 wtoken.animation = null;
3816 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003817 }
3818 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003819 if (mLastEnterAnimToken == wtoken) {
3820 mLastEnterAnimToken = null;
3821 mLastEnterAnimParams = null;
3822 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 wtoken.removed = true;
3824 if (wtoken.startingData != null) {
3825 startingToken = wtoken;
3826 }
3827 unsetAppFreezingScreenLocked(wtoken, true, true);
3828 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003829 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 mFocusedApp = null;
3831 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3832 mKeyWaiter.tickle();
3833 }
3834 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003835 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 }
Romain Guy06882f82009-06-10 13:36:04 -07003837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 if (!delayed && wtoken != null) {
3839 wtoken.updateReportedVisibilityLocked();
3840 }
3841 }
3842 Binder.restoreCallingIdentity(origId);
3843
3844 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003845 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 + startingToken + ": app token removed");
3847 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3848 mH.sendMessage(m);
3849 }
3850 }
3851
3852 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3853 final int NW = token.windows.size();
3854 for (int i=0; i<NW; i++) {
3855 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003856 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 mWindows.remove(win);
3858 int j = win.mChildWindows.size();
3859 while (j > 0) {
3860 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003861 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003862 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003863 "Tmp removing child window " + cwin);
3864 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 }
3866 }
3867 return NW > 0;
3868 }
3869
3870 void dumpAppTokensLocked() {
3871 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003872 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003873 }
3874 }
Romain Guy06882f82009-06-10 13:36:04 -07003875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 void dumpWindowsLocked() {
3877 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003878 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 }
3880 }
Romain Guy06882f82009-06-10 13:36:04 -07003881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 private int findWindowOffsetLocked(int tokenPos) {
3883 final int NW = mWindows.size();
3884
3885 if (tokenPos >= mAppTokens.size()) {
3886 int i = NW;
3887 while (i > 0) {
3888 i--;
3889 WindowState win = (WindowState)mWindows.get(i);
3890 if (win.getAppToken() != null) {
3891 return i+1;
3892 }
3893 }
3894 }
3895
3896 while (tokenPos > 0) {
3897 // Find the first app token below the new position that has
3898 // a window displayed.
3899 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003900 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003901 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003902 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003903 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003904 "Skipping token -- currently sending to bottom");
3905 tokenPos--;
3906 continue;
3907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003908 int i = wtoken.windows.size();
3909 while (i > 0) {
3910 i--;
3911 WindowState win = wtoken.windows.get(i);
3912 int j = win.mChildWindows.size();
3913 while (j > 0) {
3914 j--;
3915 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003916 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 for (int pos=NW-1; pos>=0; pos--) {
3918 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003919 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003920 "Found child win @" + (pos+1));
3921 return pos+1;
3922 }
3923 }
3924 }
3925 }
3926 for (int pos=NW-1; pos>=0; pos--) {
3927 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003928 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 return pos+1;
3930 }
3931 }
3932 }
3933 tokenPos--;
3934 }
3935
3936 return 0;
3937 }
3938
3939 private final int reAddWindowLocked(int index, WindowState win) {
3940 final int NCW = win.mChildWindows.size();
3941 boolean added = false;
3942 for (int j=0; j<NCW; j++) {
3943 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3944 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003945 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003946 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003947 mWindows.add(index, win);
3948 index++;
3949 added = true;
3950 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003951 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003952 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003953 mWindows.add(index, cwin);
3954 index++;
3955 }
3956 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003957 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003958 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003959 mWindows.add(index, win);
3960 index++;
3961 }
3962 return index;
3963 }
Romain Guy06882f82009-06-10 13:36:04 -07003964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3966 final int NW = token.windows.size();
3967 for (int i=0; i<NW; i++) {
3968 index = reAddWindowLocked(index, token.windows.get(i));
3969 }
3970 return index;
3971 }
3972
3973 public void moveAppToken(int index, IBinder token) {
3974 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3975 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003976 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 }
3978
3979 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003980 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 if (DEBUG_REORDER) dumpAppTokensLocked();
3982 final AppWindowToken wtoken = findAppWindowToken(token);
3983 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003984 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 + token + " (" + wtoken + ")");
3986 return;
3987 }
3988 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003989 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003993 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 if (DEBUG_REORDER) dumpWindowsLocked();
3995 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003996 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 if (DEBUG_REORDER) dumpWindowsLocked();
3998 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003999 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 if (DEBUG_REORDER) dumpWindowsLocked();
4001 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 mLayoutNeeded = true;
4003 performLayoutAndPlaceSurfacesLocked();
4004 }
4005 Binder.restoreCallingIdentity(origId);
4006 }
4007 }
4008
4009 private void removeAppTokensLocked(List<IBinder> tokens) {
4010 // XXX This should be done more efficiently!
4011 // (take advantage of the fact that both lists should be
4012 // ordered in the same way.)
4013 int N = tokens.size();
4014 for (int i=0; i<N; i++) {
4015 IBinder token = tokens.get(i);
4016 final AppWindowToken wtoken = findAppWindowToken(token);
4017 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004018 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 + token + " (" + wtoken + ")");
4020 i--;
4021 N--;
4022 }
4023 }
4024 }
4025
Dianne Hackborna8f60182009-09-01 19:01:50 -07004026 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4027 boolean updateFocusAndLayout) {
4028 // First remove all of the windows from the list.
4029 tmpRemoveAppWindowsLocked(wtoken);
4030
4031 // Where to start adding?
4032 int pos = findWindowOffsetLocked(tokenPos);
4033
4034 // And now add them back at the correct place.
4035 pos = reAddAppWindowsLocked(pos, wtoken);
4036
4037 if (updateFocusAndLayout) {
4038 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4039 assignLayersLocked();
4040 }
4041 mLayoutNeeded = true;
4042 performLayoutAndPlaceSurfacesLocked();
4043 }
4044 }
4045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004046 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4047 // First remove all of the windows from the list.
4048 final int N = tokens.size();
4049 int i;
4050 for (i=0; i<N; i++) {
4051 WindowToken token = mTokenMap.get(tokens.get(i));
4052 if (token != null) {
4053 tmpRemoveAppWindowsLocked(token);
4054 }
4055 }
4056
4057 // Where to start adding?
4058 int pos = findWindowOffsetLocked(tokenPos);
4059
4060 // And now add them back at the correct place.
4061 for (i=0; i<N; i++) {
4062 WindowToken token = mTokenMap.get(tokens.get(i));
4063 if (token != null) {
4064 pos = reAddAppWindowsLocked(pos, token);
4065 }
4066 }
4067
Dianne Hackborna8f60182009-09-01 19:01:50 -07004068 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4069 assignLayersLocked();
4070 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004071 mLayoutNeeded = true;
4072 performLayoutAndPlaceSurfacesLocked();
4073
4074 //dump();
4075 }
4076
4077 public void moveAppTokensToTop(List<IBinder> tokens) {
4078 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4079 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004080 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 }
4082
4083 final long origId = Binder.clearCallingIdentity();
4084 synchronized(mWindowMap) {
4085 removeAppTokensLocked(tokens);
4086 final int N = tokens.size();
4087 for (int i=0; i<N; i++) {
4088 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4089 if (wt != null) {
4090 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004091 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004092 mToTopApps.remove(wt);
4093 mToBottomApps.remove(wt);
4094 mToTopApps.add(wt);
4095 wt.sendingToBottom = false;
4096 wt.sendingToTop = true;
4097 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 }
4099 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004100
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004101 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004102 moveAppWindowsLocked(tokens, mAppTokens.size());
4103 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004104 }
4105 Binder.restoreCallingIdentity(origId);
4106 }
4107
4108 public void moveAppTokensToBottom(List<IBinder> tokens) {
4109 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4110 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004111 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 }
4113
4114 final long origId = Binder.clearCallingIdentity();
4115 synchronized(mWindowMap) {
4116 removeAppTokensLocked(tokens);
4117 final int N = tokens.size();
4118 int pos = 0;
4119 for (int i=0; i<N; i++) {
4120 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4121 if (wt != null) {
4122 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004123 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004124 mToTopApps.remove(wt);
4125 mToBottomApps.remove(wt);
4126 mToBottomApps.add(i, wt);
4127 wt.sendingToTop = false;
4128 wt.sendingToBottom = true;
4129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004130 pos++;
4131 }
4132 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004133
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004134 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004135 moveAppWindowsLocked(tokens, 0);
4136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004137 }
4138 Binder.restoreCallingIdentity(origId);
4139 }
4140
4141 // -------------------------------------------------------------
4142 // Misc IWindowSession methods
4143 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004146 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147 != PackageManager.PERMISSION_GRANTED) {
4148 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4149 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004150 synchronized (mKeyguardTokenWatcher) {
4151 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004152 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 }
4154
4155 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004156 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004157 != PackageManager.PERMISSION_GRANTED) {
4158 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4159 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004160 synchronized (mKeyguardTokenWatcher) {
4161 mKeyguardTokenWatcher.release(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162
Mike Lockwood983ee092009-11-22 01:42:24 -05004163 if (!mKeyguardTokenWatcher.isAcquired()) {
4164 // If we are the last one to reenable the keyguard wait until
4165 // we have actaully finished reenabling until returning.
4166 // It is possible that reenableKeyguard() can be called before
4167 // the previous disableKeyguard() is handled, in which case
4168 // neither mKeyguardTokenWatcher.acquired() or released() would
4169 // be called. In that case mKeyguardDisabled will be false here
4170 // and we have nothing to wait for.
4171 while (mKeyguardDisabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 try {
Mike Lockwood983ee092009-11-22 01:42:24 -05004173 mKeyguardTokenWatcher.wait();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 } catch (InterruptedException e) {
4175 Thread.currentThread().interrupt();
4176 }
4177 }
4178 }
4179 }
4180 }
4181
4182 /**
4183 * @see android.app.KeyguardManager#exitKeyguardSecurely
4184 */
4185 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004186 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 != PackageManager.PERMISSION_GRANTED) {
4188 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4189 }
4190 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4191 public void onKeyguardExitResult(boolean success) {
4192 try {
4193 callback.onKeyguardExitResult(success);
4194 } catch (RemoteException e) {
4195 // Client has died, we don't care.
4196 }
4197 }
4198 });
4199 }
4200
4201 public boolean inKeyguardRestrictedInputMode() {
4202 return mPolicy.inKeyguardRestrictedKeyInputMode();
4203 }
Romain Guy06882f82009-06-10 13:36:04 -07004204
Dianne Hackbornffa42482009-09-23 22:20:11 -07004205 public void closeSystemDialogs(String reason) {
4206 synchronized(mWindowMap) {
4207 for (int i=mWindows.size()-1; i>=0; i--) {
4208 WindowState w = (WindowState)mWindows.get(i);
4209 if (w.mSurface != null) {
4210 try {
4211 w.mClient.closeSystemDialogs(reason);
4212 } catch (RemoteException e) {
4213 }
4214 }
4215 }
4216 }
4217 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 static float fixScale(float scale) {
4220 if (scale < 0) scale = 0;
4221 else if (scale > 20) scale = 20;
4222 return Math.abs(scale);
4223 }
Romain Guy06882f82009-06-10 13:36:04 -07004224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 public void setAnimationScale(int which, float scale) {
4226 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4227 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004228 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 }
4230
4231 if (scale < 0) scale = 0;
4232 else if (scale > 20) scale = 20;
4233 scale = Math.abs(scale);
4234 switch (which) {
4235 case 0: mWindowAnimationScale = fixScale(scale); break;
4236 case 1: mTransitionAnimationScale = fixScale(scale); break;
4237 }
Romain Guy06882f82009-06-10 13:36:04 -07004238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 // Persist setting
4240 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4241 }
Romain Guy06882f82009-06-10 13:36:04 -07004242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004243 public void setAnimationScales(float[] scales) {
4244 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4245 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004246 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 }
4248
4249 if (scales != null) {
4250 if (scales.length >= 1) {
4251 mWindowAnimationScale = fixScale(scales[0]);
4252 }
4253 if (scales.length >= 2) {
4254 mTransitionAnimationScale = fixScale(scales[1]);
4255 }
4256 }
Romain Guy06882f82009-06-10 13:36:04 -07004257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 // Persist setting
4259 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4260 }
Romain Guy06882f82009-06-10 13:36:04 -07004261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 public float getAnimationScale(int which) {
4263 switch (which) {
4264 case 0: return mWindowAnimationScale;
4265 case 1: return mTransitionAnimationScale;
4266 }
4267 return 0;
4268 }
Romain Guy06882f82009-06-10 13:36:04 -07004269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004270 public float[] getAnimationScales() {
4271 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4272 }
Romain Guy06882f82009-06-10 13:36:04 -07004273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004274 public int getSwitchState(int sw) {
4275 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4276 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004277 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 }
4279 return KeyInputQueue.getSwitchState(sw);
4280 }
Romain Guy06882f82009-06-10 13:36:04 -07004281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 public int getSwitchStateForDevice(int devid, int sw) {
4283 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4284 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004285 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 }
4287 return KeyInputQueue.getSwitchState(devid, sw);
4288 }
Romain Guy06882f82009-06-10 13:36:04 -07004289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 public int getScancodeState(int sw) {
4291 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4292 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004293 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004295 return mQueue.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 }
Romain Guy06882f82009-06-10 13:36:04 -07004297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004298 public int getScancodeStateForDevice(int devid, int sw) {
4299 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4300 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004301 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004303 return mQueue.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 }
Romain Guy06882f82009-06-10 13:36:04 -07004305
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004306 public int getTrackballScancodeState(int sw) {
4307 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4308 "getTrackballScancodeState()")) {
4309 throw new SecurityException("Requires READ_INPUT_STATE permission");
4310 }
4311 return mQueue.getTrackballScancodeState(sw);
4312 }
4313
4314 public int getDPadScancodeState(int sw) {
4315 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4316 "getDPadScancodeState()")) {
4317 throw new SecurityException("Requires READ_INPUT_STATE permission");
4318 }
4319 return mQueue.getDPadScancodeState(sw);
4320 }
4321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 public int getKeycodeState(int sw) {
4323 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4324 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004325 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004327 return mQueue.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 }
Romain Guy06882f82009-06-10 13:36:04 -07004329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 public int getKeycodeStateForDevice(int devid, int sw) {
4331 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4332 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004333 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004335 return mQueue.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004336 }
Romain Guy06882f82009-06-10 13:36:04 -07004337
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004338 public int getTrackballKeycodeState(int sw) {
4339 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4340 "getTrackballKeycodeState()")) {
4341 throw new SecurityException("Requires READ_INPUT_STATE permission");
4342 }
4343 return mQueue.getTrackballKeycodeState(sw);
4344 }
4345
4346 public int getDPadKeycodeState(int sw) {
4347 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4348 "getDPadKeycodeState()")) {
4349 throw new SecurityException("Requires READ_INPUT_STATE permission");
4350 }
4351 return mQueue.getDPadKeycodeState(sw);
4352 }
4353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
4355 return KeyInputQueue.hasKeys(keycodes, keyExists);
4356 }
Romain Guy06882f82009-06-10 13:36:04 -07004357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 public void enableScreenAfterBoot() {
4359 synchronized(mWindowMap) {
4360 if (mSystemBooted) {
4361 return;
4362 }
4363 mSystemBooted = true;
4364 }
Romain Guy06882f82009-06-10 13:36:04 -07004365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 performEnableScreen();
4367 }
Romain Guy06882f82009-06-10 13:36:04 -07004368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 public void enableScreenIfNeededLocked() {
4370 if (mDisplayEnabled) {
4371 return;
4372 }
4373 if (!mSystemBooted) {
4374 return;
4375 }
4376 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4377 }
Romain Guy06882f82009-06-10 13:36:04 -07004378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379 public void performEnableScreen() {
4380 synchronized(mWindowMap) {
4381 if (mDisplayEnabled) {
4382 return;
4383 }
4384 if (!mSystemBooted) {
4385 return;
4386 }
Romain Guy06882f82009-06-10 13:36:04 -07004387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004388 // Don't enable the screen until all existing windows
4389 // have been drawn.
4390 final int N = mWindows.size();
4391 for (int i=0; i<N; i++) {
4392 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004393 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 return;
4395 }
4396 }
Romain Guy06882f82009-06-10 13:36:04 -07004397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 mDisplayEnabled = true;
4399 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004400 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 StringWriter sw = new StringWriter();
4402 PrintWriter pw = new PrintWriter(sw);
4403 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004404 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004405 }
4406 try {
4407 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4408 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004409 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 Parcel data = Parcel.obtain();
4411 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4412 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4413 data, null, 0);
4414 data.recycle();
4415 }
4416 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004417 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 }
4419 }
Romain Guy06882f82009-06-10 13:36:04 -07004420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004421 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004424 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4425 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 }
Romain Guy06882f82009-06-10 13:36:04 -07004427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 public void setInTouchMode(boolean mode) {
4429 synchronized(mWindowMap) {
4430 mInTouchMode = mode;
4431 }
4432 }
4433
Romain Guy06882f82009-06-10 13:36:04 -07004434 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004435 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004437 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004438 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 }
4440
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004441 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004442 }
Romain Guy06882f82009-06-10 13:36:04 -07004443
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004444 public void setRotationUnchecked(int rotation,
4445 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004446 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 long origId = Binder.clearCallingIdentity();
4450 boolean changed;
4451 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004452 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 }
Romain Guy06882f82009-06-10 13:36:04 -07004454
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004455 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 sendNewConfiguration();
4457 }
Romain Guy06882f82009-06-10 13:36:04 -07004458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 Binder.restoreCallingIdentity(origId);
4460 }
Romain Guy06882f82009-06-10 13:36:04 -07004461
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004462 /**
4463 * Apply a new rotation to the screen, respecting the requests of
4464 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4465 * re-evaluate the desired rotation.
4466 *
4467 * Returns null if the rotation has been changed. In this case YOU
4468 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4469 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004470 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 boolean changed;
4472 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4473 rotation = mRequestedRotation;
4474 } else {
4475 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004476 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004478 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004479 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004481 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004485 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 "Rotation changed to " + rotation
4487 + " from " + mRotation
4488 + " (forceApp=" + mForcedAppOrientation
4489 + ", req=" + mRequestedRotation + ")");
4490 mRotation = rotation;
4491 mWindowsFreezingScreen = true;
4492 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4493 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4494 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004495 mWaitingForConfig = true;
4496 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004498 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 mQueue.setOrientation(rotation);
4500 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004501 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 }
4503 for (int i=mWindows.size()-1; i>=0; i--) {
4504 WindowState w = (WindowState)mWindows.get(i);
4505 if (w.mSurface != null) {
4506 w.mOrientationChanging = true;
4507 }
4508 }
4509 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4510 try {
4511 mRotationWatchers.get(i).onRotationChanged(rotation);
4512 } catch (RemoteException e) {
4513 }
4514 }
4515 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 return changed;
4518 }
Romain Guy06882f82009-06-10 13:36:04 -07004519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 public int getRotation() {
4521 return mRotation;
4522 }
4523
4524 public int watchRotation(IRotationWatcher watcher) {
4525 final IBinder watcherBinder = watcher.asBinder();
4526 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4527 public void binderDied() {
4528 synchronized (mWindowMap) {
4529 for (int i=0; i<mRotationWatchers.size(); i++) {
4530 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004531 IRotationWatcher removed = mRotationWatchers.remove(i);
4532 if (removed != null) {
4533 removed.asBinder().unlinkToDeath(this, 0);
4534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 i--;
4536 }
4537 }
4538 }
4539 }
4540 };
Romain Guy06882f82009-06-10 13:36:04 -07004541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542 synchronized (mWindowMap) {
4543 try {
4544 watcher.asBinder().linkToDeath(dr, 0);
4545 mRotationWatchers.add(watcher);
4546 } catch (RemoteException e) {
4547 // Client died, no cleanup needed.
4548 }
Romain Guy06882f82009-06-10 13:36:04 -07004549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 return mRotation;
4551 }
4552 }
4553
4554 /**
4555 * Starts the view server on the specified port.
4556 *
4557 * @param port The port to listener to.
4558 *
4559 * @return True if the server was successfully started, false otherwise.
4560 *
4561 * @see com.android.server.ViewServer
4562 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4563 */
4564 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004565 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004566 return false;
4567 }
4568
4569 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4570 return false;
4571 }
4572
4573 if (port < 1024) {
4574 return false;
4575 }
4576
4577 if (mViewServer != null) {
4578 if (!mViewServer.isRunning()) {
4579 try {
4580 return mViewServer.start();
4581 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004582 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004583 }
4584 }
4585 return false;
4586 }
4587
4588 try {
4589 mViewServer = new ViewServer(this, port);
4590 return mViewServer.start();
4591 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004592 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 }
4594 return false;
4595 }
4596
Romain Guy06882f82009-06-10 13:36:04 -07004597 private boolean isSystemSecure() {
4598 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4599 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4600 }
4601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004602 /**
4603 * Stops the view server if it exists.
4604 *
4605 * @return True if the server stopped, false if it wasn't started or
4606 * couldn't be stopped.
4607 *
4608 * @see com.android.server.ViewServer
4609 */
4610 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004611 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 return false;
4613 }
4614
4615 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4616 return false;
4617 }
4618
4619 if (mViewServer != null) {
4620 return mViewServer.stop();
4621 }
4622 return false;
4623 }
4624
4625 /**
4626 * Indicates whether the view server is running.
4627 *
4628 * @return True if the server is running, false otherwise.
4629 *
4630 * @see com.android.server.ViewServer
4631 */
4632 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004633 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004634 return false;
4635 }
4636
4637 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4638 return false;
4639 }
4640
4641 return mViewServer != null && mViewServer.isRunning();
4642 }
4643
4644 /**
4645 * Lists all availble windows in the system. The listing is written in the
4646 * specified Socket's output stream with the following syntax:
4647 * windowHashCodeInHexadecimal windowName
4648 * Each line of the ouput represents a different window.
4649 *
4650 * @param client The remote client to send the listing to.
4651 * @return False if an error occured, true otherwise.
4652 */
4653 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004654 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004655 return false;
4656 }
4657
4658 boolean result = true;
4659
4660 Object[] windows;
4661 synchronized (mWindowMap) {
4662 windows = new Object[mWindows.size()];
4663 //noinspection unchecked
4664 windows = mWindows.toArray(windows);
4665 }
4666
4667 BufferedWriter out = null;
4668
4669 // Any uncaught exception will crash the system process
4670 try {
4671 OutputStream clientStream = client.getOutputStream();
4672 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4673
4674 final int count = windows.length;
4675 for (int i = 0; i < count; i++) {
4676 final WindowState w = (WindowState) windows[i];
4677 out.write(Integer.toHexString(System.identityHashCode(w)));
4678 out.write(' ');
4679 out.append(w.mAttrs.getTitle());
4680 out.write('\n');
4681 }
4682
4683 out.write("DONE.\n");
4684 out.flush();
4685 } catch (Exception e) {
4686 result = false;
4687 } finally {
4688 if (out != null) {
4689 try {
4690 out.close();
4691 } catch (IOException e) {
4692 result = false;
4693 }
4694 }
4695 }
4696
4697 return result;
4698 }
4699
4700 /**
4701 * Sends a command to a target window. The result of the command, if any, will be
4702 * written in the output stream of the specified socket.
4703 *
4704 * The parameters must follow this syntax:
4705 * windowHashcode extra
4706 *
4707 * Where XX is the length in characeters of the windowTitle.
4708 *
4709 * The first parameter is the target window. The window with the specified hashcode
4710 * will be the target. If no target can be found, nothing happens. The extra parameters
4711 * will be delivered to the target window and as parameters to the command itself.
4712 *
4713 * @param client The remote client to sent the result, if any, to.
4714 * @param command The command to execute.
4715 * @param parameters The command parameters.
4716 *
4717 * @return True if the command was successfully delivered, false otherwise. This does
4718 * not indicate whether the command itself was successful.
4719 */
4720 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004721 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 return false;
4723 }
4724
4725 boolean success = true;
4726 Parcel data = null;
4727 Parcel reply = null;
4728
4729 // Any uncaught exception will crash the system process
4730 try {
4731 // Find the hashcode of the window
4732 int index = parameters.indexOf(' ');
4733 if (index == -1) {
4734 index = parameters.length();
4735 }
4736 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004737 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738
4739 // Extract the command's parameter after the window description
4740 if (index < parameters.length()) {
4741 parameters = parameters.substring(index + 1);
4742 } else {
4743 parameters = "";
4744 }
4745
4746 final WindowManagerService.WindowState window = findWindow(hashCode);
4747 if (window == null) {
4748 return false;
4749 }
4750
4751 data = Parcel.obtain();
4752 data.writeInterfaceToken("android.view.IWindow");
4753 data.writeString(command);
4754 data.writeString(parameters);
4755 data.writeInt(1);
4756 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4757
4758 reply = Parcel.obtain();
4759
4760 final IBinder binder = window.mClient.asBinder();
4761 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4762 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4763
4764 reply.readException();
4765
4766 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004767 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004768 success = false;
4769 } finally {
4770 if (data != null) {
4771 data.recycle();
4772 }
4773 if (reply != null) {
4774 reply.recycle();
4775 }
4776 }
4777
4778 return success;
4779 }
4780
4781 private WindowState findWindow(int hashCode) {
4782 if (hashCode == -1) {
4783 return getFocusedWindow();
4784 }
4785
4786 synchronized (mWindowMap) {
4787 final ArrayList windows = mWindows;
4788 final int count = windows.size();
4789
4790 for (int i = 0; i < count; i++) {
4791 WindowState w = (WindowState) windows.get(i);
4792 if (System.identityHashCode(w) == hashCode) {
4793 return w;
4794 }
4795 }
4796 }
4797
4798 return null;
4799 }
4800
4801 /*
4802 * Instruct the Activity Manager to fetch the current configuration and broadcast
4803 * that to config-changed listeners if appropriate.
4804 */
4805 void sendNewConfiguration() {
4806 try {
4807 mActivityManager.updateConfiguration(null);
4808 } catch (RemoteException e) {
4809 }
4810 }
Romain Guy06882f82009-06-10 13:36:04 -07004811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 public Configuration computeNewConfiguration() {
4813 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004814 return computeNewConfigurationLocked();
4815 }
4816 }
Romain Guy06882f82009-06-10 13:36:04 -07004817
Dianne Hackbornc485a602009-03-24 22:39:49 -07004818 Configuration computeNewConfigurationLocked() {
4819 Configuration config = new Configuration();
4820 if (!computeNewConfigurationLocked(config)) {
4821 return null;
4822 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004823 return config;
4824 }
Romain Guy06882f82009-06-10 13:36:04 -07004825
Dianne Hackbornc485a602009-03-24 22:39:49 -07004826 boolean computeNewConfigurationLocked(Configuration config) {
4827 if (mDisplay == null) {
4828 return false;
4829 }
4830 mQueue.getInputConfiguration(config);
4831 final int dw = mDisplay.getWidth();
4832 final int dh = mDisplay.getHeight();
4833 int orientation = Configuration.ORIENTATION_SQUARE;
4834 if (dw < dh) {
4835 orientation = Configuration.ORIENTATION_PORTRAIT;
4836 } else if (dw > dh) {
4837 orientation = Configuration.ORIENTATION_LANDSCAPE;
4838 }
4839 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004840
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004841 DisplayMetrics dm = new DisplayMetrics();
4842 mDisplay.getMetrics(dm);
4843 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4844
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004845 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004846 // Note we only do this once because at this point we don't
4847 // expect the screen to change in this way at runtime, and want
4848 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004849 int longSize = dw;
4850 int shortSize = dh;
4851 if (longSize < shortSize) {
4852 int tmp = longSize;
4853 longSize = shortSize;
4854 shortSize = tmp;
4855 }
4856 longSize = (int)(longSize/dm.density);
4857 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004858
Dianne Hackborn723738c2009-06-25 19:48:04 -07004859 // These semi-magic numbers define our compatibility modes for
4860 // applications with different screens. Don't change unless you
4861 // make sure to test lots and lots of apps!
4862 if (longSize < 470) {
4863 // This is shorter than an HVGA normal density screen (which
4864 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004865 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4866 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004867 } else {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004868 // Is this a large screen?
4869 if (longSize > 640 && shortSize >= 480) {
4870 // VGA or larger screens at medium density are the point
4871 // at which we consider it to be a large screen.
4872 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4873 } else {
4874 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004875
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004876 // If this screen is wider than normal HVGA, or taller
4877 // than FWVGA, then for old apps we want to run in size
4878 // compatibility mode.
4879 if (shortSize > 321 || longSize > 570) {
4880 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4881 }
4882 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004883
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004884 // Is this a long screen?
4885 if (((longSize*3)/5) >= (shortSize-1)) {
4886 // Anything wider than WVGA (5:3) is considering to be long.
4887 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4888 } else {
4889 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4890 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004891 }
4892 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004893 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004894
Dianne Hackbornc485a602009-03-24 22:39:49 -07004895 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4896 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4897 mPolicy.adjustConfigurationLw(config);
4898 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004899 }
Romain Guy06882f82009-06-10 13:36:04 -07004900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004901 // -------------------------------------------------------------
4902 // Input Events and Focus Management
4903 // -------------------------------------------------------------
4904
4905 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004906 long curTime = SystemClock.uptimeMillis();
4907
Michael Chane10de972009-05-18 11:24:50 -07004908 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004909 if (mLastTouchEventType == eventType &&
4910 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4911 return;
4912 }
4913 mLastUserActivityCallTime = curTime;
4914 mLastTouchEventType = eventType;
4915 }
4916
4917 if (targetWin == null
4918 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4919 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 }
4921 }
4922
4923 // tells if it's a cheek event or not -- this function is stateful
4924 private static final int EVENT_NONE = 0;
4925 private static final int EVENT_UNKNOWN = 0;
4926 private static final int EVENT_CHEEK = 0;
4927 private static final int EVENT_IGNORE_DURATION = 300; // ms
4928 private static final float CHEEK_THRESHOLD = 0.6f;
4929 private int mEventState = EVENT_NONE;
4930 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004932 private int eventType(MotionEvent ev) {
4933 float size = ev.getSize();
4934 switch (ev.getAction()) {
4935 case MotionEvent.ACTION_DOWN:
4936 mEventSize = size;
4937 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4938 case MotionEvent.ACTION_UP:
4939 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004940 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004941 case MotionEvent.ACTION_MOVE:
4942 final int N = ev.getHistorySize();
4943 if (size > mEventSize) mEventSize = size;
4944 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4945 for (int i=0; i<N; i++) {
4946 size = ev.getHistoricalSize(i);
4947 if (size > mEventSize) mEventSize = size;
4948 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4949 }
4950 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4951 return TOUCH_EVENT;
4952 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004953 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004954 }
4955 default:
4956 // not good
4957 return OTHER_EVENT;
4958 }
4959 }
4960
4961 /**
4962 * @return Returns true if event was dispatched, false if it was dropped for any reason
4963 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004964 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004965 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004966 "dispatchPointer " + ev);
4967
Michael Chan53071d62009-05-13 17:29:48 -07004968 if (MEASURE_LATENCY) {
4969 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
4970 }
4971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004972 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004973 ev, true, false, pid, uid);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004974
Michael Chan53071d62009-05-13 17:29:48 -07004975 if (MEASURE_LATENCY) {
4976 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
4977 }
4978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004979 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07004980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981 if (action == MotionEvent.ACTION_UP) {
4982 // let go of our target
4983 mKeyWaiter.mMotionTarget = null;
4984 mPowerManager.logPointerUpEvent();
4985 } else if (action == MotionEvent.ACTION_DOWN) {
4986 mPowerManager.logPointerDownEvent();
4987 }
4988
4989 if (targetObj == null) {
4990 // In this case we are either dropping the event, or have received
4991 // a move or up without a down. It is common to receive move
4992 // events in such a way, since this means the user is moving the
4993 // pointer without actually pressing down. All other cases should
4994 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07004995 if (action != MotionEvent.ACTION_MOVE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004996 Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004997 }
Dianne Hackborn6adba242009-11-10 11:10:09 -08004998 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08004999 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005000 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005001 if (qev != null) {
5002 mQueue.recycleEvent(qev);
5003 }
5004 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005005 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005006 }
5007 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005008 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005009 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005010 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005011 if (qev != null) {
5012 mQueue.recycleEvent(qev);
5013 }
5014 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005015 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005016 }
Romain Guy06882f82009-06-10 13:36:04 -07005017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005018 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07005019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005020 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07005021 final long eventTimeNano = ev.getEventTimeNano();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005022
Joe Onorato8a9b2202010-02-26 18:56:32 -08005023 //Slog.i(TAG, "Sending " + ev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005024
5025 if (uid != 0 && uid != target.mSession.mUid) {
5026 if (mContext.checkPermission(
5027 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5028 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005029 Slog.w(TAG, "Permission denied: injecting pointer event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005030 + pid + " uid " + uid + " to window " + target
5031 + " owned by uid " + target.mSession.mUid);
5032 if (qev != null) {
5033 mQueue.recycleEvent(qev);
5034 }
5035 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005036 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005037 }
5038 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005039
Michael Chan53071d62009-05-13 17:29:48 -07005040 if (MEASURE_LATENCY) {
5041 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5042 }
5043
Romain Guy06882f82009-06-10 13:36:04 -07005044 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
5046 //target wants to ignore fat touch events
5047 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
5048 //explicit flag to return without processing event further
5049 boolean returnFlag = false;
5050 if((action == MotionEvent.ACTION_DOWN)) {
5051 mFatTouch = false;
5052 if(cheekPress) {
5053 mFatTouch = true;
5054 returnFlag = true;
5055 }
5056 } else {
5057 if(action == MotionEvent.ACTION_UP) {
5058 if(mFatTouch) {
5059 //earlier even was invalid doesnt matter if current up is cheekpress or not
5060 mFatTouch = false;
5061 returnFlag = true;
5062 } else if(cheekPress) {
5063 //cancel the earlier event
5064 ev.setAction(MotionEvent.ACTION_CANCEL);
5065 action = MotionEvent.ACTION_CANCEL;
5066 }
5067 } else if(action == MotionEvent.ACTION_MOVE) {
5068 if(mFatTouch) {
5069 //two cases here
5070 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07005071 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005072 returnFlag = true;
5073 } else if(cheekPress) {
5074 //valid down followed by invalid moves
5075 //an invalid move have to cancel earlier action
5076 ev.setAction(MotionEvent.ACTION_CANCEL);
5077 action = MotionEvent.ACTION_CANCEL;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005078 if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005079 //note that the subsequent invalid moves will not get here
5080 mFatTouch = true;
5081 }
5082 }
5083 } //else if action
5084 if(returnFlag) {
5085 //recycle que, ev
5086 if (qev != null) {
5087 mQueue.recycleEvent(qev);
5088 }
5089 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005090 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005091 }
5092 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07005093
Michael Chan9f028e62009-08-04 17:37:46 -07005094 // Enable this for testing the "right" value
5095 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07005096 int max_events_per_sec = 35;
5097 try {
5098 max_events_per_sec = Integer.parseInt(SystemProperties
5099 .get("windowsmgr.max_events_per_sec"));
5100 if (max_events_per_sec < 1) {
5101 max_events_per_sec = 35;
5102 }
5103 } catch (NumberFormatException e) {
5104 }
5105 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
5106 }
5107
5108 /*
5109 * Throttle events to minimize CPU usage when there's a flood of events
5110 * e.g. constant contact with the screen
5111 */
5112 if (action == MotionEvent.ACTION_MOVE) {
5113 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
5114 long now = SystemClock.uptimeMillis();
5115 if (now < nextEventTime) {
5116 try {
5117 Thread.sleep(nextEventTime - now);
5118 } catch (InterruptedException e) {
5119 }
5120 mLastTouchEventTime = nextEventTime;
5121 } else {
5122 mLastTouchEventTime = now;
5123 }
5124 }
5125
Michael Chan53071d62009-05-13 17:29:48 -07005126 if (MEASURE_LATENCY) {
5127 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5128 }
5129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005130 synchronized(mWindowMap) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005131 if (!target.isVisibleLw()) {
5132 // During this motion dispatch, the target window has become
5133 // invisible.
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005134 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005135 if (qev != null) {
5136 mQueue.recycleEvent(qev);
5137 }
5138 ev.recycle();
5139 return INJECT_SUCCEEDED;
5140 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005142 if (qev != null && action == MotionEvent.ACTION_MOVE) {
5143 mKeyWaiter.bindTargetWindowLocked(target,
5144 KeyWaiter.RETURN_PENDING_POINTER, qev);
5145 ev = null;
5146 } else {
5147 if (action == MotionEvent.ACTION_DOWN) {
5148 WindowState out = mKeyWaiter.mOutsideTouchTargets;
5149 if (out != null) {
5150 MotionEvent oev = MotionEvent.obtain(ev);
5151 oev.setAction(MotionEvent.ACTION_OUTSIDE);
5152 do {
5153 final Rect frame = out.mFrame;
5154 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
5155 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005156 out.mClient.dispatchPointer(oev, eventTime, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005157 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005158 Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005159 }
5160 oev.offsetLocation((float)frame.left, (float)frame.top);
5161 out = out.mNextOutsideTouch;
5162 } while (out != null);
5163 mKeyWaiter.mOutsideTouchTargets = null;
5164 }
5165 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005166
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005167 dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005168
Dianne Hackborn6adba242009-11-10 11:10:09 -08005169 final Rect frame = target.mFrame;
5170 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
5171 mKeyWaiter.bindTargetWindowLocked(target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005172 }
5173 }
Romain Guy06882f82009-06-10 13:36:04 -07005174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005175 // finally offset the event to the target's coordinate system and
5176 // dispatch the event.
5177 try {
5178 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005179 Slog.v(TAG, "Delivering pointer " + qev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005180 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005181
Michael Chan53071d62009-05-13 17:29:48 -07005182 if (MEASURE_LATENCY) {
5183 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
5184 }
5185
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005186 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07005187
5188 if (MEASURE_LATENCY) {
5189 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
5190 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005191 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005192 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005193 Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005194 mKeyWaiter.mMotionTarget = null;
5195 try {
5196 removeWindow(target.mSession, target.mClient);
5197 } catch (java.util.NoSuchElementException ex) {
5198 // This will happen if the window has already been
5199 // removed.
5200 }
5201 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005202 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005203 }
Romain Guy06882f82009-06-10 13:36:04 -07005204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005205 /**
5206 * @return Returns true if event was dispatched, false if it was dropped for any reason
5207 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005208 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005209 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07005211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005212 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005213 ev, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005214 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005215 Slog.w(TAG, "No focus window, dropping trackball: " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005216 if (qev != null) {
5217 mQueue.recycleEvent(qev);
5218 }
5219 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005220 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005221 }
5222 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
5223 if (qev != null) {
5224 mQueue.recycleEvent(qev);
5225 }
5226 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005227 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228 }
Romain Guy06882f82009-06-10 13:36:04 -07005229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005230 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005232 if (uid != 0 && uid != focus.mSession.mUid) {
5233 if (mContext.checkPermission(
5234 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5235 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005236 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005237 + pid + " uid " + uid + " to window " + focus
5238 + " owned by uid " + focus.mSession.mUid);
5239 if (qev != null) {
5240 mQueue.recycleEvent(qev);
5241 }
5242 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005243 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005244 }
5245 }
Romain Guy06882f82009-06-10 13:36:04 -07005246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005249 synchronized(mWindowMap) {
5250 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
5251 mKeyWaiter.bindTargetWindowLocked(focus,
5252 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
5253 // We don't deliver movement events to the client, we hold
5254 // them and wait for them to call back.
5255 ev = null;
5256 } else {
5257 mKeyWaiter.bindTargetWindowLocked(focus);
5258 }
5259 }
Romain Guy06882f82009-06-10 13:36:04 -07005260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005261 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005262 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005263 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005264 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005265 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005266 try {
5267 removeWindow(focus.mSession, focus.mClient);
5268 } catch (java.util.NoSuchElementException ex) {
5269 // This will happen if the window has already been
5270 // removed.
5271 }
5272 }
Romain Guy06882f82009-06-10 13:36:04 -07005273
Dianne Hackborncfaef692009-06-15 14:24:44 -07005274 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005275 }
Romain Guy06882f82009-06-10 13:36:04 -07005276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005277 /**
5278 * @return Returns true if event was dispatched, false if it was dropped for any reason
5279 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005280 private int dispatchKey(KeyEvent event, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005281 if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005282
5283 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005284 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005285 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005286 Slog.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005287 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005288 }
5289 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005290 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291 }
Romain Guy06882f82009-06-10 13:36:04 -07005292
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07005293 // Okay we have finished waiting for the last event to be processed.
5294 // First off, if this is a repeat event, check to see if there is
5295 // a corresponding up event in the queue. If there is, we will
5296 // just drop the repeat, because it makes no sense to repeat after
5297 // the user has released a key. (This is especially important for
5298 // long presses.)
5299 if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
5300 return INJECT_SUCCEEDED;
5301 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005303 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005304
Joe Onorato8a9b2202010-02-26 18:56:32 -08005305 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005306 TAG, "Dispatching to " + focus + ": " + event);
5307
5308 if (uid != 0 && uid != focus.mSession.mUid) {
5309 if (mContext.checkPermission(
5310 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5311 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005312 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 + pid + " uid " + uid + " to window " + focus
5314 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005315 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005316 }
5317 }
Romain Guy06882f82009-06-10 13:36:04 -07005318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005319 synchronized(mWindowMap) {
5320 mKeyWaiter.bindTargetWindowLocked(focus);
5321 }
5322
5323 // NOSHIP extra state logging
5324 mKeyWaiter.recordDispatchState(event, focus);
5325 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07005326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005327 try {
5328 if (DEBUG_INPUT || DEBUG_FOCUS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005329 Slog.v(TAG, "Delivering key " + event.getKeyCode()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005330 + " to " + focus);
5331 }
5332 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005333 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005334 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005335 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005336 try {
5337 removeWindow(focus.mSession, focus.mClient);
5338 } catch (java.util.NoSuchElementException ex) {
5339 // This will happen if the window has already been
5340 // removed.
5341 }
5342 }
Romain Guy06882f82009-06-10 13:36:04 -07005343
Dianne Hackborncfaef692009-06-15 14:24:44 -07005344 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345 }
Romain Guy06882f82009-06-10 13:36:04 -07005346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 public void pauseKeyDispatching(IBinder _token) {
5348 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5349 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005350 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351 }
5352
5353 synchronized (mWindowMap) {
5354 WindowToken token = mTokenMap.get(_token);
5355 if (token != null) {
5356 mKeyWaiter.pauseDispatchingLocked(token);
5357 }
5358 }
5359 }
5360
5361 public void resumeKeyDispatching(IBinder _token) {
5362 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5363 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005364 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005365 }
5366
5367 synchronized (mWindowMap) {
5368 WindowToken token = mTokenMap.get(_token);
5369 if (token != null) {
5370 mKeyWaiter.resumeDispatchingLocked(token);
5371 }
5372 }
5373 }
5374
5375 public void setEventDispatching(boolean enabled) {
5376 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5377 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005378 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005379 }
5380
5381 synchronized (mWindowMap) {
5382 mKeyWaiter.setEventDispatchingLocked(enabled);
5383 }
5384 }
Romain Guy06882f82009-06-10 13:36:04 -07005385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005386 /**
5387 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005388 *
5389 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005390 * {@link SystemClock#uptimeMillis()} as the timebase.)
5391 * @param sync If true, wait for the event to be completed before returning to the caller.
5392 * @return Returns true if event was dispatched, false if it was dropped for any reason
5393 */
5394 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5395 long downTime = ev.getDownTime();
5396 long eventTime = ev.getEventTime();
5397
5398 int action = ev.getAction();
5399 int code = ev.getKeyCode();
5400 int repeatCount = ev.getRepeatCount();
5401 int metaState = ev.getMetaState();
5402 int deviceId = ev.getDeviceId();
5403 int scancode = ev.getScanCode();
5404
5405 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5406 if (downTime == 0) downTime = eventTime;
5407
5408 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005409 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005410
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005411 final int pid = Binder.getCallingPid();
5412 final int uid = Binder.getCallingUid();
5413 final long ident = Binder.clearCallingIdentity();
5414 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005415 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005416 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005417 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005418 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005419 switch (result) {
5420 case INJECT_NO_PERMISSION:
5421 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305422 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005423 case INJECT_SUCCEEDED:
5424 return true;
5425 }
5426 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427 }
5428
5429 /**
5430 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005431 *
5432 * @param ev A motion event describing the pointer (touch) action. (As noted in
5433 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005434 * {@link SystemClock#uptimeMillis()} as the timebase.)
5435 * @param sync If true, wait for the event to be completed before returning to the caller.
5436 * @return Returns true if event was dispatched, false if it was dropped for any reason
5437 */
5438 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005439 final int pid = Binder.getCallingPid();
5440 final int uid = Binder.getCallingUid();
5441 final long ident = Binder.clearCallingIdentity();
5442 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005443 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005444 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005446 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005447 switch (result) {
5448 case INJECT_NO_PERMISSION:
5449 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305450 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005451 case INJECT_SUCCEEDED:
5452 return true;
5453 }
5454 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005455 }
Romain Guy06882f82009-06-10 13:36:04 -07005456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 /**
5458 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005459 *
5460 * @param ev A motion event describing the trackball action. (As noted in
5461 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005462 * {@link SystemClock#uptimeMillis()} as the timebase.)
5463 * @param sync If true, wait for the event to be completed before returning to the caller.
5464 * @return Returns true if event was dispatched, false if it was dropped for any reason
5465 */
5466 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005467 final int pid = Binder.getCallingPid();
5468 final int uid = Binder.getCallingUid();
5469 final long ident = Binder.clearCallingIdentity();
5470 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005471 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005472 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005473 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005474 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005475 switch (result) {
5476 case INJECT_NO_PERMISSION:
5477 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305478 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005479 case INJECT_SUCCEEDED:
5480 return true;
5481 }
5482 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005483 }
Romain Guy06882f82009-06-10 13:36:04 -07005484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005485 private WindowState getFocusedWindow() {
5486 synchronized (mWindowMap) {
5487 return getFocusedWindowLocked();
5488 }
5489 }
5490
5491 private WindowState getFocusedWindowLocked() {
5492 return mCurrentFocus;
5493 }
Romain Guy06882f82009-06-10 13:36:04 -07005494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005495 /**
5496 * This class holds the state for dispatching key events. This state
5497 * is protected by the KeyWaiter instance, NOT by the window lock. You
5498 * can be holding the main window lock while acquire the KeyWaiter lock,
5499 * but not the other way around.
5500 */
5501 final class KeyWaiter {
5502 // NOSHIP debugging
5503 public class DispatchState {
5504 private KeyEvent event;
5505 private WindowState focus;
5506 private long time;
5507 private WindowState lastWin;
5508 private IBinder lastBinder;
5509 private boolean finished;
5510 private boolean gotFirstWindow;
5511 private boolean eventDispatching;
5512 private long timeToSwitch;
5513 private boolean wasFrozen;
5514 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005515 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005517 DispatchState(KeyEvent theEvent, WindowState theFocus) {
5518 focus = theFocus;
5519 event = theEvent;
5520 time = System.currentTimeMillis();
5521 // snapshot KeyWaiter state
5522 lastWin = mLastWin;
5523 lastBinder = mLastBinder;
5524 finished = mFinished;
5525 gotFirstWindow = mGotFirstWindow;
5526 eventDispatching = mEventDispatching;
5527 timeToSwitch = mTimeToSwitch;
5528 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005529 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005530 // cache the paused state at ctor time as well
5531 if (theFocus == null || theFocus.mToken == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005532 focusPaused = false;
5533 } else {
5534 focusPaused = theFocus.mToken.paused;
5535 }
5536 }
Romain Guy06882f82009-06-10 13:36:04 -07005537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005538 public String toString() {
5539 return "{{" + event + " to " + focus + " @ " + time
5540 + " lw=" + lastWin + " lb=" + lastBinder
5541 + " fin=" + finished + " gfw=" + gotFirstWindow
5542 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005543 + " wf=" + wasFrozen + " fp=" + focusPaused
Christopher Tate46d45252010-02-09 15:48:57 -08005544 + " mcf=" + curFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005545 }
5546 };
5547 private DispatchState mDispatchState = null;
5548 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
5549 mDispatchState = new DispatchState(theEvent, theFocus);
5550 }
5551 // END NOSHIP
5552
5553 public static final int RETURN_NOTHING = 0;
5554 public static final int RETURN_PENDING_POINTER = 1;
5555 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07005556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005557 final Object SKIP_TARGET_TOKEN = new Object();
5558 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07005559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005560 private WindowState mLastWin = null;
5561 private IBinder mLastBinder = null;
5562 private boolean mFinished = true;
5563 private boolean mGotFirstWindow = false;
5564 private boolean mEventDispatching = true;
5565 private long mTimeToSwitch = 0;
5566 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07005567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005568 // Target of Motion events
5569 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07005570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005571 // Windows above the target who would like to receive an "outside"
5572 // touch event for any down events outside of them.
5573 WindowState mOutsideTouchTargets;
5574
5575 /**
5576 * Wait for the last event dispatch to complete, then find the next
5577 * target that should receive the given event and wait for that one
5578 * to be ready to receive it.
5579 */
5580 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5581 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005582 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005583 long startTime = SystemClock.uptimeMillis();
5584 long keyDispatchingTimeout = 5 * 1000;
5585 long waitedFor = 0;
5586
5587 while (true) {
5588 // Figure out which window we care about. It is either the
5589 // last window we are waiting to have process the event or,
5590 // if none, then the next window we think the event should go
5591 // to. Note: we retrieve mLastWin outside of the lock, so
5592 // it may change before we lock. Thus we must check it again.
5593 WindowState targetWin = mLastWin;
5594 boolean targetIsNew = targetWin == null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005595 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005596 TAG, "waitForLastKey: mFinished=" + mFinished +
5597 ", mLastWin=" + mLastWin);
5598 if (targetIsNew) {
5599 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005600 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005601 if (target == SKIP_TARGET_TOKEN) {
5602 // The user has pressed a special key, and we are
5603 // dropping all pending events before it.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005604 if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005605 + " " + nextMotion);
5606 return null;
5607 }
5608 if (target == CONSUMED_EVENT_TOKEN) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005609 if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005610 + " " + nextMotion);
5611 return target;
5612 }
5613 targetWin = (WindowState)target;
5614 }
Romain Guy06882f82009-06-10 13:36:04 -07005615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005618 // Now: is it okay to send the next event to this window?
5619 synchronized (this) {
5620 // First: did we come here based on the last window not
5621 // being null, but it changed by the time we got here?
5622 // If so, try again.
5623 if (!targetIsNew && mLastWin == null) {
5624 continue;
5625 }
Romain Guy06882f82009-06-10 13:36:04 -07005626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005627 // We never dispatch events if not finished with the
5628 // last one, or the display is frozen.
5629 if (mFinished && !mDisplayFrozen) {
5630 // If event dispatching is disabled, then we
5631 // just consume the events.
5632 if (!mEventDispatching) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005633 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005634 "Skipping event; dispatching disabled: "
5635 + nextKey + " " + nextMotion);
5636 return null;
5637 }
5638 if (targetWin != null) {
5639 // If this is a new target, and that target is not
5640 // paused or unresponsive, then all looks good to
5641 // handle the event.
5642 if (targetIsNew && !targetWin.mToken.paused) {
5643 return targetWin;
5644 }
Romain Guy06882f82009-06-10 13:36:04 -07005645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005646 // If we didn't find a target window, and there is no
5647 // focused app window, then just eat the events.
5648 } else if (mFocusedApp == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005649 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005650 "Skipping event; no focused app: "
5651 + nextKey + " " + nextMotion);
5652 return null;
5653 }
5654 }
Romain Guy06882f82009-06-10 13:36:04 -07005655
Joe Onorato8a9b2202010-02-26 18:56:32 -08005656 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005657 TAG, "Waiting for last key in " + mLastBinder
5658 + " target=" + targetWin
5659 + " mFinished=" + mFinished
5660 + " mDisplayFrozen=" + mDisplayFrozen
5661 + " targetIsNew=" + targetIsNew
5662 + " paused="
5663 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005664 + " mFocusedApp=" + mFocusedApp
5665 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005667 targetApp = targetWin != null
5668 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005670 long curTimeout = keyDispatchingTimeout;
5671 if (mTimeToSwitch != 0) {
5672 long now = SystemClock.uptimeMillis();
5673 if (mTimeToSwitch <= now) {
5674 // If an app switch key has been pressed, and we have
5675 // waited too long for the current app to finish
5676 // processing keys, then wait no more!
Christopher Tate136b1f92010-02-11 17:51:24 -08005677 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005678 continue;
5679 }
5680 long switchTimeout = mTimeToSwitch - now;
5681 if (curTimeout > switchTimeout) {
5682 curTimeout = switchTimeout;
5683 }
5684 }
Romain Guy06882f82009-06-10 13:36:04 -07005685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005686 try {
5687 // after that continue
5688 // processing keys, so we don't get stuck.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005689 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005690 TAG, "Waiting for key dispatch: " + curTimeout);
5691 wait(curTimeout);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005692 if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005693 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005694 + startTime + " switchTime=" + mTimeToSwitch
5695 + " target=" + targetWin + " mLW=" + mLastWin
5696 + " mLB=" + mLastBinder + " fin=" + mFinished
5697 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005698 } catch (InterruptedException e) {
5699 }
5700 }
5701
5702 // If we were frozen during configuration change, restart the
5703 // timeout checks from now; otherwise look at whether we timed
5704 // out before awakening.
5705 if (mWasFrozen) {
5706 waitedFor = 0;
5707 mWasFrozen = false;
5708 } else {
5709 waitedFor = SystemClock.uptimeMillis() - startTime;
5710 }
5711
5712 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5713 IApplicationToken at = null;
5714 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005715 Slog.w(TAG, "Key dispatching timed out sending to " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005716 (targetWin != null ? targetWin.mAttrs.getTitle()
Ken Shirriff8200b202010-02-04 13:34:37 -08005717 : "<null>: no window ready for key dispatch"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005718 // NOSHIP debugging
Joe Onorato8a9b2202010-02-26 18:56:32 -08005719 Slog.w(TAG, "Previous dispatch state: " + mDispatchState);
5720 Slog.w(TAG, "Current dispatch state: " +
Ken Shirriff8200b202010-02-04 13:34:37 -08005721 new DispatchState(nextKey, targetWin));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005722 // END NOSHIP
5723 //dump();
5724 if (targetWin != null) {
5725 at = targetWin.getAppToken();
5726 } else if (targetApp != null) {
5727 at = targetApp.appToken;
5728 }
5729 }
5730
5731 boolean abort = true;
5732 if (at != null) {
5733 try {
5734 long timeout = at.getKeyDispatchingTimeout();
5735 if (timeout > waitedFor) {
5736 // we did not wait the proper amount of time for this application.
5737 // set the timeout to be the real timeout and wait again.
5738 keyDispatchingTimeout = timeout - waitedFor;
5739 continue;
5740 } else {
5741 abort = at.keyDispatchingTimedOut();
5742 }
5743 } catch (RemoteException ex) {
5744 }
5745 }
5746
5747 synchronized (this) {
5748 if (abort && (mLastWin == targetWin || targetWin == null)) {
5749 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005750 if (mLastWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005751 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005752 "Window " + mLastWin +
5753 " timed out on key input");
5754 if (mLastWin.mToken.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005755 Slog.w(TAG, "Un-pausing dispatching to this window");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005756 mLastWin.mToken.paused = false;
5757 }
5758 }
5759 if (mMotionTarget == targetWin) {
5760 mMotionTarget = null;
5761 }
5762 mLastWin = null;
5763 mLastBinder = null;
5764 if (failIfTimeout || targetWin == null) {
5765 return null;
5766 }
5767 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005768 Slog.w(TAG, "Continuing to wait for key to be dispatched");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005769 startTime = SystemClock.uptimeMillis();
5770 }
5771 }
5772 }
5773 }
5774 }
Romain Guy06882f82009-06-10 13:36:04 -07005775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005776 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005777 MotionEvent nextMotion, boolean isPointerEvent,
5778 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005779 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005781 if (nextKey != null) {
5782 // Find the target window for a normal key event.
5783 final int keycode = nextKey.getKeyCode();
5784 final int repeatCount = nextKey.getRepeatCount();
5785 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5786 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005788 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005789 if (callingUid == 0 ||
5790 mContext.checkPermission(
5791 android.Manifest.permission.INJECT_EVENTS,
5792 callingPid, callingUid)
5793 == PackageManager.PERMISSION_GRANTED) {
5794 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005795 nextKey.getMetaState(), down, repeatCount,
5796 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005797 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005798 Slog.w(TAG, "Event timeout during app switch: dropping "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005799 + nextKey);
5800 return SKIP_TARGET_TOKEN;
5801 }
Romain Guy06882f82009-06-10 13:36:04 -07005802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005803 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005805 WindowState focus = null;
5806 synchronized(mWindowMap) {
5807 focus = getFocusedWindowLocked();
5808 }
Romain Guy06882f82009-06-10 13:36:04 -07005809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005810 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005811
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005812 if (callingUid == 0 ||
5813 (focus != null && callingUid == focus.mSession.mUid) ||
5814 mContext.checkPermission(
5815 android.Manifest.permission.INJECT_EVENTS,
5816 callingPid, callingUid)
5817 == PackageManager.PERMISSION_GRANTED) {
5818 if (mPolicy.interceptKeyTi(focus,
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005819 keycode, nextKey.getMetaState(), down, repeatCount,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005820 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005821 return CONSUMED_EVENT_TOKEN;
5822 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 }
Romain Guy06882f82009-06-10 13:36:04 -07005824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005827 } else if (!isPointerEvent) {
5828 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5829 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005830 Slog.w(TAG, "Event timeout during app switch: dropping trackball "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831 + nextMotion);
5832 return SKIP_TARGET_TOKEN;
5833 }
Romain Guy06882f82009-06-10 13:36:04 -07005834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005835 WindowState focus = null;
5836 synchronized(mWindowMap) {
5837 focus = getFocusedWindowLocked();
5838 }
Romain Guy06882f82009-06-10 13:36:04 -07005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5841 return focus;
5842 }
Romain Guy06882f82009-06-10 13:36:04 -07005843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 if (nextMotion == null) {
5845 return SKIP_TARGET_TOKEN;
5846 }
Romain Guy06882f82009-06-10 13:36:04 -07005847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005848 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5849 KeyEvent.KEYCODE_UNKNOWN);
5850 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005851 Slog.w(TAG, "Event timeout during app switch: dropping pointer "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005852 + nextMotion);
5853 return SKIP_TARGET_TOKEN;
5854 }
Romain Guy06882f82009-06-10 13:36:04 -07005855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005856 // Find the target window for a pointer event.
5857 int action = nextMotion.getAction();
5858 final float xf = nextMotion.getX();
5859 final float yf = nextMotion.getY();
5860 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005862 final boolean screenWasOff = qev != null
5863 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005865 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005867 synchronized(mWindowMap) {
5868 synchronized (this) {
5869 if (action == MotionEvent.ACTION_DOWN) {
5870 if (mMotionTarget != null) {
5871 // this is weird, we got a pen down, but we thought it was
5872 // already down!
5873 // XXX: We should probably send an ACTION_UP to the current
5874 // target.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005875 Slog.w(TAG, "Pointer down received while already down in: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005876 + mMotionTarget);
5877 mMotionTarget = null;
5878 }
Romain Guy06882f82009-06-10 13:36:04 -07005879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 // ACTION_DOWN is special, because we need to lock next events to
5881 // the window we'll land onto.
5882 final int x = (int)xf;
5883 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005885 final ArrayList windows = mWindows;
5886 final int N = windows.size();
5887 WindowState topErrWindow = null;
5888 final Rect tmpRect = mTempRect;
5889 for (int i=N-1; i>=0; i--) {
5890 WindowState child = (WindowState)windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005891 //Slog.i(TAG, "Checking dispatch to: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005892 final int flags = child.mAttrs.flags;
5893 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5894 if (topErrWindow == null) {
5895 topErrWindow = child;
5896 }
5897 }
5898 if (!child.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005899 //Slog.i(TAG, "Not visible!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 continue;
5901 }
5902 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005903 //Slog.i(TAG, "Not touchable!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005904 if ((flags & WindowManager.LayoutParams
5905 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5906 child.mNextOutsideTouch = mOutsideTouchTargets;
5907 mOutsideTouchTargets = child;
5908 }
5909 continue;
5910 }
5911 tmpRect.set(child.mFrame);
5912 if (child.mTouchableInsets == ViewTreeObserver
5913 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5914 // The touch is inside of the window if it is
5915 // inside the frame, AND the content part of that
5916 // frame that was given by the application.
5917 tmpRect.left += child.mGivenContentInsets.left;
5918 tmpRect.top += child.mGivenContentInsets.top;
5919 tmpRect.right -= child.mGivenContentInsets.right;
5920 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5921 } else if (child.mTouchableInsets == ViewTreeObserver
5922 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5923 // The touch is inside of the window if it is
5924 // inside the frame, AND the visible part of that
5925 // frame that was given by the application.
5926 tmpRect.left += child.mGivenVisibleInsets.left;
5927 tmpRect.top += child.mGivenVisibleInsets.top;
5928 tmpRect.right -= child.mGivenVisibleInsets.right;
5929 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5930 }
5931 final int touchFlags = flags &
5932 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5933 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5934 if (tmpRect.contains(x, y) || touchFlags == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005935 //Slog.i(TAG, "Using this target!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005936 if (!screenWasOff || (flags &
5937 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5938 mMotionTarget = child;
5939 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005940 //Slog.i(TAG, "Waking, skip!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005941 mMotionTarget = null;
5942 }
5943 break;
5944 }
Romain Guy06882f82009-06-10 13:36:04 -07005945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005946 if ((flags & WindowManager.LayoutParams
5947 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5948 child.mNextOutsideTouch = mOutsideTouchTargets;
5949 mOutsideTouchTargets = child;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005950 //Slog.i(TAG, "Adding to outside target list: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005951 }
5952 }
5953
5954 // if there's an error window but it's not accepting
5955 // focus (typically because it is not yet visible) just
5956 // wait for it -- any other focused window may in fact
5957 // be in ANR state.
5958 if (topErrWindow != null && mMotionTarget != topErrWindow) {
5959 mMotionTarget = null;
5960 }
5961 }
Romain Guy06882f82009-06-10 13:36:04 -07005962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963 target = mMotionTarget;
5964 }
5965 }
Romain Guy06882f82009-06-10 13:36:04 -07005966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005967 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07005968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005969 // Pointer events are a little different -- if there isn't a
5970 // target found for any event, then just drop it.
5971 return target != null ? target : SKIP_TARGET_TOKEN;
5972 }
Romain Guy06882f82009-06-10 13:36:04 -07005973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005974 boolean checkShouldDispatchKey(int keycode) {
5975 synchronized (this) {
5976 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
5977 mTimeToSwitch = 0;
5978 return true;
5979 }
5980 if (mTimeToSwitch != 0
5981 && mTimeToSwitch < SystemClock.uptimeMillis()) {
5982 return false;
5983 }
5984 return true;
5985 }
5986 }
Romain Guy06882f82009-06-10 13:36:04 -07005987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005988 void bindTargetWindowLocked(WindowState win,
5989 int pendingWhat, QueuedEvent pendingMotion) {
5990 synchronized (this) {
5991 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
5992 }
5993 }
Romain Guy06882f82009-06-10 13:36:04 -07005994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005995 void bindTargetWindowLocked(WindowState win) {
5996 synchronized (this) {
5997 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
5998 }
5999 }
6000
6001 void bindTargetWindowLockedLocked(WindowState win,
6002 int pendingWhat, QueuedEvent pendingMotion) {
6003 mLastWin = win;
6004 mLastBinder = win.mClient.asBinder();
6005 mFinished = false;
6006 if (pendingMotion != null) {
6007 final Session s = win.mSession;
6008 if (pendingWhat == RETURN_PENDING_POINTER) {
6009 releasePendingPointerLocked(s);
6010 s.mPendingPointerMove = pendingMotion;
6011 s.mPendingPointerWindow = win;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006012 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006013 "bindTargetToWindow " + s.mPendingPointerMove);
6014 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
6015 releasePendingTrackballLocked(s);
6016 s.mPendingTrackballMove = pendingMotion;
6017 s.mPendingTrackballWindow = win;
6018 }
6019 }
6020 }
Romain Guy06882f82009-06-10 13:36:04 -07006021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006022 void releasePendingPointerLocked(Session s) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006023 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006024 "releasePendingPointer " + s.mPendingPointerMove);
6025 if (s.mPendingPointerMove != null) {
6026 mQueue.recycleEvent(s.mPendingPointerMove);
6027 s.mPendingPointerMove = null;
6028 }
6029 }
Romain Guy06882f82009-06-10 13:36:04 -07006030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006031 void releasePendingTrackballLocked(Session s) {
6032 if (s.mPendingTrackballMove != null) {
6033 mQueue.recycleEvent(s.mPendingTrackballMove);
6034 s.mPendingTrackballMove = null;
6035 }
6036 }
Romain Guy06882f82009-06-10 13:36:04 -07006037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006038 MotionEvent finishedKey(Session session, IWindow client, boolean force,
6039 int returnWhat) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006040 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006041 TAG, "finishedKey: client=" + client + ", force=" + force);
6042
6043 if (client == null) {
6044 return null;
6045 }
6046
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006047 MotionEvent res = null;
6048 QueuedEvent qev = null;
6049 WindowState win = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006051 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006052 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006053 TAG, "finishedKey: client=" + client.asBinder()
6054 + ", force=" + force + ", last=" + mLastBinder
6055 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
6056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006057 if (returnWhat == RETURN_PENDING_POINTER) {
6058 qev = session.mPendingPointerMove;
6059 win = session.mPendingPointerWindow;
6060 session.mPendingPointerMove = null;
6061 session.mPendingPointerWindow = null;
6062 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
6063 qev = session.mPendingTrackballMove;
6064 win = session.mPendingTrackballWindow;
6065 session.mPendingTrackballMove = null;
6066 session.mPendingTrackballWindow = null;
6067 }
Romain Guy06882f82009-06-10 13:36:04 -07006068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006069 if (mLastBinder == client.asBinder()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006070 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006071 TAG, "finishedKey: last paused="
6072 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
6073 if (mLastWin != null && (!mLastWin.mToken.paused || force
6074 || !mEventDispatching)) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006075 doFinishedKeyLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006076 } else {
6077 // Make sure to wake up anyone currently waiting to
6078 // dispatch a key, so they can re-evaluate their
6079 // current situation.
6080 mFinished = true;
6081 notifyAll();
6082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006083 }
Romain Guy06882f82009-06-10 13:36:04 -07006084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006085 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006086 res = (MotionEvent)qev.event;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006087 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006088 "Returning pending motion: " + res);
6089 mQueue.recycleEvent(qev);
6090 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
6091 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
6092 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006093 }
Christopher Tate2624fbc2009-12-11 12:11:31 -08006094 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006095
Christopher Tate2624fbc2009-12-11 12:11:31 -08006096 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
6097 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08006098 dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006099 }
6100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006101
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006102 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006103 }
6104
6105 void tickle() {
6106 synchronized (this) {
6107 notifyAll();
6108 }
6109 }
Romain Guy06882f82009-06-10 13:36:04 -07006110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006111 void handleNewWindowLocked(WindowState newWindow) {
6112 if (!newWindow.canReceiveKeys()) {
6113 return;
6114 }
6115 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006116 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117 TAG, "New key dispatch window: win="
6118 + newWindow.mClient.asBinder()
6119 + ", last=" + mLastBinder
6120 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6121 + "), finished=" + mFinished + ", paused="
6122 + newWindow.mToken.paused);
6123
6124 // Displaying a window implicitly causes dispatching to
6125 // be unpaused. (This is to protect against bugs if someone
6126 // pauses dispatching but forgets to resume.)
6127 newWindow.mToken.paused = false;
6128
6129 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006130
6131 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006132 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006133 "New SYSTEM_ERROR window; resetting state");
6134 mLastWin = null;
6135 mLastBinder = null;
6136 mMotionTarget = null;
6137 mFinished = true;
6138 } else if (mLastWin != null) {
6139 // If the new window is above the window we are
6140 // waiting on, then stop waiting and let key dispatching
6141 // start on the new guy.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006142 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 TAG, "Last win layer=" + mLastWin.mLayer
6144 + ", new win layer=" + newWindow.mLayer);
6145 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006146 // The new window is above the old; finish pending input to the last
6147 // window and start directing it to the new one.
6148 mLastWin.mToken.paused = false;
Christopher Tate136b1f92010-02-11 17:51:24 -08006149 doFinishedKeyLocked(false); // does a notifyAll()
6150 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006151 }
6152 }
6153
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006154 // Now that we've put a new window state in place, make the event waiter
6155 // take notice and retarget its attentions.
6156 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006157 }
6158 }
6159
6160 void pauseDispatchingLocked(WindowToken token) {
6161 synchronized (this)
6162 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006163 if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 token.paused = true;
6165
6166 /*
6167 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
6168 mPaused = true;
6169 } else {
6170 if (mLastWin == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006171 Slog.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 } else if (mFinished) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006173 Slog.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006174 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006175 Slog.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006176 }
6177 }
6178 */
6179 }
6180 }
6181
6182 void resumeDispatchingLocked(WindowToken token) {
6183 synchronized (this) {
6184 if (token.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006185 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 TAG, "Resuming WindowToken " + token
6187 + ", last=" + mLastBinder
6188 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6189 + "), finished=" + mFinished + ", paused="
6190 + token.paused);
6191 token.paused = false;
6192 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006193 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006194 } else {
6195 notifyAll();
6196 }
6197 }
6198 }
6199 }
6200
6201 void setEventDispatchingLocked(boolean enabled) {
6202 synchronized (this) {
6203 mEventDispatching = enabled;
6204 notifyAll();
6205 }
6206 }
Romain Guy06882f82009-06-10 13:36:04 -07006207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006208 void appSwitchComing() {
6209 synchronized (this) {
6210 // Don't wait for more than .5 seconds for app to finish
6211 // processing the pending events.
6212 long now = SystemClock.uptimeMillis() + 500;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006213 if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006214 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
6215 mTimeToSwitch = now;
6216 }
6217 notifyAll();
6218 }
6219 }
Romain Guy06882f82009-06-10 13:36:04 -07006220
Christopher Tate136b1f92010-02-11 17:51:24 -08006221 private final void doFinishedKeyLocked(boolean force) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006222 if (mLastWin != null) {
6223 releasePendingPointerLocked(mLastWin.mSession);
6224 releasePendingTrackballLocked(mLastWin.mSession);
6225 }
Romain Guy06882f82009-06-10 13:36:04 -07006226
Christopher Tate136b1f92010-02-11 17:51:24 -08006227 if (force || mLastWin == null || !mLastWin.mToken.paused
6228 || !mLastWin.isVisibleLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 // If the current window has been paused, we aren't -really-
6230 // finished... so let the waiters still wait.
6231 mLastWin = null;
6232 mLastBinder = null;
6233 }
6234 mFinished = true;
6235 notifyAll();
6236 }
6237 }
6238
6239 private class KeyQ extends KeyInputQueue
6240 implements KeyInputQueue.FilterCallback {
6241 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07006242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006243 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07006244 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006245 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
6246 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
6247 "KEEP_SCREEN_ON_FLAG");
6248 mHoldingScreen.setReferenceCounted(false);
6249 }
6250
6251 @Override
6252 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
6253 if (mPolicy.preprocessInputEventTq(event)) {
6254 return true;
6255 }
Romain Guy06882f82009-06-10 13:36:04 -07006256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006257 switch (event.type) {
6258 case RawInputEvent.EV_KEY: {
6259 // XXX begin hack
6260 if (DEBUG) {
6261 if (event.keycode == KeyEvent.KEYCODE_G) {
6262 if (event.value != 0) {
6263 // G down
6264 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
6265 }
6266 return false;
6267 }
6268 if (event.keycode == KeyEvent.KEYCODE_D) {
6269 if (event.value != 0) {
6270 //dump();
6271 }
6272 return false;
6273 }
6274 }
6275 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07006276
Charles Mendis322591c2009-10-29 11:06:59 -07006277 boolean screenIsOff = !mPowerManager.isScreenOn();
6278 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006279 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07006280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
6282 mPowerManager.goToSleep(event.when);
6283 }
6284
6285 if (screenIsOff) {
6286 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6287 }
6288 if (screenIsDim) {
6289 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6290 }
6291 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
6292 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07006293 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 }
Romain Guy06882f82009-06-10 13:36:04 -07006295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006296 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
6297 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
6298 filterQueue(this);
6299 mKeyWaiter.appSwitchComing();
6300 }
6301 return true;
6302 } else {
6303 return false;
6304 }
6305 }
Romain Guy06882f82009-06-10 13:36:04 -07006306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006307 case RawInputEvent.EV_REL: {
Charles Mendis322591c2009-10-29 11:06:59 -07006308 boolean screenIsOff = !mPowerManager.isScreenOn();
6309 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006310 if (screenIsOff) {
6311 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
6312 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006313 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006314 return false;
6315 }
6316 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6317 }
6318 if (screenIsDim) {
6319 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6320 }
6321 return true;
6322 }
Romain Guy06882f82009-06-10 13:36:04 -07006323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 case RawInputEvent.EV_ABS: {
Charles Mendis322591c2009-10-29 11:06:59 -07006325 boolean screenIsOff = !mPowerManager.isScreenOn();
6326 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327 if (screenIsOff) {
6328 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
6329 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006330 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 return false;
6332 }
6333 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6334 }
6335 if (screenIsDim) {
6336 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6337 }
6338 return true;
6339 }
Romain Guy06882f82009-06-10 13:36:04 -07006340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006341 default:
6342 return true;
6343 }
6344 }
6345
6346 public int filterEvent(QueuedEvent ev) {
6347 switch (ev.classType) {
6348 case RawInputEvent.CLASS_KEYBOARD:
6349 KeyEvent ke = (KeyEvent)ev.event;
6350 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006351 Slog.w(TAG, "Dropping movement key during app switch: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 + ke.getKeyCode() + ", action=" + ke.getAction());
6353 return FILTER_REMOVE;
6354 }
6355 return FILTER_ABORT;
6356 default:
6357 return FILTER_KEEP;
6358 }
6359 }
Romain Guy06882f82009-06-10 13:36:04 -07006360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006361 /**
6362 * Must be called with the main window manager lock held.
6363 */
6364 void setHoldScreenLocked(boolean holding) {
6365 boolean state = mHoldingScreen.isHeld();
6366 if (holding != state) {
6367 if (holding) {
6368 mHoldingScreen.acquire();
6369 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006370 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006371 mHoldingScreen.release();
6372 }
6373 }
6374 }
Michael Chan53071d62009-05-13 17:29:48 -07006375 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376
6377 public boolean detectSafeMode() {
6378 mSafeMode = mPolicy.detectSafeMode();
6379 return mSafeMode;
6380 }
Romain Guy06882f82009-06-10 13:36:04 -07006381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 public void systemReady() {
6383 mPolicy.systemReady();
6384 }
Romain Guy06882f82009-06-10 13:36:04 -07006385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 private final class InputDispatcherThread extends Thread {
6387 // Time to wait when there is nothing to do: 9999 seconds.
6388 static final int LONG_WAIT=9999*1000;
6389
6390 public InputDispatcherThread() {
6391 super("InputDispatcher");
6392 }
Romain Guy06882f82009-06-10 13:36:04 -07006393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 @Override
6395 public void run() {
6396 while (true) {
6397 try {
6398 process();
6399 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006400 Slog.e(TAG, "Exception in input dispatcher", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 }
6402 }
6403 }
Romain Guy06882f82009-06-10 13:36:04 -07006404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006405 private void process() {
6406 android.os.Process.setThreadPriority(
6407 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07006408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 // The last key event we saw
6410 KeyEvent lastKey = null;
6411
6412 // Last keydown time for auto-repeating keys
6413 long lastKeyTime = SystemClock.uptimeMillis();
6414 long nextKeyTime = lastKeyTime+LONG_WAIT;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006415 long downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006416
Romain Guy06882f82009-06-10 13:36:04 -07006417 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006418 int keyRepeatCount = 0;
6419
6420 // Need to report that configuration has changed?
6421 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07006422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006423 while (true) {
6424 long curTime = SystemClock.uptimeMillis();
6425
Joe Onorato8a9b2202010-02-26 18:56:32 -08006426 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 TAG, "Waiting for next key: now=" + curTime
6428 + ", repeat @ " + nextKeyTime);
6429
6430 // Retrieve next event, waiting only as long as the next
6431 // repeat timeout. If the configuration has changed, then
6432 // don't wait at all -- we'll report the change as soon as
6433 // we have processed all events.
6434 QueuedEvent ev = mQueue.getEvent(
6435 (int)((!configChanged && curTime < nextKeyTime)
6436 ? (nextKeyTime-curTime) : 0));
6437
Joe Onorato8a9b2202010-02-26 18:56:32 -08006438 if (DEBUG_INPUT && ev != null) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
6440
Michael Chan53071d62009-05-13 17:29:48 -07006441 if (MEASURE_LATENCY) {
6442 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
6443 }
6444
Mike Lockwood3d0ea722009-10-21 22:58:29 -04006445 if (lastKey != null && !mPolicy.allowKeyRepeat()) {
6446 // cancel key repeat at the request of the policy.
6447 lastKey = null;
6448 downTime = 0;
6449 lastKeyTime = curTime;
6450 nextKeyTime = curTime + LONG_WAIT;
6451 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006452 try {
6453 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07006454 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006455 int eventType;
6456 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
6457 eventType = eventType((MotionEvent)ev.event);
6458 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
6459 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
6460 eventType = LocalPowerManager.BUTTON_EVENT;
6461 } else {
6462 eventType = LocalPowerManager.OTHER_EVENT;
6463 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006464 try {
Michael Chan53071d62009-05-13 17:29:48 -07006465 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07006466 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07006467 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07006468 mBatteryStats.noteInputEvent();
6469 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006470 } catch (RemoteException e) {
6471 // Ignore
6472 }
Michael Chane10de972009-05-18 11:24:50 -07006473
Mike Lockwood5db42402009-11-30 14:51:51 -05006474 if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) {
6475 // do not wake screen in this case
6476 } else if (eventType != TOUCH_EVENT
Michael Chane10de972009-05-18 11:24:50 -07006477 && eventType != LONG_TOUCH_EVENT
6478 && eventType != CHEEK_EVENT) {
6479 mPowerManager.userActivity(curTime, false,
6480 eventType, false);
6481 } else if (mLastTouchEventType != eventType
6482 || (curTime - mLastUserActivityCallTime)
6483 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
6484 mLastUserActivityCallTime = curTime;
6485 mLastTouchEventType = eventType;
6486 mPowerManager.userActivity(curTime, false,
6487 eventType, false);
6488 }
6489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 switch (ev.classType) {
6491 case RawInputEvent.CLASS_KEYBOARD:
6492 KeyEvent ke = (KeyEvent)ev.event;
6493 if (ke.isDown()) {
6494 lastKey = ke;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006495 downTime = curTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 keyRepeatCount = 0;
6497 lastKeyTime = curTime;
6498 nextKeyTime = lastKeyTime
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006499 + ViewConfiguration.getLongPressTimeout();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006500 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006501 TAG, "Received key down: first repeat @ "
6502 + nextKeyTime);
6503 } else {
6504 lastKey = null;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006505 downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006506 // Arbitrary long timeout.
6507 lastKeyTime = curTime;
6508 nextKeyTime = curTime + LONG_WAIT;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006509 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 TAG, "Received key up: ignore repeat @ "
6511 + nextKeyTime);
6512 }
6513 dispatchKey((KeyEvent)ev.event, 0, 0);
6514 mQueue.recycleEvent(ev);
6515 break;
6516 case RawInputEvent.CLASS_TOUCHSCREEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08006517 //Slog.i(TAG, "Read next event " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006518 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
6519 break;
6520 case RawInputEvent.CLASS_TRACKBALL:
6521 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
6522 break;
6523 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
6524 configChanged = true;
6525 break;
6526 default:
6527 mQueue.recycleEvent(ev);
6528 break;
6529 }
Romain Guy06882f82009-06-10 13:36:04 -07006530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 } else if (configChanged) {
6532 configChanged = false;
6533 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07006534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006535 } else if (lastKey != null) {
6536 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006538 // Timeout occurred while key was down. If it is at or
6539 // past the key repeat time, dispatch the repeat.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006540 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006541 TAG, "Key timeout: repeat=" + nextKeyTime
6542 + ", now=" + curTime);
6543 if (curTime < nextKeyTime) {
6544 continue;
6545 }
Romain Guy06882f82009-06-10 13:36:04 -07006546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 lastKeyTime = nextKeyTime;
6548 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
6549 keyRepeatCount++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006550 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 TAG, "Key repeat: count=" + keyRepeatCount
6552 + ", next @ " + nextKeyTime);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006553 KeyEvent newEvent;
6554 if (downTime != 0 && (downTime
6555 + ViewConfiguration.getLongPressTimeout())
6556 <= curTime) {
6557 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6558 curTime, keyRepeatCount,
6559 lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6560 downTime = 0;
6561 } else {
6562 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6563 curTime, keyRepeatCount);
6564 }
6565 dispatchKey(newEvent, 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07006566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 } else {
6568 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 lastKeyTime = curTime;
6571 nextKeyTime = curTime + LONG_WAIT;
6572 }
Romain Guy06882f82009-06-10 13:36:04 -07006573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006575 Slog.e(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006576 "Input thread received uncaught exception: " + e, e);
6577 }
6578 }
6579 }
6580 }
6581
6582 // -------------------------------------------------------------
6583 // Client Session State
6584 // -------------------------------------------------------------
6585
6586 private final class Session extends IWindowSession.Stub
6587 implements IBinder.DeathRecipient {
6588 final IInputMethodClient mClient;
6589 final IInputContext mInputContext;
6590 final int mUid;
6591 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006592 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 SurfaceSession mSurfaceSession;
6594 int mNumWindow = 0;
6595 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 /**
6598 * Current pointer move event being dispatched to client window... must
6599 * hold key lock to access.
6600 */
6601 QueuedEvent mPendingPointerMove;
6602 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006604 /**
6605 * Current trackball move event being dispatched to client window... must
6606 * hold key lock to access.
6607 */
6608 QueuedEvent mPendingTrackballMove;
6609 WindowState mPendingTrackballWindow;
6610
6611 public Session(IInputMethodClient client, IInputContext inputContext) {
6612 mClient = client;
6613 mInputContext = inputContext;
6614 mUid = Binder.getCallingUid();
6615 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006616 StringBuilder sb = new StringBuilder();
6617 sb.append("Session{");
6618 sb.append(Integer.toHexString(System.identityHashCode(this)));
6619 sb.append(" uid ");
6620 sb.append(mUid);
6621 sb.append("}");
6622 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006624 synchronized (mWindowMap) {
6625 if (mInputMethodManager == null && mHaveInputMethods) {
6626 IBinder b = ServiceManager.getService(
6627 Context.INPUT_METHOD_SERVICE);
6628 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6629 }
6630 }
6631 long ident = Binder.clearCallingIdentity();
6632 try {
6633 // Note: it is safe to call in to the input method manager
6634 // here because we are not holding our lock.
6635 if (mInputMethodManager != null) {
6636 mInputMethodManager.addClient(client, inputContext,
6637 mUid, mPid);
6638 } else {
6639 client.setUsingInputMethod(false);
6640 }
6641 client.asBinder().linkToDeath(this, 0);
6642 } catch (RemoteException e) {
6643 // The caller has died, so we can just forget about this.
6644 try {
6645 if (mInputMethodManager != null) {
6646 mInputMethodManager.removeClient(client);
6647 }
6648 } catch (RemoteException ee) {
6649 }
6650 } finally {
6651 Binder.restoreCallingIdentity(ident);
6652 }
6653 }
Romain Guy06882f82009-06-10 13:36:04 -07006654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 @Override
6656 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6657 throws RemoteException {
6658 try {
6659 return super.onTransact(code, data, reply, flags);
6660 } catch (RuntimeException e) {
6661 // Log all 'real' exceptions thrown to the caller
6662 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006663 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006664 }
6665 throw e;
6666 }
6667 }
6668
6669 public void binderDied() {
6670 // Note: it is safe to call in to the input method manager
6671 // here because we are not holding our lock.
6672 try {
6673 if (mInputMethodManager != null) {
6674 mInputMethodManager.removeClient(mClient);
6675 }
6676 } catch (RemoteException e) {
6677 }
6678 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006679 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006680 mClientDead = true;
6681 killSessionLocked();
6682 }
6683 }
6684
6685 public int add(IWindow window, WindowManager.LayoutParams attrs,
6686 int viewVisibility, Rect outContentInsets) {
6687 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6688 }
Romain Guy06882f82009-06-10 13:36:04 -07006689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 public void remove(IWindow window) {
6691 removeWindow(this, window);
6692 }
Romain Guy06882f82009-06-10 13:36:04 -07006693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006694 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6695 int requestedWidth, int requestedHeight, int viewFlags,
6696 boolean insetsPending, Rect outFrame, Rect outContentInsets,
6697 Rect outVisibleInsets, Surface outSurface) {
6698 return relayoutWindow(this, window, attrs,
6699 requestedWidth, requestedHeight, viewFlags, insetsPending,
6700 outFrame, outContentInsets, outVisibleInsets, outSurface);
6701 }
Romain Guy06882f82009-06-10 13:36:04 -07006702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 public void setTransparentRegion(IWindow window, Region region) {
6704 setTransparentRegionWindow(this, window, region);
6705 }
Romain Guy06882f82009-06-10 13:36:04 -07006706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006707 public void setInsets(IWindow window, int touchableInsets,
6708 Rect contentInsets, Rect visibleInsets) {
6709 setInsetsWindow(this, window, touchableInsets, contentInsets,
6710 visibleInsets);
6711 }
Romain Guy06882f82009-06-10 13:36:04 -07006712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006713 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6714 getWindowDisplayFrame(this, window, outDisplayFrame);
6715 }
Romain Guy06882f82009-06-10 13:36:04 -07006716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006718 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006719 TAG, "IWindow finishDrawing called for " + window);
6720 finishDrawingWindow(this, window);
6721 }
6722
6723 public void finishKey(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006724 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 TAG, "IWindow finishKey called for " + window);
6726 mKeyWaiter.finishedKey(this, window, false,
6727 KeyWaiter.RETURN_NOTHING);
6728 }
6729
6730 public MotionEvent getPendingPointerMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006731 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 TAG, "IWindow getPendingMotionEvent called for " + window);
6733 return mKeyWaiter.finishedKey(this, window, false,
6734 KeyWaiter.RETURN_PENDING_POINTER);
6735 }
Romain Guy06882f82009-06-10 13:36:04 -07006736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 public MotionEvent getPendingTrackballMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006738 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006739 TAG, "IWindow getPendingMotionEvent called for " + window);
6740 return mKeyWaiter.finishedKey(this, window, false,
6741 KeyWaiter.RETURN_PENDING_TRACKBALL);
6742 }
6743
6744 public void setInTouchMode(boolean mode) {
6745 synchronized(mWindowMap) {
6746 mInTouchMode = mode;
6747 }
6748 }
6749
6750 public boolean getInTouchMode() {
6751 synchronized(mWindowMap) {
6752 return mInTouchMode;
6753 }
6754 }
6755
6756 public boolean performHapticFeedback(IWindow window, int effectId,
6757 boolean always) {
6758 synchronized(mWindowMap) {
6759 long ident = Binder.clearCallingIdentity();
6760 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006761 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006762 windowForClientLocked(this, window, true),
6763 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006764 } finally {
6765 Binder.restoreCallingIdentity(ident);
6766 }
6767 }
6768 }
Romain Guy06882f82009-06-10 13:36:04 -07006769
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006770 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006771 synchronized(mWindowMap) {
6772 long ident = Binder.clearCallingIdentity();
6773 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006774 setWindowWallpaperPositionLocked(
6775 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006776 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006777 } finally {
6778 Binder.restoreCallingIdentity(ident);
6779 }
6780 }
6781 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006782
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006783 public void wallpaperOffsetsComplete(IBinder window) {
6784 WindowManagerService.this.wallpaperOffsetsComplete(window);
6785 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006786
Dianne Hackborn75804932009-10-20 20:15:20 -07006787 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6788 int z, Bundle extras, boolean sync) {
6789 synchronized(mWindowMap) {
6790 long ident = Binder.clearCallingIdentity();
6791 try {
6792 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006793 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006794 action, x, y, z, extras, sync);
6795 } finally {
6796 Binder.restoreCallingIdentity(ident);
6797 }
6798 }
6799 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006800
Dianne Hackborn75804932009-10-20 20:15:20 -07006801 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6802 WindowManagerService.this.wallpaperCommandComplete(window, result);
6803 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006805 void windowAddedLocked() {
6806 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006807 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006808 TAG, "First window added to " + this + ", creating SurfaceSession");
6809 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006810 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006811 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 mSessions.add(this);
6813 }
6814 mNumWindow++;
6815 }
6816
6817 void windowRemovedLocked() {
6818 mNumWindow--;
6819 killSessionLocked();
6820 }
Romain Guy06882f82009-06-10 13:36:04 -07006821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006822 void killSessionLocked() {
6823 if (mNumWindow <= 0 && mClientDead) {
6824 mSessions.remove(this);
6825 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006826 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 TAG, "Last window removed from " + this
6828 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006829 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006830 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831 try {
6832 mSurfaceSession.kill();
6833 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006834 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006835 + mSurfaceSession + " in session " + this
6836 + ": " + e.toString());
6837 }
6838 mSurfaceSession = null;
6839 }
6840 }
6841 }
Romain Guy06882f82009-06-10 13:36:04 -07006842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006844 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6845 pw.print(" mClientDead="); pw.print(mClientDead);
6846 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6847 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6848 pw.print(prefix);
6849 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6850 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6851 }
6852 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6853 pw.print(prefix);
6854 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6855 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6856 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 }
6858
6859 @Override
6860 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006861 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862 }
6863 }
6864
6865 // -------------------------------------------------------------
6866 // Client Window State
6867 // -------------------------------------------------------------
6868
6869 private final class WindowState implements WindowManagerPolicy.WindowState {
6870 final Session mSession;
6871 final IWindow mClient;
6872 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006873 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006874 AppWindowToken mAppToken;
6875 AppWindowToken mTargetAppToken;
6876 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6877 final DeathRecipient mDeathRecipient;
6878 final WindowState mAttachedWindow;
6879 final ArrayList mChildWindows = new ArrayList();
6880 final int mBaseLayer;
6881 final int mSubLayer;
6882 final boolean mLayoutAttached;
6883 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006884 final boolean mIsWallpaper;
6885 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006886 int mViewVisibility;
6887 boolean mPolicyVisibility = true;
6888 boolean mPolicyVisibilityAfterAnim = true;
6889 boolean mAppFreezing;
6890 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006891 boolean mReportDestroySurface;
6892 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 boolean mAttachedHidden; // is our parent window hidden?
6894 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006895 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006896 int mRequestedWidth;
6897 int mRequestedHeight;
6898 int mLastRequestedWidth;
6899 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006900 int mLayer;
6901 int mAnimLayer;
6902 int mLastLayer;
6903 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006904 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006905 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006906
6907 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006908
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006909 int mLayoutSeq = -1;
6910
6911 Configuration mConfiguration = null;
6912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006913 // Actual frame shown on-screen (may be modified by animation)
6914 final Rect mShownFrame = new Rect();
6915 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006917 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006918 * Set when we have changed the size of the surface, to know that
6919 * we must tell them application to resize (and thus redraw itself).
6920 */
6921 boolean mSurfaceResized;
6922
6923 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006924 * Insets that determine the actually visible area
6925 */
6926 final Rect mVisibleInsets = new Rect();
6927 final Rect mLastVisibleInsets = new Rect();
6928 boolean mVisibleInsetsChanged;
6929
6930 /**
6931 * Insets that are covered by system windows
6932 */
6933 final Rect mContentInsets = new Rect();
6934 final Rect mLastContentInsets = new Rect();
6935 boolean mContentInsetsChanged;
6936
6937 /**
6938 * Set to true if we are waiting for this window to receive its
6939 * given internal insets before laying out other windows based on it.
6940 */
6941 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006943 /**
6944 * These are the content insets that were given during layout for
6945 * this window, to be applied to windows behind it.
6946 */
6947 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 /**
6950 * These are the visible insets that were given during layout for
6951 * this window, to be applied to windows behind it.
6952 */
6953 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 /**
6956 * Flag indicating whether the touchable region should be adjusted by
6957 * the visible insets; if false the area outside the visible insets is
6958 * NOT touchable, so we must use those to adjust the frame during hit
6959 * tests.
6960 */
6961 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 // Current transformation being applied.
6964 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6965 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6966 float mHScale=1, mVScale=1;
6967 float mLastHScale=1, mLastVScale=1;
6968 final Matrix mTmpMatrix = new Matrix();
6969
6970 // "Real" frame that the application sees.
6971 final Rect mFrame = new Rect();
6972 final Rect mLastFrame = new Rect();
6973
6974 final Rect mContainingFrame = new Rect();
6975 final Rect mDisplayFrame = new Rect();
6976 final Rect mContentFrame = new Rect();
6977 final Rect mVisibleFrame = new Rect();
6978
6979 float mShownAlpha = 1;
6980 float mAlpha = 1;
6981 float mLastAlpha = 1;
6982
6983 // Set to true if, when the window gets displayed, it should perform
6984 // an enter animation.
6985 boolean mEnterAnimationPending;
6986
6987 // Currently running animation.
6988 boolean mAnimating;
6989 boolean mLocalAnimating;
6990 Animation mAnimation;
6991 boolean mAnimationIsEntrance;
6992 boolean mHasTransformation;
6993 boolean mHasLocalTransformation;
6994 final Transformation mTransformation = new Transformation();
6995
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006996 // If a window showing a wallpaper: the requested offset for the
6997 // wallpaper; if a wallpaper window: the currently applied offset.
6998 float mWallpaperX = -1;
6999 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007000
7001 // If a window showing a wallpaper: what fraction of the offset
7002 // range corresponds to a full virtual screen.
7003 float mWallpaperXStep = -1;
7004 float mWallpaperYStep = -1;
7005
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007006 // Wallpaper windows: pixels offset based on above variables.
7007 int mXOffset;
7008 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007010 // This is set after IWindowSession.relayout() has been called at
7011 // least once for the window. It allows us to detect the situation
7012 // where we don't yet have a surface, but should have one soon, so
7013 // we can give the window focus before waiting for the relayout.
7014 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007016 // This is set after the Surface has been created but before the
7017 // window has been drawn. During this time the surface is hidden.
7018 boolean mDrawPending;
7019
7020 // This is set after the window has finished drawing for the first
7021 // time but before its surface is shown. The surface will be
7022 // displayed when the next layout is run.
7023 boolean mCommitDrawPending;
7024
7025 // This is set during the time after the window's drawing has been
7026 // committed, and before its surface is actually shown. It is used
7027 // to delay showing the surface until all windows in a token are ready
7028 // to be shown.
7029 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007031 // Set when the window has been shown in the screen the first time.
7032 boolean mHasDrawn;
7033
7034 // Currently running an exit animation?
7035 boolean mExiting;
7036
7037 // Currently on the mDestroySurface list?
7038 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007040 // Completely remove from window manager after exit animation?
7041 boolean mRemoveOnExit;
7042
7043 // Set when the orientation is changing and this window has not yet
7044 // been updated for the new orientation.
7045 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007047 // Is this window now (or just being) removed?
7048 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007050 WindowState(Session s, IWindow c, WindowToken token,
7051 WindowState attachedWindow, WindowManager.LayoutParams a,
7052 int viewVisibility) {
7053 mSession = s;
7054 mClient = c;
7055 mToken = token;
7056 mAttrs.copyFrom(a);
7057 mViewVisibility = viewVisibility;
7058 DeathRecipient deathRecipient = new DeathRecipient();
7059 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007060 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 TAG, "Window " + this + " client=" + c.asBinder()
7062 + " token=" + token + " (" + mAttrs.token + ")");
7063 try {
7064 c.asBinder().linkToDeath(deathRecipient, 0);
7065 } catch (RemoteException e) {
7066 mDeathRecipient = null;
7067 mAttachedWindow = null;
7068 mLayoutAttached = false;
7069 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007070 mIsWallpaper = false;
7071 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 mBaseLayer = 0;
7073 mSubLayer = 0;
7074 return;
7075 }
7076 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007078 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7079 mAttrs.type <= LAST_SUB_WINDOW)) {
7080 // The multiplier here is to reserve space for multiple
7081 // windows in the same type layer.
7082 mBaseLayer = mPolicy.windowTypeToLayerLw(
7083 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7084 + TYPE_LAYER_OFFSET;
7085 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7086 mAttachedWindow = attachedWindow;
7087 mAttachedWindow.mChildWindows.add(this);
7088 mLayoutAttached = mAttrs.type !=
7089 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7090 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7091 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007092 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7093 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 } else {
7095 // The multiplier here is to reserve space for multiple
7096 // windows in the same type layer.
7097 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7098 * TYPE_LAYER_MULTIPLIER
7099 + TYPE_LAYER_OFFSET;
7100 mSubLayer = 0;
7101 mAttachedWindow = null;
7102 mLayoutAttached = false;
7103 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7104 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007105 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7106 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007107 }
7108
7109 WindowState appWin = this;
7110 while (appWin.mAttachedWindow != null) {
7111 appWin = mAttachedWindow;
7112 }
7113 WindowToken appToken = appWin.mToken;
7114 while (appToken.appWindowToken == null) {
7115 WindowToken parent = mTokenMap.get(appToken.token);
7116 if (parent == null || appToken == parent) {
7117 break;
7118 }
7119 appToken = parent;
7120 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007121 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007122 mAppToken = appToken.appWindowToken;
7123
7124 mSurface = null;
7125 mRequestedWidth = 0;
7126 mRequestedHeight = 0;
7127 mLastRequestedWidth = 0;
7128 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007129 mXOffset = 0;
7130 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007131 mLayer = 0;
7132 mAnimLayer = 0;
7133 mLastLayer = 0;
7134 }
7135
7136 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007137 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007138 TAG, "Attaching " + this + " token=" + mToken
7139 + ", list=" + mToken.windows);
7140 mSession.windowAddedLocked();
7141 }
7142
7143 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7144 mHaveFrame = true;
7145
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007146 final Rect container = mContainingFrame;
7147 container.set(pf);
7148
7149 final Rect display = mDisplayFrame;
7150 display.set(df);
7151
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007152 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007153 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007154 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7155 display.intersect(mCompatibleScreenFrame);
7156 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007157 }
7158
7159 final int pw = container.right - container.left;
7160 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007161
7162 int w,h;
7163 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7164 w = mAttrs.width < 0 ? pw : mAttrs.width;
7165 h = mAttrs.height< 0 ? ph : mAttrs.height;
7166 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007167 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7168 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007169 }
Romain Guy06882f82009-06-10 13:36:04 -07007170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007171 final Rect content = mContentFrame;
7172 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007174 final Rect visible = mVisibleFrame;
7175 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007177 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007178 final int fw = frame.width();
7179 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007181 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7182 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7183
7184 Gravity.apply(mAttrs.gravity, w, h, container,
7185 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7186 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7187
7188 //System.out.println("Out: " + mFrame);
7189
7190 // Now make sure the window fits in the overall display.
7191 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 // Make sure the content and visible frames are inside of the
7194 // final window frame.
7195 if (content.left < frame.left) content.left = frame.left;
7196 if (content.top < frame.top) content.top = frame.top;
7197 if (content.right > frame.right) content.right = frame.right;
7198 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7199 if (visible.left < frame.left) visible.left = frame.left;
7200 if (visible.top < frame.top) visible.top = frame.top;
7201 if (visible.right > frame.right) visible.right = frame.right;
7202 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007204 final Rect contentInsets = mContentInsets;
7205 contentInsets.left = content.left-frame.left;
7206 contentInsets.top = content.top-frame.top;
7207 contentInsets.right = frame.right-content.right;
7208 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 final Rect visibleInsets = mVisibleInsets;
7211 visibleInsets.left = visible.left-frame.left;
7212 visibleInsets.top = visible.top-frame.top;
7213 visibleInsets.right = frame.right-visible.right;
7214 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007215
Dianne Hackborn284ac932009-08-28 10:34:25 -07007216 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7217 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007218 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007219 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007221 if (localLOGV) {
7222 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7223 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007224 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007225 + mRequestedWidth + ", mRequestedheight="
7226 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7227 + "): frame=" + mFrame.toShortString()
7228 + " ci=" + contentInsets.toShortString()
7229 + " vi=" + visibleInsets.toShortString());
7230 //}
7231 }
7232 }
Romain Guy06882f82009-06-10 13:36:04 -07007233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007234 public Rect getFrameLw() {
7235 return mFrame;
7236 }
7237
7238 public Rect getShownFrameLw() {
7239 return mShownFrame;
7240 }
7241
7242 public Rect getDisplayFrameLw() {
7243 return mDisplayFrame;
7244 }
7245
7246 public Rect getContentFrameLw() {
7247 return mContentFrame;
7248 }
7249
7250 public Rect getVisibleFrameLw() {
7251 return mVisibleFrame;
7252 }
7253
7254 public boolean getGivenInsetsPendingLw() {
7255 return mGivenInsetsPending;
7256 }
7257
7258 public Rect getGivenContentInsetsLw() {
7259 return mGivenContentInsets;
7260 }
Romain Guy06882f82009-06-10 13:36:04 -07007261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 public Rect getGivenVisibleInsetsLw() {
7263 return mGivenVisibleInsets;
7264 }
Romain Guy06882f82009-06-10 13:36:04 -07007265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007266 public WindowManager.LayoutParams getAttrs() {
7267 return mAttrs;
7268 }
7269
7270 public int getSurfaceLayer() {
7271 return mLayer;
7272 }
Romain Guy06882f82009-06-10 13:36:04 -07007273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007274 public IApplicationToken getAppToken() {
7275 return mAppToken != null ? mAppToken.appToken : null;
7276 }
7277
7278 public boolean hasAppShownWindows() {
7279 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7280 }
7281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007282 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007283 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 TAG, "Setting animation in " + this + ": " + anim);
7285 mAnimating = false;
7286 mLocalAnimating = false;
7287 mAnimation = anim;
7288 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7289 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7290 }
7291
7292 public void clearAnimation() {
7293 if (mAnimation != null) {
7294 mAnimating = true;
7295 mLocalAnimating = false;
7296 mAnimation = null;
7297 }
7298 }
Romain Guy06882f82009-06-10 13:36:04 -07007299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 Surface createSurfaceLocked() {
7301 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007302 mReportDestroySurface = false;
7303 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 mDrawPending = true;
7305 mCommitDrawPending = false;
7306 mReadyToShow = false;
7307 if (mAppToken != null) {
7308 mAppToken.allDrawn = false;
7309 }
7310
7311 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007312 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007313 flags |= Surface.PUSH_BUFFERS;
7314 }
7315
7316 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7317 flags |= Surface.SECURE;
7318 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007319 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007320 TAG, "Creating surface in session "
7321 + mSession.mSurfaceSession + " window " + this
7322 + " w=" + mFrame.width()
7323 + " h=" + mFrame.height() + " format="
7324 + mAttrs.format + " flags=" + flags);
7325
7326 int w = mFrame.width();
7327 int h = mFrame.height();
7328 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7329 // for a scaled surface, we always want the requested
7330 // size.
7331 w = mRequestedWidth;
7332 h = mRequestedHeight;
7333 }
7334
Romain Guy9825ec62009-10-01 00:58:09 -07007335 // Something is wrong and SurfaceFlinger will not like this,
7336 // try to revert to sane values
7337 if (w <= 0) w = 1;
7338 if (h <= 0) h = 1;
7339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 try {
7341 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007342 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007343 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007345 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007346 + mSurface + " IN SESSION "
7347 + mSession.mSurfaceSession
7348 + ": pid=" + mSession.mPid + " format="
7349 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007350 + Integer.toHexString(flags)
7351 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007353 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 reclaimSomeSurfaceMemoryLocked(this, "create");
7355 return null;
7356 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007357 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007358 return null;
7359 }
Romain Guy06882f82009-06-10 13:36:04 -07007360
Joe Onorato8a9b2202010-02-26 18:56:32 -08007361 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 TAG, "Got surface: " + mSurface
7363 + ", set left=" + mFrame.left + " top=" + mFrame.top
7364 + ", animLayer=" + mAnimLayer);
7365 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007366 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007367 if (SHOW_TRANSACTIONS) logSurface(this,
7368 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7369 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7370 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007371 }
7372 Surface.openTransaction();
7373 try {
7374 try {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007375 mSurface.setPosition(mFrame.left + mXOffset,
7376 mFrame.top + mYOffset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007377 mSurface.setLayer(mAnimLayer);
7378 mSurface.hide();
7379 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007380 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007381 mSurface.setFlags(Surface.SURFACE_DITHER,
7382 Surface.SURFACE_DITHER);
7383 }
7384 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007385 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7387 }
7388 mLastHidden = true;
7389 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007390 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007391 Surface.closeTransaction();
7392 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007393 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007394 TAG, "Created surface " + this);
7395 }
7396 return mSurface;
7397 }
Romain Guy06882f82009-06-10 13:36:04 -07007398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 void destroySurfaceLocked() {
7400 // Window is no longer on-screen, so can no longer receive
7401 // key events... if we were waiting for it to finish
7402 // handling a key event, the wait is over!
7403 mKeyWaiter.finishedKey(mSession, mClient, true,
7404 KeyWaiter.RETURN_NOTHING);
7405 mKeyWaiter.releasePendingPointerLocked(mSession);
7406 mKeyWaiter.releasePendingTrackballLocked(mSession);
7407
7408 if (mAppToken != null && this == mAppToken.startingWindow) {
7409 mAppToken.startingDisplayed = false;
7410 }
Romain Guy06882f82009-06-10 13:36:04 -07007411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007413 mDrawPending = false;
7414 mCommitDrawPending = false;
7415 mReadyToShow = false;
7416
7417 int i = mChildWindows.size();
7418 while (i > 0) {
7419 i--;
7420 WindowState c = (WindowState)mChildWindows.get(i);
7421 c.mAttachedHidden = true;
7422 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007423
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007424 if (mReportDestroySurface) {
7425 mReportDestroySurface = false;
7426 mSurfacePendingDestroy = true;
7427 try {
7428 mClient.dispatchGetNewSurface();
7429 // We'll really destroy on the next time around.
7430 return;
7431 } catch (RemoteException e) {
7432 }
7433 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007436 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007437 RuntimeException e = null;
7438 if (!HIDE_STACK_CRAWLS) {
7439 e = new RuntimeException();
7440 e.fillInStackTrace();
7441 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007442 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007443 + mSurface + ", session " + mSession, e);
7444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007446 RuntimeException e = null;
7447 if (!HIDE_STACK_CRAWLS) {
7448 e = new RuntimeException();
7449 e.fillInStackTrace();
7450 }
7451 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007453 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007455 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 + " surface " + mSurface + " session " + mSession
7457 + ": " + e.toString());
7458 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 }
7462 }
7463
7464 boolean finishDrawingLocked() {
7465 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007466 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 TAG, "finishDrawingLocked: " + mSurface);
7468 mCommitDrawPending = true;
7469 mDrawPending = false;
7470 return true;
7471 }
7472 return false;
7473 }
7474
7475 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007476 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007477 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007479 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 }
7481 mCommitDrawPending = false;
7482 mReadyToShow = true;
7483 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7484 final AppWindowToken atoken = mAppToken;
7485 if (atoken == null || atoken.allDrawn || starting) {
7486 performShowLocked();
7487 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007488 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007489 }
7490
7491 // This must be called while inside a transaction.
7492 boolean performShowLocked() {
7493 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007494 RuntimeException e = null;
7495 if (!HIDE_STACK_CRAWLS) {
7496 e = new RuntimeException();
7497 e.fillInStackTrace();
7498 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007499 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7501 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7502 }
7503 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007504 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7505 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007506 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 + " during animation: policyVis=" + mPolicyVisibility
7508 + " attHidden=" + mAttachedHidden
7509 + " tok.hiddenRequested="
7510 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007511 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 + (mAppToken != null ? mAppToken.hidden : false)
7513 + " animating=" + mAnimating
7514 + " tok animating="
7515 + (mAppToken != null ? mAppToken.animating : false));
7516 if (!showSurfaceRobustlyLocked(this)) {
7517 return false;
7518 }
7519 mLastAlpha = -1;
7520 mHasDrawn = true;
7521 mLastHidden = false;
7522 mReadyToShow = false;
7523 enableScreenIfNeededLocked();
7524
7525 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 int i = mChildWindows.size();
7528 while (i > 0) {
7529 i--;
7530 WindowState c = (WindowState)mChildWindows.get(i);
7531 if (c.mSurface != null && c.mAttachedHidden) {
7532 c.mAttachedHidden = false;
7533 c.performShowLocked();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007534 // It hadn't been shown, which means layout not
7535 // performed on it, so now we want to make sure to
7536 // do a layout. If called from within the transaction
7537 // loop, this will cause it to restart with a new
7538 // layout.
7539 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 }
7541 }
Romain Guy06882f82009-06-10 13:36:04 -07007542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 if (mAttrs.type != TYPE_APPLICATION_STARTING
7544 && mAppToken != null) {
7545 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007546
Dianne Hackborn248b1882009-09-16 16:46:44 -07007547 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007548 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007549 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007551 // If this initial window is animating, stop it -- we
7552 // will do an animation to reveal it from behind the
7553 // starting window, so there is no need for it to also
7554 // be doing its own stuff.
7555 if (mAnimation != null) {
7556 mAnimation = null;
7557 // Make sure we clean up the animation.
7558 mAnimating = true;
7559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007560 mFinishedStarting.add(mAppToken);
7561 mH.sendEmptyMessage(H.FINISHED_STARTING);
7562 }
7563 mAppToken.updateReportedVisibilityLocked();
7564 }
7565 }
7566 return true;
7567 }
Romain Guy06882f82009-06-10 13:36:04 -07007568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 // This must be called while inside a transaction. Returns true if
7570 // there is more animation to run.
7571 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007572 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7576 mHasTransformation = true;
7577 mHasLocalTransformation = true;
7578 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007579 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 TAG, "Starting animation in " + this +
7581 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7582 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7583 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7584 mAnimation.setStartTime(currentTime);
7585 mLocalAnimating = true;
7586 mAnimating = true;
7587 }
7588 mTransformation.clear();
7589 final boolean more = mAnimation.getTransformation(
7590 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007591 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 TAG, "Stepped animation in " + this +
7593 ": more=" + more + ", xform=" + mTransformation);
7594 if (more) {
7595 // we're not done!
7596 return true;
7597 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007598 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 TAG, "Finished animation in " + this +
7600 " @ " + currentTime);
7601 mAnimation = null;
7602 //WindowManagerService.this.dump();
7603 }
7604 mHasLocalTransformation = false;
7605 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007606 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 // When our app token is animating, we kind-of pretend like
7608 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7609 // part of this check means that we will only do this if
7610 // our window is not currently exiting, or it is not
7611 // locally animating itself. The idea being that one that
7612 // is exiting and doing a local animation should be removed
7613 // once that animation is done.
7614 mAnimating = true;
7615 mHasTransformation = true;
7616 mTransformation.clear();
7617 return false;
7618 } else if (mHasTransformation) {
7619 // Little trick to get through the path below to act like
7620 // we have finished an animation.
7621 mAnimating = true;
7622 } else if (isAnimating()) {
7623 mAnimating = true;
7624 }
7625 } else if (mAnimation != null) {
7626 // If the display is frozen, and there is a pending animation,
7627 // clear it and make sure we run the cleanup code.
7628 mAnimating = true;
7629 mLocalAnimating = true;
7630 mAnimation = null;
7631 }
Romain Guy06882f82009-06-10 13:36:04 -07007632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007633 if (!mAnimating && !mLocalAnimating) {
7634 return false;
7635 }
7636
Joe Onorato8a9b2202010-02-26 18:56:32 -08007637 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 TAG, "Animation done in " + this + ": exiting=" + mExiting
7639 + ", reportedVisible="
7640 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007642 mAnimating = false;
7643 mLocalAnimating = false;
7644 mAnimation = null;
7645 mAnimLayer = mLayer;
7646 if (mIsImWindow) {
7647 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007648 } else if (mIsWallpaper) {
7649 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007650 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007651 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007652 + " anim layer: " + mAnimLayer);
7653 mHasTransformation = false;
7654 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007655 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7656 if (DEBUG_VISIBILITY) {
7657 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7658 + mPolicyVisibilityAfterAnim);
7659 }
7660 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7661 if (!mPolicyVisibility) {
7662 if (mCurrentFocus == this) {
7663 mFocusMayChange = true;
7664 }
7665 // Window is no longer visible -- make sure if we were waiting
7666 // for it to be displayed before enabling the display, that
7667 // we allow the display to be enabled now.
7668 enableScreenIfNeededLocked();
7669 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007671 mTransformation.clear();
7672 if (mHasDrawn
7673 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7674 && mAppToken != null
7675 && mAppToken.firstWindowDrawn
7676 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007677 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 + mToken + ": first real window done animating");
7679 mFinishedStarting.add(mAppToken);
7680 mH.sendEmptyMessage(H.FINISHED_STARTING);
7681 }
Romain Guy06882f82009-06-10 13:36:04 -07007682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007683 finishExit();
7684
7685 if (mAppToken != null) {
7686 mAppToken.updateReportedVisibilityLocked();
7687 }
7688
7689 return false;
7690 }
7691
7692 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007693 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 TAG, "finishExit in " + this
7695 + ": exiting=" + mExiting
7696 + " remove=" + mRemoveOnExit
7697 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007699 final int N = mChildWindows.size();
7700 for (int i=0; i<N; i++) {
7701 ((WindowState)mChildWindows.get(i)).finishExit();
7702 }
Romain Guy06882f82009-06-10 13:36:04 -07007703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 if (!mExiting) {
7705 return;
7706 }
Romain Guy06882f82009-06-10 13:36:04 -07007707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708 if (isWindowAnimating()) {
7709 return;
7710 }
7711
Joe Onorato8a9b2202010-02-26 18:56:32 -08007712 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007713 TAG, "Exit animation finished in " + this
7714 + ": remove=" + mRemoveOnExit);
7715 if (mSurface != null) {
7716 mDestroySurface.add(this);
7717 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007718 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007719 try {
7720 mSurface.hide();
7721 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007722 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007723 }
7724 mLastHidden = true;
7725 mKeyWaiter.releasePendingPointerLocked(mSession);
7726 }
7727 mExiting = false;
7728 if (mRemoveOnExit) {
7729 mPendingRemove.add(this);
7730 mRemoveOnExit = false;
7731 }
7732 }
Romain Guy06882f82009-06-10 13:36:04 -07007733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007734 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7735 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7736 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7737 if (dtdx < -.000001f || dtdx > .000001f) return false;
7738 if (dsdy < -.000001f || dsdy > .000001f) return false;
7739 return true;
7740 }
Romain Guy06882f82009-06-10 13:36:04 -07007741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007742 void computeShownFrameLocked() {
7743 final boolean selfTransformation = mHasLocalTransformation;
7744 Transformation attachedTransformation =
7745 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7746 ? mAttachedWindow.mTransformation : null;
7747 Transformation appTransformation =
7748 (mAppToken != null && mAppToken.hasTransformation)
7749 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007750
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007751 // Wallpapers are animated based on the "real" window they
7752 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007753 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007754 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007755 if (mWallpaperTarget.mHasLocalTransformation &&
7756 mWallpaperTarget.mAnimation != null &&
7757 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007758 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007759 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007760 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007761 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007762 }
7763 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007764 mWallpaperTarget.mAppToken.hasTransformation &&
7765 mWallpaperTarget.mAppToken.animation != null &&
7766 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007767 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007768 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007769 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007770 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007771 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007772 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 if (selfTransformation || attachedTransformation != null
7775 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007776 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 final Rect frame = mFrame;
7778 final float tmpFloats[] = mTmpFloats;
7779 final Matrix tmpMatrix = mTmpMatrix;
7780
7781 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007782 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007784 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007785 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007786 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007787 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007788 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007789 }
7790 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007791 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007792 }
7793
7794 // "convert" it into SurfaceFlinger's format
7795 // (a 2x2 matrix + an offset)
7796 // Here we must not transform the position of the surface
7797 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007798 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007800 tmpMatrix.getValues(tmpFloats);
7801 mDsDx = tmpFloats[Matrix.MSCALE_X];
7802 mDtDx = tmpFloats[Matrix.MSKEW_X];
7803 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7804 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007805 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7806 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 int w = frame.width();
7808 int h = frame.height();
7809 mShownFrame.set(x, y, x+w, y+h);
7810
7811 // Now set the alpha... but because our current hardware
7812 // can't do alpha transformation on a non-opaque surface,
7813 // turn it off if we are running an animation that is also
7814 // transforming since it is more important to have that
7815 // animation be smooth.
7816 mShownAlpha = mAlpha;
7817 if (!mLimitedAlphaCompositing
7818 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7819 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7820 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007821 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007822 if (selfTransformation) {
7823 mShownAlpha *= mTransformation.getAlpha();
7824 }
7825 if (attachedTransformation != null) {
7826 mShownAlpha *= attachedTransformation.getAlpha();
7827 }
7828 if (appTransformation != null) {
7829 mShownAlpha *= appTransformation.getAlpha();
7830 }
7831 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007832 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 }
Romain Guy06882f82009-06-10 13:36:04 -07007834
Joe Onorato8a9b2202010-02-26 18:56:32 -08007835 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007836 TAG, "Continuing animation in " + this +
7837 ": " + mShownFrame +
7838 ", alpha=" + mTransformation.getAlpha());
7839 return;
7840 }
Romain Guy06882f82009-06-10 13:36:04 -07007841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007843 if (mXOffset != 0 || mYOffset != 0) {
7844 mShownFrame.offset(mXOffset, mYOffset);
7845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007846 mShownAlpha = mAlpha;
7847 mDsDx = 1;
7848 mDtDx = 0;
7849 mDsDy = 0;
7850 mDtDy = 1;
7851 }
Romain Guy06882f82009-06-10 13:36:04 -07007852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007853 /**
7854 * Is this window visible? It is not visible if there is no
7855 * surface, or we are in the process of running an exit animation
7856 * that will remove the surface, or its app token has been hidden.
7857 */
7858 public boolean isVisibleLw() {
7859 final AppWindowToken atoken = mAppToken;
7860 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7861 && (atoken == null || !atoken.hiddenRequested)
7862 && !mExiting && !mDestroying;
7863 }
7864
7865 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007866 * Like {@link #isVisibleLw}, but also counts a window that is currently
7867 * "hidden" behind the keyguard as visible. This allows us to apply
7868 * things like window flags that impact the keyguard.
7869 * XXX I am starting to think we need to have ANOTHER visibility flag
7870 * for this "hidden behind keyguard" state rather than overloading
7871 * mPolicyVisibility. Ungh.
7872 */
7873 public boolean isVisibleOrBehindKeyguardLw() {
7874 final AppWindowToken atoken = mAppToken;
7875 return mSurface != null && !mAttachedHidden
7876 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007877 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007878 && !mExiting && !mDestroying;
7879 }
7880
7881 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007882 * Is this window visible, ignoring its app token? It is not visible
7883 * if there is no surface, or we are in the process of running an exit animation
7884 * that will remove the surface.
7885 */
7886 public boolean isWinVisibleLw() {
7887 final AppWindowToken atoken = mAppToken;
7888 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7889 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7890 && !mExiting && !mDestroying;
7891 }
7892
7893 /**
7894 * The same as isVisible(), but follows the current hidden state of
7895 * the associated app token, not the pending requested hidden state.
7896 */
7897 boolean isVisibleNow() {
7898 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007899 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007900 }
7901
7902 /**
7903 * Same as isVisible(), but we also count it as visible between the
7904 * call to IWindowSession.add() and the first relayout().
7905 */
7906 boolean isVisibleOrAdding() {
7907 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007908 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007909 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7910 && mPolicyVisibility && !mAttachedHidden
7911 && (atoken == null || !atoken.hiddenRequested)
7912 && !mExiting && !mDestroying;
7913 }
7914
7915 /**
7916 * Is this window currently on-screen? It is on-screen either if it
7917 * is visible or it is currently running an animation before no longer
7918 * being visible.
7919 */
7920 boolean isOnScreen() {
7921 final AppWindowToken atoken = mAppToken;
7922 if (atoken != null) {
7923 return mSurface != null && mPolicyVisibility && !mDestroying
7924 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007925 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007926 } else {
7927 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007928 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 }
7930 }
Romain Guy06882f82009-06-10 13:36:04 -07007931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 /**
7933 * Like isOnScreen(), but we don't return true if the window is part
7934 * of a transition that has not yet been started.
7935 */
7936 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007937 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007938 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007939 return false;
7940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007941 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007942 final boolean animating = atoken != null
7943 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007944 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007945 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7946 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007947 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007948 }
7949
7950 /** Is the window or its container currently animating? */
7951 boolean isAnimating() {
7952 final WindowState attached = mAttachedWindow;
7953 final AppWindowToken atoken = mAppToken;
7954 return mAnimation != null
7955 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007956 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007957 (atoken.animation != null
7958 || atoken.inPendingTransaction));
7959 }
7960
7961 /** Is this window currently animating? */
7962 boolean isWindowAnimating() {
7963 return mAnimation != null;
7964 }
7965
7966 /**
7967 * Like isOnScreen, but returns false if the surface hasn't yet
7968 * been drawn.
7969 */
7970 public boolean isDisplayedLw() {
7971 final AppWindowToken atoken = mAppToken;
7972 return mSurface != null && mPolicyVisibility && !mDestroying
7973 && !mDrawPending && !mCommitDrawPending
7974 && ((!mAttachedHidden &&
7975 (atoken == null || !atoken.hiddenRequested))
7976 || mAnimating);
7977 }
7978
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007979 /**
7980 * Returns true if the window has a surface that it has drawn a
7981 * complete UI in to.
7982 */
7983 public boolean isDrawnLw() {
7984 final AppWindowToken atoken = mAppToken;
7985 return mSurface != null && !mDestroying
7986 && !mDrawPending && !mCommitDrawPending;
7987 }
7988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007989 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7990 boolean shownFrame, boolean onlyOpaque) {
7991 if (mSurface == null) {
7992 return false;
7993 }
7994 if (mAppToken != null && !mAppToken.appFullscreen) {
7995 return false;
7996 }
7997 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7998 return false;
7999 }
8000 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008001
8002 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
8003 return frame.left <= mCompatibleScreenFrame.left &&
8004 frame.top <= mCompatibleScreenFrame.top &&
8005 frame.right >= mCompatibleScreenFrame.right &&
8006 frame.bottom >= mCompatibleScreenFrame.bottom;
8007 } else {
8008 return frame.left <= 0 && frame.top <= 0
8009 && frame.right >= screenWidth
8010 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008012 }
Romain Guy06882f82009-06-10 13:36:04 -07008013
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008014 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008015 * Return true if the window is opaque and fully drawn. This indicates
8016 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008017 */
8018 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008019 return (mAttrs.format == PixelFormat.OPAQUE
8020 || mAttrs.type == TYPE_WALLPAPER)
8021 && mSurface != null && mAnimation == null
8022 && (mAppToken == null || mAppToken.animation == null)
8023 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008024 }
8025
8026 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8027 return
8028 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008029 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8030 // only if it's visible
8031 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008032 // and only if the application fills the compatible screen
8033 mFrame.left <= mCompatibleScreenFrame.left &&
8034 mFrame.top <= mCompatibleScreenFrame.top &&
8035 mFrame.right >= mCompatibleScreenFrame.right &&
8036 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008037 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008038 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008039 }
8040
8041 boolean isFullscreen(int screenWidth, int screenHeight) {
8042 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008043 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008044 }
8045
8046 void removeLocked() {
8047 if (mAttachedWindow != null) {
8048 mAttachedWindow.mChildWindows.remove(this);
8049 }
8050 destroySurfaceLocked();
8051 mSession.windowRemovedLocked();
8052 try {
8053 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8054 } catch (RuntimeException e) {
8055 // Ignore if it has already been removed (usually because
8056 // we are doing this as part of processing a death note.)
8057 }
8058 }
8059
8060 private class DeathRecipient implements IBinder.DeathRecipient {
8061 public void binderDied() {
8062 try {
8063 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008064 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008065 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008066 if (win != null) {
8067 removeWindowLocked(mSession, win);
8068 }
8069 }
8070 } catch (IllegalArgumentException ex) {
8071 // This will happen if the window has already been
8072 // removed.
8073 }
8074 }
8075 }
8076
8077 /** Returns true if this window desires key events. */
8078 public final boolean canReceiveKeys() {
8079 return isVisibleOrAdding()
8080 && (mViewVisibility == View.VISIBLE)
8081 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8082 }
8083
8084 public boolean hasDrawnLw() {
8085 return mHasDrawn;
8086 }
8087
8088 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008089 return showLw(doAnimation, true);
8090 }
8091
8092 boolean showLw(boolean doAnimation, boolean requestAnim) {
8093 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8094 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008095 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008096 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008097 if (doAnimation) {
8098 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8099 + mPolicyVisibility + " mAnimation=" + mAnimation);
8100 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8101 doAnimation = false;
8102 } else if (mPolicyVisibility && mAnimation == null) {
8103 // Check for the case where we are currently visible and
8104 // not animating; we do not want to do animation at such a
8105 // point to become visible when we already are.
8106 doAnimation = false;
8107 }
8108 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008109 mPolicyVisibility = true;
8110 mPolicyVisibilityAfterAnim = true;
8111 if (doAnimation) {
8112 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8113 }
8114 if (requestAnim) {
8115 requestAnimationLocked(0);
8116 }
8117 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008118 }
8119
8120 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008121 return hideLw(doAnimation, true);
8122 }
8123
8124 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008125 if (doAnimation) {
8126 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8127 doAnimation = false;
8128 }
8129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008130 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8131 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008132 if (!current) {
8133 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008135 if (doAnimation) {
8136 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8137 if (mAnimation == null) {
8138 doAnimation = false;
8139 }
8140 }
8141 if (doAnimation) {
8142 mPolicyVisibilityAfterAnim = false;
8143 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008144 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008145 mPolicyVisibilityAfterAnim = false;
8146 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008147 // Window is no longer visible -- make sure if we were waiting
8148 // for it to be displayed before enabling the display, that
8149 // we allow the display to be enabled now.
8150 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008151 if (mCurrentFocus == this) {
8152 mFocusMayChange = true;
8153 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008154 }
8155 if (requestAnim) {
8156 requestAnimationLocked(0);
8157 }
8158 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 }
8160
8161 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008162 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8163 pw.print(" mClient="); pw.println(mClient.asBinder());
8164 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8165 if (mAttachedWindow != null || mLayoutAttached) {
8166 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8167 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8168 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008169 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8170 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8171 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008172 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8173 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008174 }
8175 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8176 pw.print(" mSubLayer="); pw.print(mSubLayer);
8177 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8178 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8179 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8180 pw.print("="); pw.print(mAnimLayer);
8181 pw.print(" mLastLayer="); pw.println(mLastLayer);
8182 if (mSurface != null) {
8183 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
8184 }
8185 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8186 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8187 if (mAppToken != null) {
8188 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8189 }
8190 if (mTargetAppToken != null) {
8191 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8192 }
8193 pw.print(prefix); pw.print("mViewVisibility=0x");
8194 pw.print(Integer.toHexString(mViewVisibility));
8195 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008196 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8197 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008198 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8199 pw.print(prefix); pw.print("mPolicyVisibility=");
8200 pw.print(mPolicyVisibility);
8201 pw.print(" mPolicyVisibilityAfterAnim=");
8202 pw.print(mPolicyVisibilityAfterAnim);
8203 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8204 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008205 if (!mRelayoutCalled) {
8206 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8207 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008208 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008209 pw.print(" h="); pw.print(mRequestedHeight);
8210 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008211 if (mXOffset != 0 || mYOffset != 0) {
8212 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8213 pw.print(" y="); pw.println(mYOffset);
8214 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008215 pw.print(prefix); pw.print("mGivenContentInsets=");
8216 mGivenContentInsets.printShortString(pw);
8217 pw.print(" mGivenVisibleInsets=");
8218 mGivenVisibleInsets.printShortString(pw);
8219 pw.println();
8220 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8221 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8222 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8223 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008224 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008225 pw.print(prefix); pw.print("mShownFrame=");
8226 mShownFrame.printShortString(pw);
8227 pw.print(" last="); mLastShownFrame.printShortString(pw);
8228 pw.println();
8229 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8230 pw.print(" last="); mLastFrame.printShortString(pw);
8231 pw.println();
8232 pw.print(prefix); pw.print("mContainingFrame=");
8233 mContainingFrame.printShortString(pw);
8234 pw.print(" mDisplayFrame=");
8235 mDisplayFrame.printShortString(pw);
8236 pw.println();
8237 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8238 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8239 pw.println();
8240 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8241 pw.print(" last="); mLastContentInsets.printShortString(pw);
8242 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8243 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8244 pw.println();
8245 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8246 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8247 pw.print(" mAlpha="); pw.print(mAlpha);
8248 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8249 }
8250 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8251 || mAnimation != null) {
8252 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8253 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8254 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8255 pw.print(" mAnimation="); pw.println(mAnimation);
8256 }
8257 if (mHasTransformation || mHasLocalTransformation) {
8258 pw.print(prefix); pw.print("XForm: has=");
8259 pw.print(mHasTransformation);
8260 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8261 pw.print(" "); mTransformation.printShortString(pw);
8262 pw.println();
8263 }
8264 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8265 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8266 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8267 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8268 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8269 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8270 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8271 pw.print(" mDestroying="); pw.print(mDestroying);
8272 pw.print(" mRemoved="); pw.println(mRemoved);
8273 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008274 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008275 pw.print(prefix); pw.print("mOrientationChanging=");
8276 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008277 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8278 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008279 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008280 if (mHScale != 1 || mVScale != 1) {
8281 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8282 pw.print(" mVScale="); pw.println(mVScale);
8283 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008284 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008285 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8286 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8287 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008288 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8289 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8290 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8291 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008292 }
8293
8294 @Override
8295 public String toString() {
8296 return "Window{"
8297 + Integer.toHexString(System.identityHashCode(this))
8298 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8299 }
8300 }
Romain Guy06882f82009-06-10 13:36:04 -07008301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008302 // -------------------------------------------------------------
8303 // Window Token State
8304 // -------------------------------------------------------------
8305
8306 class WindowToken {
8307 // The actual token.
8308 final IBinder token;
8309
8310 // The type of window this token is for, as per WindowManager.LayoutParams.
8311 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 // Set if this token was explicitly added by a client, so should
8314 // not be removed when all windows are removed.
8315 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008316
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008317 // For printing.
8318 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008320 // If this is an AppWindowToken, this is non-null.
8321 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008323 // All of the windows associated with this token.
8324 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8325
8326 // Is key dispatching paused for this token?
8327 boolean paused = false;
8328
8329 // Should this token's windows be hidden?
8330 boolean hidden;
8331
8332 // Temporary for finding which tokens no longer have visible windows.
8333 boolean hasVisible;
8334
Dianne Hackborna8f60182009-09-01 19:01:50 -07008335 // Set to true when this token is in a pending transaction where it
8336 // will be shown.
8337 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008338
Dianne Hackborna8f60182009-09-01 19:01:50 -07008339 // Set to true when this token is in a pending transaction where it
8340 // will be hidden.
8341 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008342
Dianne Hackborna8f60182009-09-01 19:01:50 -07008343 // Set to true when this token is in a pending transaction where its
8344 // windows will be put to the bottom of the list.
8345 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008346
Dianne Hackborna8f60182009-09-01 19:01:50 -07008347 // Set to true when this token is in a pending transaction where its
8348 // windows will be put to the top of the list.
8349 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008351 WindowToken(IBinder _token, int type, boolean _explicit) {
8352 token = _token;
8353 windowType = type;
8354 explicit = _explicit;
8355 }
8356
8357 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008358 pw.print(prefix); pw.print("token="); pw.println(token);
8359 pw.print(prefix); pw.print("windows="); pw.println(windows);
8360 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8361 pw.print(" hidden="); pw.print(hidden);
8362 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008363 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8364 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8365 pw.print(" waitingToHide="); pw.print(waitingToHide);
8366 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8367 pw.print(" sendingToTop="); pw.println(sendingToTop);
8368 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008369 }
8370
8371 @Override
8372 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008373 if (stringName == null) {
8374 StringBuilder sb = new StringBuilder();
8375 sb.append("WindowToken{");
8376 sb.append(Integer.toHexString(System.identityHashCode(this)));
8377 sb.append(" token="); sb.append(token); sb.append('}');
8378 stringName = sb.toString();
8379 }
8380 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008381 }
8382 };
8383
8384 class AppWindowToken extends WindowToken {
8385 // Non-null only for application tokens.
8386 final IApplicationToken appToken;
8387
8388 // All of the windows and child windows that are included in this
8389 // application token. Note this list is NOT sorted!
8390 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8391
8392 int groupId = -1;
8393 boolean appFullscreen;
8394 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008396 // These are used for determining when all windows associated with
8397 // an activity have been drawn, so they can be made visible together
8398 // at the same time.
8399 int lastTransactionSequence = mTransactionSequence-1;
8400 int numInterestingWindows;
8401 int numDrawnWindows;
8402 boolean inPendingTransaction;
8403 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008405 // Is this token going to be hidden in a little while? If so, it
8406 // won't be taken into account for setting the screen orientation.
8407 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 // Is this window's surface needed? This is almost like hidden, except
8410 // it will sometimes be true a little earlier: when the token has
8411 // been shown, but is still waiting for its app transition to execute
8412 // before making its windows shown.
8413 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 // Have we told the window clients to hide themselves?
8416 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418 // Last visibility state we reported to the app token.
8419 boolean reportedVisible;
8420
8421 // Set to true when the token has been removed from the window mgr.
8422 boolean removed;
8423
8424 // Have we been asked to have this token keep the screen frozen?
8425 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 boolean animating;
8428 Animation animation;
8429 boolean hasTransformation;
8430 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008432 // Offset to the window of all layers in the token, for use by
8433 // AppWindowToken animations.
8434 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 // Information about an application starting window if displayed.
8437 StartingData startingData;
8438 WindowState startingWindow;
8439 View startingView;
8440 boolean startingDisplayed;
8441 boolean startingMoved;
8442 boolean firstWindowDrawn;
8443
8444 AppWindowToken(IApplicationToken _token) {
8445 super(_token.asBinder(),
8446 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8447 appWindowToken = this;
8448 appToken = _token;
8449 }
Romain Guy06882f82009-06-10 13:36:04 -07008450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008451 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008452 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453 TAG, "Setting animation in " + this + ": " + anim);
8454 animation = anim;
8455 animating = false;
8456 anim.restrictDuration(MAX_ANIMATION_DURATION);
8457 anim.scaleCurrentDuration(mTransitionAnimationScale);
8458 int zorder = anim.getZAdjustment();
8459 int adj = 0;
8460 if (zorder == Animation.ZORDER_TOP) {
8461 adj = TYPE_LAYER_OFFSET;
8462 } else if (zorder == Animation.ZORDER_BOTTOM) {
8463 adj = -TYPE_LAYER_OFFSET;
8464 }
Romain Guy06882f82009-06-10 13:36:04 -07008465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 if (animLayerAdjustment != adj) {
8467 animLayerAdjustment = adj;
8468 updateLayers();
8469 }
8470 }
Romain Guy06882f82009-06-10 13:36:04 -07008471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008472 public void setDummyAnimation() {
8473 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008474 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008475 TAG, "Setting dummy animation in " + this);
8476 animation = sDummyAnimation;
8477 }
8478 }
8479
8480 public void clearAnimation() {
8481 if (animation != null) {
8482 animation = null;
8483 animating = true;
8484 }
8485 }
Romain Guy06882f82009-06-10 13:36:04 -07008486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008487 void updateLayers() {
8488 final int N = allAppWindows.size();
8489 final int adj = animLayerAdjustment;
8490 for (int i=0; i<N; i++) {
8491 WindowState w = allAppWindows.get(i);
8492 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008493 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 + w.mAnimLayer);
8495 if (w == mInputMethodTarget) {
8496 setInputMethodAnimLayerAdjustment(adj);
8497 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008498 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008499 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 }
8502 }
Romain Guy06882f82009-06-10 13:36:04 -07008503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008504 void sendAppVisibilityToClients() {
8505 final int N = allAppWindows.size();
8506 for (int i=0; i<N; i++) {
8507 WindowState win = allAppWindows.get(i);
8508 if (win == startingWindow && clientHidden) {
8509 // Don't hide the starting window.
8510 continue;
8511 }
8512 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008513 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008514 "Setting visibility of " + win + ": " + (!clientHidden));
8515 win.mClient.dispatchAppVisibility(!clientHidden);
8516 } catch (RemoteException e) {
8517 }
8518 }
8519 }
Romain Guy06882f82009-06-10 13:36:04 -07008520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008521 void showAllWindowsLocked() {
8522 final int NW = allAppWindows.size();
8523 for (int i=0; i<NW; i++) {
8524 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008525 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 "performing show on: " + w);
8527 w.performShowLocked();
8528 }
8529 }
Romain Guy06882f82009-06-10 13:36:04 -07008530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 // This must be called while inside a transaction.
8532 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008533 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 if (animation == sDummyAnimation) {
8537 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008538 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 // when it is really time to animate, this will be set to
8540 // a real animation and the next call will execute normally.
8541 return false;
8542 }
Romain Guy06882f82009-06-10 13:36:04 -07008543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8545 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008546 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 TAG, "Starting animation in " + this +
8548 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8549 + " scale=" + mTransitionAnimationScale
8550 + " allDrawn=" + allDrawn + " animating=" + animating);
8551 animation.initialize(dw, dh, dw, dh);
8552 animation.setStartTime(currentTime);
8553 animating = true;
8554 }
8555 transformation.clear();
8556 final boolean more = animation.getTransformation(
8557 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008558 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 TAG, "Stepped animation in " + this +
8560 ": more=" + more + ", xform=" + transformation);
8561 if (more) {
8562 // we're done!
8563 hasTransformation = true;
8564 return true;
8565 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008566 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008567 TAG, "Finished animation in " + this +
8568 " @ " + currentTime);
8569 animation = null;
8570 }
8571 } else if (animation != null) {
8572 // If the display is frozen, and there is a pending animation,
8573 // clear it and make sure we run the cleanup code.
8574 animating = true;
8575 animation = null;
8576 }
8577
8578 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008580 if (!animating) {
8581 return false;
8582 }
8583
8584 clearAnimation();
8585 animating = false;
8586 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8587 moveInputMethodWindowsIfNeededLocked(true);
8588 }
Romain Guy06882f82009-06-10 13:36:04 -07008589
Joe Onorato8a9b2202010-02-26 18:56:32 -08008590 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008591 TAG, "Animation done in " + this
8592 + ": reportedVisible=" + reportedVisible);
8593
8594 transformation.clear();
8595 if (animLayerAdjustment != 0) {
8596 animLayerAdjustment = 0;
8597 updateLayers();
8598 }
Romain Guy06882f82009-06-10 13:36:04 -07008599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008600 final int N = windows.size();
8601 for (int i=0; i<N; i++) {
8602 ((WindowState)windows.get(i)).finishExit();
8603 }
8604 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 return false;
8607 }
8608
8609 void updateReportedVisibilityLocked() {
8610 if (appToken == null) {
8611 return;
8612 }
Romain Guy06882f82009-06-10 13:36:04 -07008613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008614 int numInteresting = 0;
8615 int numVisible = 0;
8616 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008617
Joe Onorato8a9b2202010-02-26 18:56:32 -08008618 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 final int N = allAppWindows.size();
8620 for (int i=0; i<N; i++) {
8621 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008622 if (win == startingWindow || win.mAppFreezing
8623 || win.mViewVisibility != View.VISIBLE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008624 continue;
8625 }
8626 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008627 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008628 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008630 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008631 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008632 + " pv=" + win.mPolicyVisibility
8633 + " dp=" + win.mDrawPending
8634 + " cdp=" + win.mCommitDrawPending
8635 + " ah=" + win.mAttachedHidden
8636 + " th="
8637 + (win.mAppToken != null
8638 ? win.mAppToken.hiddenRequested : false)
8639 + " a=" + win.mAnimating);
8640 }
8641 }
8642 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008643 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 if (!win.isAnimating()) {
8645 numVisible++;
8646 }
8647 nowGone = false;
8648 } else if (win.isAnimating()) {
8649 nowGone = false;
8650 }
8651 }
Romain Guy06882f82009-06-10 13:36:04 -07008652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008654 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 + numInteresting + " visible=" + numVisible);
8656 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008657 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008658 TAG, "Visibility changed in " + this
8659 + ": vis=" + nowVisible);
8660 reportedVisible = nowVisible;
8661 Message m = mH.obtainMessage(
8662 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8663 nowVisible ? 1 : 0,
8664 nowGone ? 1 : 0,
8665 this);
8666 mH.sendMessage(m);
8667 }
8668 }
Romain Guy06882f82009-06-10 13:36:04 -07008669
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008670 WindowState findMainWindow() {
8671 int j = windows.size();
8672 while (j > 0) {
8673 j--;
8674 WindowState win = windows.get(j);
8675 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8676 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8677 return win;
8678 }
8679 }
8680 return null;
8681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 void dump(PrintWriter pw, String prefix) {
8684 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008685 if (appToken != null) {
8686 pw.print(prefix); pw.println("app=true");
8687 }
8688 if (allAppWindows.size() > 0) {
8689 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8690 }
8691 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008692 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008693 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8694 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8695 pw.print(" clientHidden="); pw.print(clientHidden);
8696 pw.print(" willBeHidden="); pw.print(willBeHidden);
8697 pw.print(" reportedVisible="); pw.println(reportedVisible);
8698 if (paused || freezingScreen) {
8699 pw.print(prefix); pw.print("paused="); pw.print(paused);
8700 pw.print(" freezingScreen="); pw.println(freezingScreen);
8701 }
8702 if (numInterestingWindows != 0 || numDrawnWindows != 0
8703 || inPendingTransaction || allDrawn) {
8704 pw.print(prefix); pw.print("numInterestingWindows=");
8705 pw.print(numInterestingWindows);
8706 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8707 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8708 pw.print(" allDrawn="); pw.println(allDrawn);
8709 }
8710 if (animating || animation != null) {
8711 pw.print(prefix); pw.print("animating="); pw.print(animating);
8712 pw.print(" animation="); pw.println(animation);
8713 }
8714 if (animLayerAdjustment != 0) {
8715 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8716 }
8717 if (hasTransformation) {
8718 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8719 pw.print(" transformation="); transformation.printShortString(pw);
8720 pw.println();
8721 }
8722 if (startingData != null || removed || firstWindowDrawn) {
8723 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8724 pw.print(" removed="); pw.print(removed);
8725 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8726 }
8727 if (startingWindow != null || startingView != null
8728 || startingDisplayed || startingMoved) {
8729 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8730 pw.print(" startingView="); pw.print(startingView);
8731 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8732 pw.print(" startingMoved"); pw.println(startingMoved);
8733 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734 }
8735
8736 @Override
8737 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008738 if (stringName == null) {
8739 StringBuilder sb = new StringBuilder();
8740 sb.append("AppWindowToken{");
8741 sb.append(Integer.toHexString(System.identityHashCode(this)));
8742 sb.append(" token="); sb.append(token); sb.append('}');
8743 stringName = sb.toString();
8744 }
8745 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008746 }
8747 }
Romain Guy06882f82009-06-10 13:36:04 -07008748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008749 // -------------------------------------------------------------
8750 // DummyAnimation
8751 // -------------------------------------------------------------
8752
8753 // This is an animation that does nothing: it just immediately finishes
8754 // itself every time it is called. It is used as a stub animation in cases
8755 // where we want to synchronize multiple things that may be animating.
8756 static final class DummyAnimation extends Animation {
8757 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8758 return false;
8759 }
8760 }
8761 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008763 // -------------------------------------------------------------
8764 // Async Handler
8765 // -------------------------------------------------------------
8766
8767 static final class StartingData {
8768 final String pkg;
8769 final int theme;
8770 final CharSequence nonLocalizedLabel;
8771 final int labelRes;
8772 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008774 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8775 int _labelRes, int _icon) {
8776 pkg = _pkg;
8777 theme = _theme;
8778 nonLocalizedLabel = _nonLocalizedLabel;
8779 labelRes = _labelRes;
8780 icon = _icon;
8781 }
8782 }
8783
8784 private final class H extends Handler {
8785 public static final int REPORT_FOCUS_CHANGE = 2;
8786 public static final int REPORT_LOSING_FOCUS = 3;
8787 public static final int ANIMATE = 4;
8788 public static final int ADD_STARTING = 5;
8789 public static final int REMOVE_STARTING = 6;
8790 public static final int FINISHED_STARTING = 7;
8791 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8793 public static final int HOLD_SCREEN_CHANGED = 12;
8794 public static final int APP_TRANSITION_TIMEOUT = 13;
8795 public static final int PERSIST_ANIMATION_SCALE = 14;
8796 public static final int FORCE_GC = 15;
8797 public static final int ENABLE_SCREEN = 16;
8798 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008799 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008801 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008803 public H() {
8804 }
Romain Guy06882f82009-06-10 13:36:04 -07008805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008806 @Override
8807 public void handleMessage(Message msg) {
8808 switch (msg.what) {
8809 case REPORT_FOCUS_CHANGE: {
8810 WindowState lastFocus;
8811 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008813 synchronized(mWindowMap) {
8814 lastFocus = mLastFocus;
8815 newFocus = mCurrentFocus;
8816 if (lastFocus == newFocus) {
8817 // Focus is not changing, so nothing to do.
8818 return;
8819 }
8820 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008821 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008822 // + " to " + newFocus);
8823 if (newFocus != null && lastFocus != null
8824 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008825 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008826 mLosingFocus.add(lastFocus);
8827 lastFocus = null;
8828 }
8829 }
8830
8831 if (lastFocus != newFocus) {
8832 //System.out.println("Changing focus from " + lastFocus
8833 // + " to " + newFocus);
8834 if (newFocus != null) {
8835 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008836 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008837 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8838 } catch (RemoteException e) {
8839 // Ignore if process has died.
8840 }
8841 }
8842
8843 if (lastFocus != null) {
8844 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008845 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008846 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8847 } catch (RemoteException e) {
8848 // Ignore if process has died.
8849 }
8850 }
8851 }
8852 } break;
8853
8854 case REPORT_LOSING_FOCUS: {
8855 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008857 synchronized(mWindowMap) {
8858 losers = mLosingFocus;
8859 mLosingFocus = new ArrayList<WindowState>();
8860 }
8861
8862 final int N = losers.size();
8863 for (int i=0; i<N; i++) {
8864 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008865 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8867 } catch (RemoteException e) {
8868 // Ignore if process has died.
8869 }
8870 }
8871 } break;
8872
8873 case ANIMATE: {
8874 synchronized(mWindowMap) {
8875 mAnimationPending = false;
8876 performLayoutAndPlaceSurfacesLocked();
8877 }
8878 } break;
8879
8880 case ADD_STARTING: {
8881 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8882 final StartingData sd = wtoken.startingData;
8883
8884 if (sd == null) {
8885 // Animation has been canceled... do nothing.
8886 return;
8887 }
Romain Guy06882f82009-06-10 13:36:04 -07008888
Joe Onorato8a9b2202010-02-26 18:56:32 -08008889 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008892 View view = null;
8893 try {
8894 view = mPolicy.addStartingWindow(
8895 wtoken.token, sd.pkg,
8896 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8897 sd.icon);
8898 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008899 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 }
8901
8902 if (view != null) {
8903 boolean abort = false;
8904
8905 synchronized(mWindowMap) {
8906 if (wtoken.removed || wtoken.startingData == null) {
8907 // If the window was successfully added, then
8908 // we need to remove it.
8909 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008910 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008911 "Aborted starting " + wtoken
8912 + ": removed=" + wtoken.removed
8913 + " startingData=" + wtoken.startingData);
8914 wtoken.startingWindow = null;
8915 wtoken.startingData = null;
8916 abort = true;
8917 }
8918 } else {
8919 wtoken.startingView = view;
8920 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008921 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008922 "Added starting " + wtoken
8923 + ": startingWindow="
8924 + wtoken.startingWindow + " startingView="
8925 + wtoken.startingView);
8926 }
8927
8928 if (abort) {
8929 try {
8930 mPolicy.removeStartingWindow(wtoken.token, view);
8931 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008932 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008933 }
8934 }
8935 }
8936 } break;
8937
8938 case REMOVE_STARTING: {
8939 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8940 IBinder token = null;
8941 View view = null;
8942 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008943 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008944 + wtoken + ": startingWindow="
8945 + wtoken.startingWindow + " startingView="
8946 + wtoken.startingView);
8947 if (wtoken.startingWindow != null) {
8948 view = wtoken.startingView;
8949 token = wtoken.token;
8950 wtoken.startingData = null;
8951 wtoken.startingView = null;
8952 wtoken.startingWindow = null;
8953 }
8954 }
8955 if (view != null) {
8956 try {
8957 mPolicy.removeStartingWindow(token, view);
8958 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008959 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008960 }
8961 }
8962 } break;
8963
8964 case FINISHED_STARTING: {
8965 IBinder token = null;
8966 View view = null;
8967 while (true) {
8968 synchronized (mWindowMap) {
8969 final int N = mFinishedStarting.size();
8970 if (N <= 0) {
8971 break;
8972 }
8973 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8974
Joe Onorato8a9b2202010-02-26 18:56:32 -08008975 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 "Finished starting " + wtoken
8977 + ": startingWindow=" + wtoken.startingWindow
8978 + " startingView=" + wtoken.startingView);
8979
8980 if (wtoken.startingWindow == null) {
8981 continue;
8982 }
8983
8984 view = wtoken.startingView;
8985 token = wtoken.token;
8986 wtoken.startingData = null;
8987 wtoken.startingView = null;
8988 wtoken.startingWindow = null;
8989 }
8990
8991 try {
8992 mPolicy.removeStartingWindow(token, view);
8993 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008994 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008995 }
8996 }
8997 } break;
8998
8999 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9000 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9001
9002 boolean nowVisible = msg.arg1 != 0;
9003 boolean nowGone = msg.arg2 != 0;
9004
9005 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009006 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009007 TAG, "Reporting visible in " + wtoken
9008 + " visible=" + nowVisible
9009 + " gone=" + nowGone);
9010 if (nowVisible) {
9011 wtoken.appToken.windowsVisible();
9012 } else {
9013 wtoken.appToken.windowsGone();
9014 }
9015 } catch (RemoteException ex) {
9016 }
9017 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 case WINDOW_FREEZE_TIMEOUT: {
9020 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009021 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009022 int i = mWindows.size();
9023 while (i > 0) {
9024 i--;
9025 WindowState w = (WindowState)mWindows.get(i);
9026 if (w.mOrientationChanging) {
9027 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009028 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009029 }
9030 }
9031 performLayoutAndPlaceSurfacesLocked();
9032 }
9033 break;
9034 }
Romain Guy06882f82009-06-10 13:36:04 -07009035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009036 case HOLD_SCREEN_CHANGED: {
9037 Session oldHold;
9038 Session newHold;
9039 synchronized (mWindowMap) {
9040 oldHold = mLastReportedHold;
9041 newHold = (Session)msg.obj;
9042 mLastReportedHold = newHold;
9043 }
Romain Guy06882f82009-06-10 13:36:04 -07009044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009045 if (oldHold != newHold) {
9046 try {
9047 if (oldHold != null) {
9048 mBatteryStats.noteStopWakelock(oldHold.mUid,
9049 "window",
9050 BatteryStats.WAKE_TYPE_WINDOW);
9051 }
9052 if (newHold != null) {
9053 mBatteryStats.noteStartWakelock(newHold.mUid,
9054 "window",
9055 BatteryStats.WAKE_TYPE_WINDOW);
9056 }
9057 } catch (RemoteException e) {
9058 }
9059 }
9060 break;
9061 }
Romain Guy06882f82009-06-10 13:36:04 -07009062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009063 case APP_TRANSITION_TIMEOUT: {
9064 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009065 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009066 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009067 "*** APP TRANSITION TIMEOUT");
9068 mAppTransitionReady = true;
9069 mAppTransitionTimeout = true;
9070 performLayoutAndPlaceSurfacesLocked();
9071 }
9072 }
9073 break;
9074 }
Romain Guy06882f82009-06-10 13:36:04 -07009075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009076 case PERSIST_ANIMATION_SCALE: {
9077 Settings.System.putFloat(mContext.getContentResolver(),
9078 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9079 Settings.System.putFloat(mContext.getContentResolver(),
9080 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9081 break;
9082 }
Romain Guy06882f82009-06-10 13:36:04 -07009083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 case FORCE_GC: {
9085 synchronized(mWindowMap) {
9086 if (mAnimationPending) {
9087 // If we are animating, don't do the gc now but
9088 // delay a bit so we don't interrupt the animation.
9089 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9090 2000);
9091 return;
9092 }
9093 // If we are currently rotating the display, it will
9094 // schedule a new message when done.
9095 if (mDisplayFrozen) {
9096 return;
9097 }
9098 mFreezeGcPending = 0;
9099 }
9100 Runtime.getRuntime().gc();
9101 break;
9102 }
Romain Guy06882f82009-06-10 13:36:04 -07009103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009104 case ENABLE_SCREEN: {
9105 performEnableScreen();
9106 break;
9107 }
Romain Guy06882f82009-06-10 13:36:04 -07009108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009109 case APP_FREEZE_TIMEOUT: {
9110 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009111 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009112 int i = mAppTokens.size();
9113 while (i > 0) {
9114 i--;
9115 AppWindowToken tok = mAppTokens.get(i);
9116 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009117 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 unsetAppFreezingScreenLocked(tok, true, true);
9119 }
9120 }
9121 }
9122 break;
9123 }
Romain Guy06882f82009-06-10 13:36:04 -07009124
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009125 case SEND_NEW_CONFIGURATION: {
9126 removeMessages(SEND_NEW_CONFIGURATION);
9127 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009128 break;
9129 }
Romain Guy06882f82009-06-10 13:36:04 -07009130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009131 }
9132 }
9133 }
9134
9135 // -------------------------------------------------------------
9136 // IWindowManager API
9137 // -------------------------------------------------------------
9138
9139 public IWindowSession openSession(IInputMethodClient client,
9140 IInputContext inputContext) {
9141 if (client == null) throw new IllegalArgumentException("null client");
9142 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9143 return new Session(client, inputContext);
9144 }
9145
9146 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9147 synchronized (mWindowMap) {
9148 // The focus for the client is the window immediately below
9149 // where we would place the input method window.
9150 int idx = findDesiredInputMethodWindowIndexLocked(false);
9151 WindowState imFocus;
9152 if (idx > 0) {
9153 imFocus = (WindowState)mWindows.get(idx-1);
9154 if (imFocus != null) {
9155 if (imFocus.mSession.mClient != null &&
9156 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9157 return true;
9158 }
9159 }
9160 }
9161 }
9162 return false;
9163 }
Romain Guy06882f82009-06-10 13:36:04 -07009164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009165 // -------------------------------------------------------------
9166 // Internals
9167 // -------------------------------------------------------------
9168
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009169 final WindowState windowForClientLocked(Session session, IWindow client,
9170 boolean throwOnError) {
9171 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009172 }
Romain Guy06882f82009-06-10 13:36:04 -07009173
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009174 final WindowState windowForClientLocked(Session session, IBinder client,
9175 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009176 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009177 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009178 TAG, "Looking up client " + client + ": " + win);
9179 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009180 RuntimeException ex = new IllegalArgumentException(
9181 "Requested window " + client + " does not exist");
9182 if (throwOnError) {
9183 throw ex;
9184 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009185 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009186 return null;
9187 }
9188 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009189 RuntimeException ex = new IllegalArgumentException(
9190 "Requested window " + client + " is in session " +
9191 win.mSession + ", not " + session);
9192 if (throwOnError) {
9193 throw ex;
9194 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009195 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009196 return null;
9197 }
9198
9199 return win;
9200 }
9201
Dianne Hackborna8f60182009-09-01 19:01:50 -07009202 final void rebuildAppWindowListLocked() {
9203 int NW = mWindows.size();
9204 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009205 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009206 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009207
Dianne Hackborna8f60182009-09-01 19:01:50 -07009208 // First remove all existing app windows.
9209 i=0;
9210 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009211 WindowState w = (WindowState)mWindows.get(i);
9212 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009213 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009214 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009215 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009216 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009217 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009218 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009219 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9220 && lastWallpaper == i-1) {
9221 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009222 }
9223 i++;
9224 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009225
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009226 // The wallpaper window(s) typically live at the bottom of the stack,
9227 // so skip them before adding app tokens.
9228 lastWallpaper++;
9229 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009230
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009231 // First add all of the exiting app tokens... these are no longer
9232 // in the main app list, but still have windows shown. We put them
9233 // in the back because now that the animation is over we no longer
9234 // will care about them.
9235 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009236 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009237 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9238 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009239
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009240 // And add in the still active app tokens in Z order.
9241 NT = mAppTokens.size();
9242 for (int j=0; j<NT; j++) {
9243 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009244 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009245
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009246 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009247 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009248 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009249 + " windows but added " + i);
9250 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009251 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 private final void assignLayersLocked() {
9254 int N = mWindows.size();
9255 int curBaseLayer = 0;
9256 int curLayer = 0;
9257 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009259 for (i=0; i<N; i++) {
9260 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009261 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9262 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009263 curLayer += WINDOW_LAYER_MULTIPLIER;
9264 w.mLayer = curLayer;
9265 } else {
9266 curBaseLayer = curLayer = w.mBaseLayer;
9267 w.mLayer = curLayer;
9268 }
9269 if (w.mTargetAppToken != null) {
9270 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9271 } else if (w.mAppToken != null) {
9272 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9273 } else {
9274 w.mAnimLayer = w.mLayer;
9275 }
9276 if (w.mIsImWindow) {
9277 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009278 } else if (w.mIsWallpaper) {
9279 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009281 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009282 + w.mAnimLayer);
9283 //System.out.println(
9284 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9285 }
9286 }
9287
9288 private boolean mInLayout = false;
9289 private final void performLayoutAndPlaceSurfacesLocked() {
9290 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009291 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009292 throw new RuntimeException("Recursive call!");
9293 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009294 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 return;
9296 }
9297
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009298 if (mWaitingForConfig) {
9299 // Our configuration has changed (most likely rotation), but we
9300 // don't yet have the complete configuration to report to
9301 // applications. Don't do any window layout until we have it.
9302 return;
9303 }
9304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009305 boolean recoveringMemory = false;
9306 if (mForceRemoves != null) {
9307 recoveringMemory = true;
9308 // Wait a little it for things to settle down, and off we go.
9309 for (int i=0; i<mForceRemoves.size(); i++) {
9310 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009311 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 removeWindowInnerLocked(ws.mSession, ws);
9313 }
9314 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009315 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009316 Object tmp = new Object();
9317 synchronized (tmp) {
9318 try {
9319 tmp.wait(250);
9320 } catch (InterruptedException e) {
9321 }
9322 }
9323 }
Romain Guy06882f82009-06-10 13:36:04 -07009324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009325 mInLayout = true;
9326 try {
9327 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009329 int i = mPendingRemove.size()-1;
9330 if (i >= 0) {
9331 while (i >= 0) {
9332 WindowState w = mPendingRemove.get(i);
9333 removeWindowInnerLocked(w.mSession, w);
9334 i--;
9335 }
9336 mPendingRemove.clear();
9337
9338 mInLayout = false;
9339 assignLayersLocked();
9340 mLayoutNeeded = true;
9341 performLayoutAndPlaceSurfacesLocked();
9342
9343 } else {
9344 mInLayout = false;
9345 if (mLayoutNeeded) {
9346 requestAnimationLocked(0);
9347 }
9348 }
9349 } catch (RuntimeException e) {
9350 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009351 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009352 }
9353 }
9354
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009355 private final int performLayoutLockedInner() {
9356 if (!mLayoutNeeded) {
9357 return 0;
9358 }
9359
9360 mLayoutNeeded = false;
9361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009362 final int dw = mDisplay.getWidth();
9363 final int dh = mDisplay.getHeight();
9364
9365 final int N = mWindows.size();
9366 int i;
9367
Joe Onorato8a9b2202010-02-26 18:56:32 -08009368 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009369 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9370
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009371 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009372
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009373 int seq = mLayoutSeq+1;
9374 if (seq < 0) seq = 0;
9375 mLayoutSeq = seq;
9376
9377 // First perform layout of any root windows (not attached
9378 // to another window).
9379 int topAttached = -1;
9380 for (i = N-1; i >= 0; i--) {
9381 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009382
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009383 // Don't do layout of a window if it is not visible, or
9384 // soon won't be visible, to avoid wasting time and funky
9385 // changes while a window is animating away.
9386 final AppWindowToken atoken = win.mAppToken;
9387 final boolean gone = win.mViewVisibility == View.GONE
9388 || !win.mRelayoutCalled
9389 || win.mRootToken.hidden
9390 || (atoken != null && atoken.hiddenRequested)
9391 || win.mAttachedHidden
9392 || win.mExiting || win.mDestroying;
9393
9394 if (!win.mLayoutAttached) {
9395 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9396 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9397 + " mLayoutAttached=" + win.mLayoutAttached);
9398 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9399 + win.mViewVisibility + " mRelayoutCalled="
9400 + win.mRelayoutCalled + " hidden="
9401 + win.mRootToken.hidden + " hiddenRequested="
9402 + (atoken != null && atoken.hiddenRequested)
9403 + " mAttachedHidden=" + win.mAttachedHidden);
9404 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009405
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009406 // If this view is GONE, then skip it -- keep the current
9407 // frame, and let the caller know so they can ignore it
9408 // if they want. (We do the normal layout for INVISIBLE
9409 // windows, since that means "perform layout as normal,
9410 // just don't display").
9411 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009412 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009413 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9414 win.mLayoutSeq = seq;
9415 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9416 + win.mFrame + " mContainingFrame="
9417 + win.mContainingFrame + " mDisplayFrame="
9418 + win.mDisplayFrame);
9419 } else {
9420 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009421 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009423 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009424
9425 // Now perform layout of attached windows, which usually
9426 // depend on the position of the window they are attached to.
9427 // XXX does not deal with windows that are attached to windows
9428 // that are themselves attached.
9429 for (i = topAttached; i >= 0; i--) {
9430 WindowState win = (WindowState) mWindows.get(i);
9431
9432 // If this view is GONE, then skip it -- keep the current
9433 // frame, and let the caller know so they can ignore it
9434 // if they want. (We do the normal layout for INVISIBLE
9435 // windows, since that means "perform layout as normal,
9436 // just don't display").
9437 if (win.mLayoutAttached) {
9438 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9439 + " mHaveFrame=" + win.mHaveFrame
9440 + " mViewVisibility=" + win.mViewVisibility
9441 + " mRelayoutCalled=" + win.mRelayoutCalled);
9442 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9443 || !win.mHaveFrame) {
9444 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9445 win.mLayoutSeq = seq;
9446 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9447 + win.mFrame + " mContainingFrame="
9448 + win.mContainingFrame + " mDisplayFrame="
9449 + win.mDisplayFrame);
9450 }
9451 }
9452 }
9453
9454 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009455 }
Romain Guy06882f82009-06-10 13:36:04 -07009456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009457 private final void performLayoutAndPlaceSurfacesLockedInner(
9458 boolean recoveringMemory) {
9459 final long currentTime = SystemClock.uptimeMillis();
9460 final int dw = mDisplay.getWidth();
9461 final int dh = mDisplay.getHeight();
9462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009463 int i;
9464
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009465 if (mFocusMayChange) {
9466 mFocusMayChange = false;
9467 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9468 }
9469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009470 if (mFxSession == null) {
9471 mFxSession = new SurfaceSession();
9472 }
Romain Guy06882f82009-06-10 13:36:04 -07009473
Joe Onorato8a9b2202010-02-26 18:56:32 -08009474 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009475
9476 // Initialize state of exiting tokens.
9477 for (i=mExitingTokens.size()-1; i>=0; i--) {
9478 mExitingTokens.get(i).hasVisible = false;
9479 }
9480
9481 // Initialize state of exiting applications.
9482 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9483 mExitingAppTokens.get(i).hasVisible = false;
9484 }
9485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009486 boolean orientationChangeComplete = true;
9487 Session holdScreen = null;
9488 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009489 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009490 boolean focusDisplayed = false;
9491 boolean animating = false;
9492
9493 Surface.openTransaction();
9494 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009495 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009496 int repeats = 0;
9497 int changes = 0;
9498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009500 repeats++;
9501 if (repeats > 6) {
9502 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9503 mLayoutNeeded = false;
9504 break;
9505 }
9506
9507 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9508 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9509 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9510 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9511 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9512 assignLayersLocked();
9513 mLayoutNeeded = true;
9514 }
9515 }
9516 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9517 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9518 if (updateOrientationFromAppTokensLocked()) {
9519 mLayoutNeeded = true;
9520 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9521 }
9522 }
9523 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9524 mLayoutNeeded = true;
9525 }
9526 }
9527
9528 // FIRST LOOP: Perform a layout, if needed.
9529 if (repeats < 4) {
9530 changes = performLayoutLockedInner();
9531 if (changes != 0) {
9532 continue;
9533 }
9534 } else {
9535 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9536 changes = 0;
9537 }
9538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 final int transactionSequence = ++mTransactionSequence;
9540
9541 // Update animations of all applications, including those
9542 // associated with exiting/removed apps
9543 boolean tokensAnimating = false;
9544 final int NAT = mAppTokens.size();
9545 for (i=0; i<NAT; i++) {
9546 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9547 tokensAnimating = true;
9548 }
9549 }
9550 final int NEAT = mExitingAppTokens.size();
9551 for (i=0; i<NEAT; i++) {
9552 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9553 tokensAnimating = true;
9554 }
9555 }
9556
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009557 // SECOND LOOP: Execute animations and update visibility of windows.
9558
Joe Onorato8a9b2202010-02-26 18:56:32 -08009559 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009560 + transactionSequence + " tokensAnimating="
9561 + tokensAnimating);
9562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009563 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009564
9565 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009566 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009567 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009568
9569 mPolicy.beginAnimationLw(dw, dh);
9570
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009571 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009573 for (i=N-1; i>=0; i--) {
9574 WindowState w = (WindowState)mWindows.get(i);
9575
9576 final WindowManager.LayoutParams attrs = w.mAttrs;
9577
9578 if (w.mSurface != null) {
9579 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009580 if (w.commitFinishDrawingLocked(currentTime)) {
9581 if ((w.mAttrs.flags
9582 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009583 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009584 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009585 wallpaperMayChange = true;
9586 }
9587 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009588
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009589 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009590 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9591 animating = true;
9592 //w.dump(" ");
9593 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009594 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9595 wallpaperMayChange = true;
9596 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009597
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009598 if (mPolicy.doesForceHide(w, attrs)) {
9599 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009600 if (DEBUG_VISIBILITY) Slog.v(TAG,
9601 "Animation done that could impact force hide: "
9602 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009603 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009604 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009605 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9606 forceHiding = true;
9607 }
9608 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9609 boolean changed;
9610 if (forceHiding) {
9611 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009612 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9613 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009614 } else {
9615 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009616 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9617 "Now policy shown: " + w);
9618 if (changed) {
9619 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009620 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009621 // Assume we will need to animate. If
9622 // we don't (because the wallpaper will
9623 // stay with the lock screen), then we will
9624 // clean up later.
9625 Animation a = mPolicy.createForceHideEnterAnimation();
9626 if (a != null) {
9627 w.setAnimation(a);
9628 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009629 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009630 if (mCurrentFocus == null ||
9631 mCurrentFocus.mLayer < w.mLayer) {
9632 // We are showing on to of the current
9633 // focus, so re-evaluate focus to make
9634 // sure it is correct.
9635 mFocusMayChange = true;
9636 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009637 }
9638 }
9639 if (changed && (attrs.flags
9640 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9641 wallpaperMayChange = true;
9642 }
9643 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009645 mPolicy.animatingWindowLw(w, attrs);
9646 }
9647
9648 final AppWindowToken atoken = w.mAppToken;
9649 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9650 if (atoken.lastTransactionSequence != transactionSequence) {
9651 atoken.lastTransactionSequence = transactionSequence;
9652 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9653 atoken.startingDisplayed = false;
9654 }
9655 if ((w.isOnScreen() || w.mAttrs.type
9656 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9657 && !w.mExiting && !w.mDestroying) {
9658 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009659 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009660 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009662 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009663 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009664 + " pv=" + w.mPolicyVisibility
9665 + " dp=" + w.mDrawPending
9666 + " cdp=" + w.mCommitDrawPending
9667 + " ah=" + w.mAttachedHidden
9668 + " th=" + atoken.hiddenRequested
9669 + " a=" + w.mAnimating);
9670 }
9671 }
9672 if (w != atoken.startingWindow) {
9673 if (!atoken.freezingScreen || !w.mAppFreezing) {
9674 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009675 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009676 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009677 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009678 "tokenMayBeDrawn: " + atoken
9679 + " freezingScreen=" + atoken.freezingScreen
9680 + " mAppFreezing=" + w.mAppFreezing);
9681 tokenMayBeDrawn = true;
9682 }
9683 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009684 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685 atoken.startingDisplayed = true;
9686 }
9687 }
9688 } else if (w.mReadyToShow) {
9689 w.performShowLocked();
9690 }
9691 }
9692
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009693 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009694
9695 if (tokenMayBeDrawn) {
9696 // See if any windows have been drawn, so they (and others
9697 // associated with them) can now be shown.
9698 final int NT = mTokenList.size();
9699 for (i=0; i<NT; i++) {
9700 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9701 if (wtoken == null) {
9702 continue;
9703 }
9704 if (wtoken.freezingScreen) {
9705 int numInteresting = wtoken.numInterestingWindows;
9706 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009707 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009708 "allDrawn: " + wtoken
9709 + " interesting=" + numInteresting
9710 + " drawn=" + wtoken.numDrawnWindows);
9711 wtoken.showAllWindowsLocked();
9712 unsetAppFreezingScreenLocked(wtoken, false, true);
9713 orientationChangeComplete = true;
9714 }
9715 } else if (!wtoken.allDrawn) {
9716 int numInteresting = wtoken.numInterestingWindows;
9717 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009718 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009719 "allDrawn: " + wtoken
9720 + " interesting=" + numInteresting
9721 + " drawn=" + wtoken.numDrawnWindows);
9722 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009723 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009724
9725 // We can now show all of the drawn windows!
9726 if (!mOpeningApps.contains(wtoken)) {
9727 wtoken.showAllWindowsLocked();
9728 }
9729 }
9730 }
9731 }
9732 }
9733
9734 // If we are ready to perform an app transition, check through
9735 // all of the app tokens to be shown and see if they are ready
9736 // to go.
9737 if (mAppTransitionReady) {
9738 int NN = mOpeningApps.size();
9739 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009740 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741 "Checking " + NN + " opening apps (frozen="
9742 + mDisplayFrozen + " timeout="
9743 + mAppTransitionTimeout + ")...");
9744 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9745 // If the display isn't frozen, wait to do anything until
9746 // all of the apps are ready. Otherwise just go because
9747 // we'll unfreeze the display when everyone is ready.
9748 for (i=0; i<NN && goodToGo; i++) {
9749 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009751 "Check opening app" + wtoken + ": allDrawn="
9752 + wtoken.allDrawn + " startingDisplayed="
9753 + wtoken.startingDisplayed);
9754 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9755 && !wtoken.startingMoved) {
9756 goodToGo = false;
9757 }
9758 }
9759 }
9760 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009761 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009762 int transit = mNextAppTransition;
9763 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009764 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009766 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009768 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 mAppTransitionTimeout = false;
9770 mStartingIconInTransition = false;
9771 mSkipAppTransitionAnimation = false;
9772
9773 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9774
Dianne Hackborna8f60182009-09-01 19:01:50 -07009775 // If there are applications waiting to come to the
9776 // top of the stack, now is the time to move their windows.
9777 // (Note that we don't do apps going to the bottom
9778 // here -- we want to keep their windows in the old
9779 // Z-order until the animation completes.)
9780 if (mToTopApps.size() > 0) {
9781 NN = mAppTokens.size();
9782 for (i=0; i<NN; i++) {
9783 AppWindowToken wtoken = mAppTokens.get(i);
9784 if (wtoken.sendingToTop) {
9785 wtoken.sendingToTop = false;
9786 moveAppWindowsLocked(wtoken, NN, false);
9787 }
9788 }
9789 mToTopApps.clear();
9790 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009791
Dianne Hackborn25994b42009-09-04 14:21:19 -07009792 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009793
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009794 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009795 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009796
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009797 // The top-most window will supply the layout params,
9798 // and we will determine it below.
9799 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009800 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009801 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009802
Joe Onorato8a9b2202010-02-26 18:56:32 -08009803 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009804 "New wallpaper target=" + mWallpaperTarget
9805 + ", lower target=" + mLowerWallpaperTarget
9806 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009807 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009808 // Do a first pass through the tokens for two
9809 // things:
9810 // (1) Determine if both the closing and opening
9811 // app token sets are wallpaper targets, in which
9812 // case special animations are needed
9813 // (since the wallpaper needs to stay static
9814 // behind them).
9815 // (2) Find the layout params of the top-most
9816 // application window in the tokens, which is
9817 // what will control the animation theme.
9818 final int NC = mClosingApps.size();
9819 NN = NC + mOpeningApps.size();
9820 for (i=0; i<NN; i++) {
9821 AppWindowToken wtoken;
9822 int mode;
9823 if (i < NC) {
9824 wtoken = mClosingApps.get(i);
9825 mode = 1;
9826 } else {
9827 wtoken = mOpeningApps.get(i-NC);
9828 mode = 2;
9829 }
9830 if (mLowerWallpaperTarget != null) {
9831 if (mLowerWallpaperTarget.mAppToken == wtoken
9832 || mUpperWallpaperTarget.mAppToken == wtoken) {
9833 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009834 }
9835 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009836 if (wtoken.appFullscreen) {
9837 WindowState ws = wtoken.findMainWindow();
9838 if (ws != null) {
9839 // If this is a compatibility mode
9840 // window, we will always use its anim.
9841 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9842 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009843 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009844 bestAnimLayer = Integer.MAX_VALUE;
9845 } else if (ws.mLayer > bestAnimLayer) {
9846 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009847 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009848 bestAnimLayer = ws.mLayer;
9849 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009850 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009851 }
9852 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009853
Dianne Hackborn25994b42009-09-04 14:21:19 -07009854 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009855 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009856 "Wallpaper animation!");
9857 switch (transit) {
9858 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9859 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9860 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9861 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9862 break;
9863 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9864 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9865 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9866 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9867 break;
9868 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009869 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009870 "New transit: " + transit);
9871 } else if (oldWallpaper != null) {
9872 // We are transitioning from an activity with
9873 // a wallpaper to one without.
9874 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009875 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009876 "New transit away from wallpaper: " + transit);
9877 } else if (mWallpaperTarget != null) {
9878 // We are transitioning from an activity without
9879 // a wallpaper to now showing the wallpaper
9880 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009881 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009882 "New transit into wallpaper: " + transit);
9883 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009884
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009885 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9886 mLastEnterAnimToken = animToken;
9887 mLastEnterAnimParams = animLp;
9888 } else if (mLastEnterAnimParams != null) {
9889 animLp = mLastEnterAnimParams;
9890 mLastEnterAnimToken = null;
9891 mLastEnterAnimParams = null;
9892 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009893
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009894 // If all closing windows are obscured, then there is
9895 // no need to do an animation. This is the case, for
9896 // example, when this transition is being done behind
9897 // the lock screen.
9898 if (!mPolicy.allowAppAnimationsLw()) {
9899 animLp = null;
9900 }
9901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 NN = mOpeningApps.size();
9903 for (i=0; i<NN; i++) {
9904 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009905 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009906 "Now opening app" + wtoken);
9907 wtoken.reportedVisible = false;
9908 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009909 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009910 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009911 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009912 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009913 wtoken.showAllWindowsLocked();
9914 }
9915 NN = mClosingApps.size();
9916 for (i=0; i<NN; i++) {
9917 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009918 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009919 "Now closing app" + wtoken);
9920 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009921 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009922 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009923 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009924 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009925 // Force the allDrawn flag, because we want to start
9926 // this guy's animations regardless of whether it's
9927 // gotten drawn.
9928 wtoken.allDrawn = true;
9929 }
9930
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009931 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009933 mOpeningApps.clear();
9934 mClosingApps.clear();
9935
9936 // This has changed the visibility of windows, so perform
9937 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009938 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009940 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9941 assignLayersLocked();
9942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009943 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009944 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009945 }
9946 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009947
Dianne Hackborna8f60182009-09-01 19:01:50 -07009948 if (!animating && mAppTransitionRunning) {
9949 // We have finished the animation of an app transition. To do
9950 // this, we have delayed a lot of operations like showing and
9951 // hiding apps, moving apps in Z-order, etc. The app token list
9952 // reflects the correct Z-order, but the window list may now
9953 // be out of sync with it. So here we will just rebuild the
9954 // entire app window list. Fun!
9955 mAppTransitionRunning = false;
9956 // Clear information about apps that were moving.
9957 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009958
Dianne Hackborna8f60182009-09-01 19:01:50 -07009959 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009960 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009961 moveInputMethodWindowsIfNeededLocked(false);
9962 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009963 // Since the window list has been rebuilt, focus might
9964 // have to be recomputed since the actual order of windows
9965 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009966 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009967 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009968
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009969 int adjResult = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009970
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009971 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009972 // At this point, there was a window with a wallpaper that
9973 // was force hiding other windows behind it, but now it
9974 // is going away. This may be simple -- just animate
9975 // away the wallpaper and its window -- or it may be
9976 // hard -- the wallpaper now needs to be shown behind
9977 // something that was hidden.
9978 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009979 if (mLowerWallpaperTarget != null
9980 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009981 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009982 "wallpaperForceHiding changed with lower="
9983 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009984 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009985 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9986 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9987 if (mLowerWallpaperTarget.mAppToken.hidden) {
9988 // The lower target has become hidden before we
9989 // actually started the animation... let's completely
9990 // re-evaluate everything.
9991 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009992 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009993 }
9994 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009995 adjResult = adjustWallpaperWindowsLocked();
9996 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009997 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009998 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009999 + " NEW: " + mWallpaperTarget
10000 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010001 if (mLowerWallpaperTarget == null) {
10002 // Whoops, we don't need a special wallpaper animation.
10003 // Clear them out.
10004 forceHiding = false;
10005 for (i=N-1; i>=0; i--) {
10006 WindowState w = (WindowState)mWindows.get(i);
10007 if (w.mSurface != null) {
10008 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010009 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010010 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010011 forceHiding = true;
10012 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10013 if (!w.mAnimating) {
10014 // We set the animation above so it
10015 // is not yet running.
10016 w.clearAnimation();
10017 }
10018 }
10019 }
10020 }
10021 }
10022 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010023
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010024 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010025 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010026 "Wallpaper may change! Adjusting");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010027 adjResult = adjustWallpaperWindowsLocked();
10028 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010029
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010030 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010031 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010032 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010033 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010034 assignLayersLocked();
10035 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010036 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010037 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010038 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010039 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010040
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010041 if (mFocusMayChange) {
10042 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010043 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010044 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010045 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010046 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010047 }
10048
10049 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010050 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010051 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010052
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010053 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10054 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010055
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010056 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010057
10058 // THIRD LOOP: Update the surfaces of all windows.
10059
10060 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10061
10062 boolean obscured = false;
10063 boolean blurring = false;
10064 boolean dimming = false;
10065 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010066 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010067 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010068
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010069 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 for (i=N-1; i>=0; i--) {
10072 WindowState w = (WindowState)mWindows.get(i);
10073
10074 boolean displayed = false;
10075 final WindowManager.LayoutParams attrs = w.mAttrs;
10076 final int attrFlags = attrs.flags;
10077
10078 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010079 // XXX NOTE: The logic here could be improved. We have
10080 // the decision about whether to resize a window separated
10081 // from whether to hide the surface. This can cause us to
10082 // resize a surface even if we are going to hide it. You
10083 // can see this by (1) holding device in landscape mode on
10084 // home screen; (2) tapping browser icon (device will rotate
10085 // to landscape; (3) tap home. The wallpaper will be resized
10086 // in step 2 but then immediately hidden, causing us to
10087 // have to resize and then redraw it again in step 3. It
10088 // would be nice to figure out how to avoid this, but it is
10089 // difficult because we do need to resize surfaces in some
10090 // cases while they are hidden such as when first showing a
10091 // window.
10092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010093 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010094 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010095 TAG, "Placing surface #" + i + " " + w.mSurface
10096 + ": new=" + w.mShownFrame + ", old="
10097 + w.mLastShownFrame);
10098
10099 boolean resize;
10100 int width, height;
10101 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10102 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10103 w.mLastRequestedHeight != w.mRequestedHeight;
10104 // for a scaled surface, we just want to use
10105 // the requested size.
10106 width = w.mRequestedWidth;
10107 height = w.mRequestedHeight;
10108 w.mLastRequestedWidth = width;
10109 w.mLastRequestedHeight = height;
10110 w.mLastShownFrame.set(w.mShownFrame);
10111 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010112 if (SHOW_TRANSACTIONS) logSurface(w,
10113 "POS " + w.mShownFrame.left
10114 + ", " + w.mShownFrame.top, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010115 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10116 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010117 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010118 if (!recoveringMemory) {
10119 reclaimSomeSurfaceMemoryLocked(w, "position");
10120 }
10121 }
10122 } else {
10123 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10124 width = w.mShownFrame.width();
10125 height = w.mShownFrame.height();
10126 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010127 }
10128
10129 if (resize) {
10130 if (width < 1) width = 1;
10131 if (height < 1) height = 1;
10132 if (w.mSurface != null) {
10133 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010134 if (SHOW_TRANSACTIONS) logSurface(w,
10135 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010136 + w.mShownFrame.top + " SIZE "
10137 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010138 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010139 w.mSurfaceResized = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010140 w.mSurface.setSize(width, height);
10141 w.mSurface.setPosition(w.mShownFrame.left,
10142 w.mShownFrame.top);
10143 } catch (RuntimeException e) {
10144 // If something goes wrong with the surface (such
10145 // as running out of memory), don't take down the
10146 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010147 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010148 + "size=(" + width + "x" + height
10149 + "), pos=(" + w.mShownFrame.left
10150 + "," + w.mShownFrame.top + ")", e);
10151 if (!recoveringMemory) {
10152 reclaimSomeSurfaceMemoryLocked(w, "size");
10153 }
10154 }
10155 }
10156 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010157 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 w.mContentInsetsChanged =
10159 !w.mLastContentInsets.equals(w.mContentInsets);
10160 w.mVisibleInsetsChanged =
10161 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010162 boolean configChanged =
10163 w.mConfiguration != mCurConfiguration
10164 && (w.mConfiguration == null
10165 || mCurConfiguration.diff(w.mConfiguration) != 0);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010166 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010167 + ": configChanged=" + configChanged
10168 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010169 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010170 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010171 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010172 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010173 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010174 w.mLastFrame.set(w.mFrame);
10175 w.mLastContentInsets.set(w.mContentInsets);
10176 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010177 // If the screen is currently frozen, then keep
10178 // it frozen until this window draws at its new
10179 // orientation.
10180 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010181 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010182 "Resizing while display frozen: " + w);
10183 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010184 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010185 mWindowsFreezingScreen = true;
10186 // XXX should probably keep timeout from
10187 // when we first froze the display.
10188 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10189 mH.sendMessageDelayed(mH.obtainMessage(
10190 H.WINDOW_FREEZE_TIMEOUT), 2000);
10191 }
10192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010193 // If the orientation is changing, then we need to
10194 // hold off on unfreezing the display until this
10195 // window has been redrawn; to do that, we need
10196 // to go through the process of getting informed
10197 // by the application when it has finished drawing.
10198 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010199 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010200 "Orientation start waiting for draw in "
10201 + w + ", surface " + w.mSurface);
10202 w.mDrawPending = true;
10203 w.mCommitDrawPending = false;
10204 w.mReadyToShow = false;
10205 if (w.mAppToken != null) {
10206 w.mAppToken.allDrawn = false;
10207 }
10208 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010209 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010210 "Resizing window " + w + " to " + w.mFrame);
10211 mResizingWindows.add(w);
10212 } else if (w.mOrientationChanging) {
10213 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010214 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010215 "Orientation not waiting for draw in "
10216 + w + ", surface " + w.mSurface);
10217 w.mOrientationChanging = false;
10218 }
10219 }
10220 }
10221
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010222 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010223 if (!w.mLastHidden) {
10224 //dump();
10225 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010226 if (SHOW_TRANSACTIONS) logSurface(w,
10227 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010228 if (w.mSurface != null) {
10229 try {
10230 w.mSurface.hide();
10231 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010232 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010233 }
10234 }
10235 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10236 }
10237 // If we are waiting for this window to handle an
10238 // orientation change, well, it is hidden, so
10239 // doesn't really matter. Note that this does
10240 // introduce a potential glitch if the window
10241 // becomes unhidden before it has drawn for the
10242 // new orientation.
10243 if (w.mOrientationChanging) {
10244 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010245 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010246 "Orientation change skips hidden " + w);
10247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010248 } else if (w.mLastLayer != w.mAnimLayer
10249 || w.mLastAlpha != w.mShownAlpha
10250 || w.mLastDsDx != w.mDsDx
10251 || w.mLastDtDx != w.mDtDx
10252 || w.mLastDsDy != w.mDsDy
10253 || w.mLastDtDy != w.mDtDy
10254 || w.mLastHScale != w.mHScale
10255 || w.mLastVScale != w.mVScale
10256 || w.mLastHidden) {
10257 displayed = true;
10258 w.mLastAlpha = w.mShownAlpha;
10259 w.mLastLayer = w.mAnimLayer;
10260 w.mLastDsDx = w.mDsDx;
10261 w.mLastDtDx = w.mDtDx;
10262 w.mLastDsDy = w.mDsDy;
10263 w.mLastDtDy = w.mDtDy;
10264 w.mLastHScale = w.mHScale;
10265 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010266 if (SHOW_TRANSACTIONS) logSurface(w,
10267 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010268 + " matrix=[" + (w.mDsDx*w.mHScale)
10269 + "," + (w.mDtDx*w.mVScale)
10270 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010271 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 if (w.mSurface != null) {
10273 try {
10274 w.mSurface.setAlpha(w.mShownAlpha);
10275 w.mSurface.setLayer(w.mAnimLayer);
10276 w.mSurface.setMatrix(
10277 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10278 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10279 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010280 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 if (!recoveringMemory) {
10282 reclaimSomeSurfaceMemoryLocked(w, "update");
10283 }
10284 }
10285 }
10286
10287 if (w.mLastHidden && !w.mDrawPending
10288 && !w.mCommitDrawPending
10289 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010290 if (SHOW_TRANSACTIONS) logSurface(w,
10291 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010292 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 + " during relayout");
10294 if (showSurfaceRobustlyLocked(w)) {
10295 w.mHasDrawn = true;
10296 w.mLastHidden = false;
10297 } else {
10298 w.mOrientationChanging = false;
10299 }
10300 }
10301 if (w.mSurface != null) {
10302 w.mToken.hasVisible = true;
10303 }
10304 } else {
10305 displayed = true;
10306 }
10307
10308 if (displayed) {
10309 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010310 if (attrs.width == LayoutParams.MATCH_PARENT
10311 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010312 covered = true;
10313 }
10314 }
10315 if (w.mOrientationChanging) {
10316 if (w.mDrawPending || w.mCommitDrawPending) {
10317 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010318 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010319 "Orientation continue waiting for draw in " + w);
10320 } else {
10321 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010322 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010323 "Orientation change complete in " + w);
10324 }
10325 }
10326 w.mToken.hasVisible = true;
10327 }
10328 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010329 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 "Orientation change skips hidden " + w);
10331 w.mOrientationChanging = false;
10332 }
10333
10334 final boolean canBeSeen = w.isDisplayedLw();
10335
10336 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10337 focusDisplayed = true;
10338 }
10339
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010340 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010342 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010343 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010344 if (w.mSurface != null) {
10345 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10346 holdScreen = w.mSession;
10347 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010348 if (!syswin && w.mAttrs.screenBrightness >= 0
10349 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010350 screenBrightness = w.mAttrs.screenBrightness;
10351 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010352 if (!syswin && w.mAttrs.buttonBrightness >= 0
10353 && buttonBrightness < 0) {
10354 buttonBrightness = w.mAttrs.buttonBrightness;
10355 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010356 if (canBeSeen
10357 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10358 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10359 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010360 syswin = true;
10361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010362 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010363
Dianne Hackborn25994b42009-09-04 14:21:19 -070010364 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10365 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010366 // This window completely covers everything behind it,
10367 // so we want to leave all of them as unblurred (for
10368 // performance reasons).
10369 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010370 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010371 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010372 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010373 obscured = true;
10374 if (mBackgroundFillerSurface == null) {
10375 try {
10376 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010377 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010378 0, dw, dh,
10379 PixelFormat.OPAQUE,
10380 Surface.FX_SURFACE_NORMAL);
10381 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010382 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010383 }
10384 }
10385 try {
10386 mBackgroundFillerSurface.setPosition(0, 0);
10387 mBackgroundFillerSurface.setSize(dw, dh);
10388 // Using the same layer as Dim because they will never be shown at the
10389 // same time.
10390 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10391 mBackgroundFillerSurface.show();
10392 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010393 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010394 }
10395 backgroundFillerShown = true;
10396 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010397 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010399 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010400 + ": blurring=" + blurring
10401 + " obscured=" + obscured
10402 + " displayed=" + displayed);
10403 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10404 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010405 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010406 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010407 if (mDimAnimator == null) {
10408 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010409 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010410 mDimAnimator.show(dw, dh);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010411 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010412 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 }
10414 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10415 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010416 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417 blurring = true;
10418 mBlurShown = true;
10419 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010420 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 + mBlurSurface + ": CREATE");
10422 try {
Romain Guy06882f82009-06-10 13:36:04 -070010423 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010424 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010425 -1, 16, 16,
10426 PixelFormat.OPAQUE,
10427 Surface.FX_SURFACE_BLUR);
10428 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010429 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010430 }
10431 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010432 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433 + mBlurSurface + ": SHOW pos=(0,0) (" +
10434 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
10435 if (mBlurSurface != null) {
10436 mBlurSurface.setPosition(0, 0);
10437 mBlurSurface.setSize(dw, dh);
10438 try {
10439 mBlurSurface.show();
10440 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010441 Slog.w(TAG, "Failure showing blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 }
10443 }
10444 }
10445 mBlurSurface.setLayer(w.mAnimLayer-2);
10446 }
10447 }
10448 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010449
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010450 if (obscuredChanged && mWallpaperTarget == w) {
10451 // This is the wallpaper target and its obscured state
10452 // changed... make sure the current wallaper's visibility
10453 // has been updated accordingly.
10454 updateWallpaperVisibilityLocked();
10455 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010456 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010457
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010458 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10459 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010460 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010461 try {
10462 mBackgroundFillerSurface.hide();
10463 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010464 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010465 }
10466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010467
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010468 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010469 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10470 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010471 }
Romain Guy06882f82009-06-10 13:36:04 -070010472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010474 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 + ": HIDE");
10476 try {
10477 mBlurSurface.hide();
10478 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010479 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010480 }
10481 mBlurShown = false;
10482 }
10483
Joe Onorato8a9b2202010-02-26 18:56:32 -080010484 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010485 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010486 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010487 }
10488
10489 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010490
Joe Onorato8a9b2202010-02-26 18:56:32 -080010491 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010492 "With display frozen, orientationChangeComplete="
10493 + orientationChangeComplete);
10494 if (orientationChangeComplete) {
10495 if (mWindowsFreezingScreen) {
10496 mWindowsFreezingScreen = false;
10497 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10498 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010499 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010500 }
Romain Guy06882f82009-06-10 13:36:04 -070010501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 i = mResizingWindows.size();
10503 if (i > 0) {
10504 do {
10505 i--;
10506 WindowState win = mResizingWindows.get(i);
10507 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010508 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10509 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010510 boolean configChanged =
10511 win.mConfiguration != mCurConfiguration
10512 && (win.mConfiguration == null
10513 || mCurConfiguration.diff(win.mConfiguration) != 0);
10514 win.mConfiguration = mCurConfiguration;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010515 if ((DEBUG_RESIZE || DEBUG_ORIENTATION) && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010516 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010517 + win.mFrame.width() + "x" + win.mFrame.height()
10518 + " / " + win.mConfiguration);
10519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010520 win.mClient.resized(win.mFrame.width(),
10521 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010522 win.mLastVisibleInsets, win.mDrawPending,
10523 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524 win.mContentInsetsChanged = false;
10525 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010526 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010527 } catch (RemoteException e) {
10528 win.mOrientationChanging = false;
10529 }
10530 } while (i > 0);
10531 mResizingWindows.clear();
10532 }
Romain Guy06882f82009-06-10 13:36:04 -070010533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010535 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536 i = mDestroySurface.size();
10537 if (i > 0) {
10538 do {
10539 i--;
10540 WindowState win = mDestroySurface.get(i);
10541 win.mDestroying = false;
10542 if (mInputMethodWindow == win) {
10543 mInputMethodWindow = null;
10544 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010545 if (win == mWallpaperTarget) {
10546 wallpaperDestroyed = true;
10547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010548 win.destroySurfaceLocked();
10549 } while (i > 0);
10550 mDestroySurface.clear();
10551 }
10552
10553 // Time to remove any exiting tokens?
10554 for (i=mExitingTokens.size()-1; i>=0; i--) {
10555 WindowToken token = mExitingTokens.get(i);
10556 if (!token.hasVisible) {
10557 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010558 if (token.windowType == TYPE_WALLPAPER) {
10559 mWallpaperTokens.remove(token);
10560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561 }
10562 }
10563
10564 // Time to remove any exiting applications?
10565 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10566 AppWindowToken token = mExitingAppTokens.get(i);
10567 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010568 // Make sure there is no animation running on this token,
10569 // so any windows associated with it will be removed as
10570 // soon as their animations are complete
10571 token.animation = null;
10572 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 mAppTokens.remove(token);
10574 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010575 if (mLastEnterAnimToken == token) {
10576 mLastEnterAnimToken = null;
10577 mLastEnterAnimParams = null;
10578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010579 }
10580 }
10581
Dianne Hackborna8f60182009-09-01 19:01:50 -070010582 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010583
Dianne Hackborna8f60182009-09-01 19:01:50 -070010584 if (!animating && mAppTransitionRunning) {
10585 // We have finished the animation of an app transition. To do
10586 // this, we have delayed a lot of operations like showing and
10587 // hiding apps, moving apps in Z-order, etc. The app token list
10588 // reflects the correct Z-order, but the window list may now
10589 // be out of sync with it. So here we will just rebuild the
10590 // entire app window list. Fun!
10591 mAppTransitionRunning = false;
10592 needRelayout = true;
10593 rebuildAppWindowListLocked();
10594 // Clear information about apps that were moving.
10595 mToBottomApps.clear();
10596 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010598 if (focusDisplayed) {
10599 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10600 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010601 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010602 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010603 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010604 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010605 requestAnimationLocked(0);
10606 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010607 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10608 }
10609 mQueue.setHoldScreenLocked(holdScreen != null);
10610 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10611 mPowerManager.setScreenBrightnessOverride(-1);
10612 } else {
10613 mPowerManager.setScreenBrightnessOverride((int)
10614 (screenBrightness * Power.BRIGHTNESS_ON));
10615 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010616 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10617 mPowerManager.setButtonBrightnessOverride(-1);
10618 } else {
10619 mPowerManager.setButtonBrightnessOverride((int)
10620 (buttonBrightness * Power.BRIGHTNESS_ON));
10621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010622 if (holdScreen != mHoldingScreenOn) {
10623 mHoldingScreenOn = holdScreen;
10624 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10625 mH.sendMessage(m);
10626 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010627
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010628 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010629 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010630 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10631 LocalPowerManager.BUTTON_EVENT, true);
10632 mTurnOnScreen = false;
10633 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010634
10635 // Check to see if we are now in a state where the screen should
10636 // be enabled, because the window obscured flags have changed.
10637 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010638 }
10639
10640 void requestAnimationLocked(long delay) {
10641 if (!mAnimationPending) {
10642 mAnimationPending = true;
10643 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10644 }
10645 }
Romain Guy06882f82009-06-10 13:36:04 -070010646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 /**
10648 * Have the surface flinger show a surface, robustly dealing with
10649 * error conditions. In particular, if there is not enough memory
10650 * to show the surface, then we will try to get rid of other surfaces
10651 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010652 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010653 * @return Returns true if the surface was successfully shown.
10654 */
10655 boolean showSurfaceRobustlyLocked(WindowState win) {
10656 try {
10657 if (win.mSurface != null) {
10658 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010659 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010660 if (DEBUG_VISIBILITY) Slog.v(TAG,
10661 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010662 win.mTurnOnScreen = false;
10663 mTurnOnScreen = true;
10664 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010665 }
10666 return true;
10667 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010668 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010669 }
Romain Guy06882f82009-06-10 13:36:04 -070010670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010671 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010673 return false;
10674 }
Romain Guy06882f82009-06-10 13:36:04 -070010675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010676 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10677 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010678
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010679 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010680 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010682 if (mForceRemoves == null) {
10683 mForceRemoves = new ArrayList<WindowState>();
10684 }
Romain Guy06882f82009-06-10 13:36:04 -070010685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010686 long callingIdentity = Binder.clearCallingIdentity();
10687 try {
10688 // There was some problem... first, do a sanity check of the
10689 // window list to make sure we haven't left any dangling surfaces
10690 // around.
10691 int N = mWindows.size();
10692 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010693 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010694 for (int i=0; i<N; i++) {
10695 WindowState ws = (WindowState)mWindows.get(i);
10696 if (ws.mSurface != null) {
10697 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010698 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010699 + ws + " surface=" + ws.mSurface
10700 + " token=" + win.mToken
10701 + " pid=" + ws.mSession.mPid
10702 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010703 ws.mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010704 ws.mSurface = null;
10705 mForceRemoves.add(ws);
10706 i--;
10707 N--;
10708 leakedSurface = true;
10709 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010710 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010711 + ws + " surface=" + ws.mSurface
10712 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010713 ws.mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010714 ws.mSurface = null;
10715 leakedSurface = true;
10716 }
10717 }
10718 }
Romain Guy06882f82009-06-10 13:36:04 -070010719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010720 boolean killedApps = false;
10721 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010722 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010723 SparseIntArray pidCandidates = new SparseIntArray();
10724 for (int i=0; i<N; i++) {
10725 WindowState ws = (WindowState)mWindows.get(i);
10726 if (ws.mSurface != null) {
10727 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10728 }
10729 }
10730 if (pidCandidates.size() > 0) {
10731 int[] pids = new int[pidCandidates.size()];
10732 for (int i=0; i<pids.length; i++) {
10733 pids[i] = pidCandidates.keyAt(i);
10734 }
10735 try {
10736 if (mActivityManager.killPidsForMemory(pids)) {
10737 killedApps = true;
10738 }
10739 } catch (RemoteException e) {
10740 }
10741 }
10742 }
Romain Guy06882f82009-06-10 13:36:04 -070010743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010744 if (leakedSurface || killedApps) {
10745 // We managed to reclaim some memory, so get rid of the trouble
10746 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010747 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010748 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010749 surface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010750 win.mSurface = null;
10751 }
Romain Guy06882f82009-06-10 13:36:04 -070010752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010753 try {
10754 win.mClient.dispatchGetNewSurface();
10755 } catch (RemoteException e) {
10756 }
10757 }
10758 } finally {
10759 Binder.restoreCallingIdentity(callingIdentity);
10760 }
10761 }
Romain Guy06882f82009-06-10 13:36:04 -070010762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010763 private boolean updateFocusedWindowLocked(int mode) {
10764 WindowState newFocus = computeFocusedWindowLocked();
10765 if (mCurrentFocus != newFocus) {
10766 // This check makes sure that we don't already have the focus
10767 // change message pending.
10768 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10769 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010770 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010771 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10772 final WindowState oldFocus = mCurrentFocus;
10773 mCurrentFocus = newFocus;
10774 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010776 final WindowState imWindow = mInputMethodWindow;
10777 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010778 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010780 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10781 mLayoutNeeded = true;
10782 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010783 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10784 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010785 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10786 // Client will do the layout, but we need to assign layers
10787 // for handleNewWindowLocked() below.
10788 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010789 }
10790 }
Romain Guy06882f82009-06-10 13:36:04 -070010791
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010792 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10793 mKeyWaiter.handleNewWindowLocked(newFocus);
10794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010795 return true;
10796 }
10797 return false;
10798 }
10799
10800 private WindowState computeFocusedWindowLocked() {
10801 WindowState result = null;
10802 WindowState win;
10803
10804 int i = mWindows.size() - 1;
10805 int nextAppIndex = mAppTokens.size()-1;
10806 WindowToken nextApp = nextAppIndex >= 0
10807 ? mAppTokens.get(nextAppIndex) : null;
10808
10809 while (i >= 0) {
10810 win = (WindowState)mWindows.get(i);
10811
Joe Onorato8a9b2202010-02-26 18:56:32 -080010812 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010813 TAG, "Looking for focus: " + i
10814 + " = " + win
10815 + ", flags=" + win.mAttrs.flags
10816 + ", canReceive=" + win.canReceiveKeys());
10817
10818 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010820 // If this window's application has been removed, just skip it.
10821 if (thisApp != null && thisApp.removed) {
10822 i--;
10823 continue;
10824 }
Romain Guy06882f82009-06-10 13:36:04 -070010825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010826 // If there is a focused app, don't allow focus to go to any
10827 // windows below it. If this is an application window, step
10828 // through the app tokens until we find its app.
10829 if (thisApp != null && nextApp != null && thisApp != nextApp
10830 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10831 int origAppIndex = nextAppIndex;
10832 while (nextAppIndex > 0) {
10833 if (nextApp == mFocusedApp) {
10834 // Whoops, we are below the focused app... no focus
10835 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010836 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010837 TAG, "Reached focused app: " + mFocusedApp);
10838 return null;
10839 }
10840 nextAppIndex--;
10841 nextApp = mAppTokens.get(nextAppIndex);
10842 if (nextApp == thisApp) {
10843 break;
10844 }
10845 }
10846 if (thisApp != nextApp) {
10847 // Uh oh, the app token doesn't exist! This shouldn't
10848 // happen, but if it does we can get totally hosed...
10849 // so restart at the original app.
10850 nextAppIndex = origAppIndex;
10851 nextApp = mAppTokens.get(nextAppIndex);
10852 }
10853 }
10854
10855 // Dispatch to this window if it is wants key events.
10856 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010857 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010858 TAG, "Found focus @ " + i + " = " + win);
10859 result = win;
10860 break;
10861 }
10862
10863 i--;
10864 }
10865
10866 return result;
10867 }
10868
10869 private void startFreezingDisplayLocked() {
10870 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010871 // Freezing the display also suspends key event delivery, to
10872 // keep events from going astray while the display is reconfigured.
10873 // If someone has changed orientation again while the screen is
10874 // still frozen, the events will continue to be blocked while the
10875 // successive orientation change is processed. To prevent spurious
10876 // ANRs, we reset the event dispatch timeout in this case.
10877 synchronized (mKeyWaiter) {
10878 mKeyWaiter.mWasFrozen = true;
10879 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010880 return;
10881 }
Romain Guy06882f82009-06-10 13:36:04 -070010882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010883 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010885 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010886 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010887 if (mFreezeGcPending != 0) {
10888 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010889 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010890 mH.removeMessages(H.FORCE_GC);
10891 Runtime.getRuntime().gc();
10892 mFreezeGcPending = now;
10893 }
10894 } else {
10895 mFreezeGcPending = now;
10896 }
Romain Guy06882f82009-06-10 13:36:04 -070010897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010899 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10900 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010901 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010902 mAppTransitionReady = true;
10903 }
Romain Guy06882f82009-06-10 13:36:04 -070010904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010905 if (PROFILE_ORIENTATION) {
10906 File file = new File("/data/system/frozen");
10907 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10908 }
10909 Surface.freezeDisplay(0);
10910 }
Romain Guy06882f82009-06-10 13:36:04 -070010911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010912 private void stopFreezingDisplayLocked() {
10913 if (!mDisplayFrozen) {
10914 return;
10915 }
Romain Guy06882f82009-06-10 13:36:04 -070010916
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010917 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10918 return;
10919 }
10920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010921 mDisplayFrozen = false;
10922 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10923 if (PROFILE_ORIENTATION) {
10924 Debug.stopMethodTracing();
10925 }
10926 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010927
Chris Tate2ad63a92009-03-25 17:36:48 -070010928 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
10929 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010930 synchronized (mKeyWaiter) {
10931 mKeyWaiter.mWasFrozen = true;
10932 mKeyWaiter.notifyAll();
10933 }
10934
10935 // A little kludge: a lot could have happened while the
10936 // display was frozen, so now that we are coming back we
10937 // do a gc so that any remote references the system
10938 // processes holds on others can be released if they are
10939 // no longer needed.
10940 mH.removeMessages(H.FORCE_GC);
10941 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10942 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010944 mScreenFrozenLock.release();
10945 }
Romain Guy06882f82009-06-10 13:36:04 -070010946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010947 @Override
10948 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10949 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10950 != PackageManager.PERMISSION_GRANTED) {
10951 pw.println("Permission Denial: can't dump WindowManager from from pid="
10952 + Binder.getCallingPid()
10953 + ", uid=" + Binder.getCallingUid());
10954 return;
10955 }
Romain Guy06882f82009-06-10 13:36:04 -070010956
Dianne Hackborna2e92262010-03-02 17:19:29 -080010957 pw.println("Input State:");
10958 mQueue.dump(pw, " ");
10959 pw.println(" ");
10960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010961 synchronized(mWindowMap) {
10962 pw.println("Current Window Manager state:");
10963 for (int i=mWindows.size()-1; i>=0; i--) {
10964 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010965 pw.print(" Window #"); pw.print(i); pw.print(' ');
10966 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010967 w.dump(pw, " ");
10968 }
10969 if (mInputMethodDialogs.size() > 0) {
10970 pw.println(" ");
10971 pw.println(" Input method dialogs:");
10972 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10973 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010974 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010975 }
10976 }
10977 if (mPendingRemove.size() > 0) {
10978 pw.println(" ");
10979 pw.println(" Remove pending for:");
10980 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10981 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010982 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10983 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010984 w.dump(pw, " ");
10985 }
10986 }
10987 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10988 pw.println(" ");
10989 pw.println(" Windows force removing:");
10990 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10991 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010992 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10993 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010994 w.dump(pw, " ");
10995 }
10996 }
10997 if (mDestroySurface.size() > 0) {
10998 pw.println(" ");
10999 pw.println(" Windows waiting to destroy their surface:");
11000 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11001 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011002 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11003 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011004 w.dump(pw, " ");
11005 }
11006 }
11007 if (mLosingFocus.size() > 0) {
11008 pw.println(" ");
11009 pw.println(" Windows losing focus:");
11010 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11011 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011012 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11013 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011014 w.dump(pw, " ");
11015 }
11016 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011017 if (mResizingWindows.size() > 0) {
11018 pw.println(" ");
11019 pw.println(" Windows waiting to resize:");
11020 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11021 WindowState w = mResizingWindows.get(i);
11022 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11023 pw.print(w); pw.println(":");
11024 w.dump(pw, " ");
11025 }
11026 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011027 if (mSessions.size() > 0) {
11028 pw.println(" ");
11029 pw.println(" All active sessions:");
11030 Iterator<Session> it = mSessions.iterator();
11031 while (it.hasNext()) {
11032 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011033 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011034 s.dump(pw, " ");
11035 }
11036 }
11037 if (mTokenMap.size() > 0) {
11038 pw.println(" ");
11039 pw.println(" All tokens:");
11040 Iterator<WindowToken> it = mTokenMap.values().iterator();
11041 while (it.hasNext()) {
11042 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011043 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011044 token.dump(pw, " ");
11045 }
11046 }
11047 if (mTokenList.size() > 0) {
11048 pw.println(" ");
11049 pw.println(" Window token list:");
11050 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011051 pw.print(" #"); pw.print(i); pw.print(": ");
11052 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011053 }
11054 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011055 if (mWallpaperTokens.size() > 0) {
11056 pw.println(" ");
11057 pw.println(" Wallpaper tokens:");
11058 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11059 WindowToken token = mWallpaperTokens.get(i);
11060 pw.print(" Wallpaper #"); pw.print(i);
11061 pw.print(' '); pw.print(token); pw.println(':');
11062 token.dump(pw, " ");
11063 }
11064 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011065 if (mAppTokens.size() > 0) {
11066 pw.println(" ");
11067 pw.println(" Application tokens in Z order:");
11068 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011069 pw.print(" App #"); pw.print(i); pw.print(": ");
11070 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011071 }
11072 }
11073 if (mFinishedStarting.size() > 0) {
11074 pw.println(" ");
11075 pw.println(" Finishing start of application tokens:");
11076 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11077 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011078 pw.print(" Finished Starting #"); pw.print(i);
11079 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011080 token.dump(pw, " ");
11081 }
11082 }
11083 if (mExitingTokens.size() > 0) {
11084 pw.println(" ");
11085 pw.println(" Exiting tokens:");
11086 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11087 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011088 pw.print(" Exiting #"); pw.print(i);
11089 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011090 token.dump(pw, " ");
11091 }
11092 }
11093 if (mExitingAppTokens.size() > 0) {
11094 pw.println(" ");
11095 pw.println(" Exiting application tokens:");
11096 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11097 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011098 pw.print(" Exiting App #"); pw.print(i);
11099 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011100 token.dump(pw, " ");
11101 }
11102 }
11103 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011104 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11105 pw.print(" mLastFocus="); pw.println(mLastFocus);
11106 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11107 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11108 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011109 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011110 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11111 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11112 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11113 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011114 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11115 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11116 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011117 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11118 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11119 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11120 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011121 if (mDimAnimator != null) {
11122 mDimAnimator.printTo(pw);
11123 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011124 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011125 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011126 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011127 pw.print(mInputMethodAnimLayerAdjustment);
11128 pw.print(" mWallpaperAnimLayerAdjustment=");
11129 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011130 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11131 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011132 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11133 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011134 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11135 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011136 pw.print(" mRotation="); pw.print(mRotation);
11137 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11138 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11139 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11140 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11141 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11142 pw.print(" mNextAppTransition=0x");
11143 pw.print(Integer.toHexString(mNextAppTransition));
11144 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011145 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011146 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011147 if (mNextAppTransitionPackage != null) {
11148 pw.print(" mNextAppTransitionPackage=");
11149 pw.print(mNextAppTransitionPackage);
11150 pw.print(", mNextAppTransitionEnter=0x");
11151 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11152 pw.print(", mNextAppTransitionExit=0x");
11153 pw.print(Integer.toHexString(mNextAppTransitionExit));
11154 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011155 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11156 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011157 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11158 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11159 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11160 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011161 if (mOpeningApps.size() > 0) {
11162 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11163 }
11164 if (mClosingApps.size() > 0) {
11165 pw.print(" mClosingApps="); pw.println(mClosingApps);
11166 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011167 if (mToTopApps.size() > 0) {
11168 pw.print(" mToTopApps="); pw.println(mToTopApps);
11169 }
11170 if (mToBottomApps.size() > 0) {
11171 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11172 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011173 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11174 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011175 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011176 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
11177 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
11178 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
11179 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
11180 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
11181 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011182 }
11183 }
11184
11185 public void monitor() {
11186 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011187 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011188 synchronized (mKeyWaiter) { }
11189 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011190
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011191 public void virtualKeyFeedback(KeyEvent event) {
11192 mPolicy.keyFeedbackFromInput(event);
11193 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011194
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011195 /**
11196 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011197 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011198 */
11199 private static class DimAnimator {
11200 Surface mDimSurface;
11201 boolean mDimShown = false;
11202 float mDimCurrentAlpha;
11203 float mDimTargetAlpha;
11204 float mDimDeltaPerMs;
11205 long mLastDimAnimTime;
11206
11207 DimAnimator (SurfaceSession session) {
11208 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011209 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011210 + mDimSurface + ": CREATE");
11211 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011212 mDimSurface = new Surface(session, 0,
11213 "DimSurface",
11214 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011215 Surface.FX_SURFACE_DIM);
11216 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011217 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011218 }
11219 }
11220 }
11221
11222 /**
11223 * Show the dim surface.
11224 */
11225 void show(int dw, int dh) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011226 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011227 dw + "x" + dh + ")");
11228 mDimShown = true;
11229 try {
11230 mDimSurface.setPosition(0, 0);
11231 mDimSurface.setSize(dw, dh);
11232 mDimSurface.show();
11233 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011234 Slog.w(TAG, "Failure showing dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011235 }
11236 }
11237
11238 /**
11239 * Set's the dim surface's layer and update dim parameters that will be used in
11240 * {@link updateSurface} after all windows are examined.
11241 */
11242 void updateParameters(WindowState w, long currentTime) {
11243 mDimSurface.setLayer(w.mAnimLayer-1);
11244
11245 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011246 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011247 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011248 if (mDimTargetAlpha != target) {
11249 // If the desired dim level has changed, then
11250 // start an animation to it.
11251 mLastDimAnimTime = currentTime;
11252 long duration = (w.mAnimating && w.mAnimation != null)
11253 ? w.mAnimation.computeDurationHint()
11254 : DEFAULT_DIM_DURATION;
11255 if (target > mDimTargetAlpha) {
11256 // This is happening behind the activity UI,
11257 // so we can make it run a little longer to
11258 // give a stronger impression without disrupting
11259 // the user.
11260 duration *= DIM_DURATION_MULTIPLIER;
11261 }
11262 if (duration < 1) {
11263 // Don't divide by zero
11264 duration = 1;
11265 }
11266 mDimTargetAlpha = target;
11267 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11268 }
11269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011270
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011271 /**
11272 * Updating the surface's alpha. Returns true if the animation continues, or returns
11273 * false when the animation is finished and the dim surface is hidden.
11274 */
11275 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11276 if (!dimming) {
11277 if (mDimTargetAlpha != 0) {
11278 mLastDimAnimTime = currentTime;
11279 mDimTargetAlpha = 0;
11280 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11281 }
11282 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011283
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011284 boolean animating = false;
11285 if (mLastDimAnimTime != 0) {
11286 mDimCurrentAlpha += mDimDeltaPerMs
11287 * (currentTime-mLastDimAnimTime);
11288 boolean more = true;
11289 if (displayFrozen) {
11290 // If the display is frozen, there is no reason to animate.
11291 more = false;
11292 } else if (mDimDeltaPerMs > 0) {
11293 if (mDimCurrentAlpha > mDimTargetAlpha) {
11294 more = false;
11295 }
11296 } else if (mDimDeltaPerMs < 0) {
11297 if (mDimCurrentAlpha < mDimTargetAlpha) {
11298 more = false;
11299 }
11300 } else {
11301 more = false;
11302 }
11303
11304 // Do we need to continue animating?
11305 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011306 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011307 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11308 mLastDimAnimTime = currentTime;
11309 mDimSurface.setAlpha(mDimCurrentAlpha);
11310 animating = true;
11311 } else {
11312 mDimCurrentAlpha = mDimTargetAlpha;
11313 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011314 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011315 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11316 mDimSurface.setAlpha(mDimCurrentAlpha);
11317 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011318 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011319 + ": HIDE");
11320 try {
11321 mDimSurface.hide();
11322 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011323 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011324 }
11325 mDimShown = false;
11326 }
11327 }
11328 }
11329 return animating;
11330 }
11331
11332 public void printTo(PrintWriter pw) {
11333 pw.print(" mDimShown="); pw.print(mDimShown);
11334 pw.print(" current="); pw.print(mDimCurrentAlpha);
11335 pw.print(" target="); pw.print(mDimTargetAlpha);
11336 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11337 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11338 }
11339 }
11340
11341 /**
11342 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11343 * This is used for opening/closing transition for apps in compatible mode.
11344 */
11345 private static class FadeInOutAnimation extends Animation {
11346 int mWidth;
11347 boolean mFadeIn;
11348
11349 public FadeInOutAnimation(boolean fadeIn) {
11350 setInterpolator(new AccelerateInterpolator());
11351 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11352 mFadeIn = fadeIn;
11353 }
11354
11355 @Override
11356 protected void applyTransformation(float interpolatedTime, Transformation t) {
11357 float x = interpolatedTime;
11358 if (!mFadeIn) {
11359 x = 1.0f - x; // reverse the interpolation for fade out
11360 }
11361 if (x < 0.5) {
11362 // move the window out of the screen.
11363 t.getMatrix().setTranslate(mWidth, 0);
11364 } else {
11365 t.getMatrix().setTranslate(0, 0);// show
11366 t.setAlpha((x - 0.5f) * 2);
11367 }
11368 }
11369
11370 @Override
11371 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11372 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11373 mWidth = width;
11374 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011375
11376 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011377 public int getZAdjustment() {
11378 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011379 }
11380 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011381}