blob: b82ec0197cb8ed56e6dafd5aefc16a0640b5480f [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.am.BatteryStatsService;
52
53import android.Manifest;
54import android.app.ActivityManagerNative;
55import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070056import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070057import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070059import android.content.Intent;
60import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.pm.ActivityInfo;
62import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.content.res.Configuration;
65import android.graphics.Matrix;
66import android.graphics.PixelFormat;
67import android.graphics.Rect;
68import android.graphics.Region;
69import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070075import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.LocalPowerManager;
77import android.os.Looper;
78import android.os.Message;
79import android.os.Parcel;
80import android.os.ParcelFileDescriptor;
81import android.os.Power;
82import android.os.PowerManager;
83import android.os.Process;
84import android.os.RemoteException;
85import android.os.ServiceManager;
86import android.os.SystemClock;
87import android.os.SystemProperties;
88import android.os.TokenWatcher;
89import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070090import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070092import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080093import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.SparseIntArray;
95import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700106import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107import android.view.KeyEvent;
108import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109import android.view.Surface;
110import android.view.SurfaceSession;
111import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700112import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.ViewTreeObserver;
114import android.view.WindowManager;
115import android.view.WindowManagerImpl;
116import android.view.WindowManagerPolicy;
117import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700118import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119import android.view.animation.Animation;
120import android.view.animation.AnimationUtils;
121import android.view.animation.Transformation;
122
123import java.io.BufferedWriter;
124import java.io.File;
125import java.io.FileDescriptor;
126import java.io.IOException;
127import java.io.OutputStream;
128import java.io.OutputStreamWriter;
129import java.io.PrintWriter;
130import java.io.StringWriter;
131import java.net.Socket;
132import java.util.ArrayList;
133import java.util.HashMap;
134import java.util.HashSet;
135import java.util.Iterator;
136import java.util.List;
137
138/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700139public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700140 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
143 static final boolean DEBUG_FOCUS = false;
144 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800145 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800146 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 static final boolean DEBUG_LAYERS = false;
148 static final boolean DEBUG_INPUT = false;
149 static final boolean DEBUG_INPUT_METHOD = false;
150 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700151 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700153 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 static final boolean DEBUG_APP_TRANSITIONS = false;
155 static final boolean DEBUG_STARTING_WINDOW = false;
156 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700157 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700159 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700160 static final boolean MEASURE_LATENCY = false;
161 static private LatencyTimer lt;
162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean PROFILE_ORIENTATION = false;
164 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700165 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 /** How much to multiply the policy's type layer, to reserve room
168 * for multiple windows of the same type and Z-ordering adjustment
169 * with TYPE_LAYER_OFFSET. */
170 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
173 * or below others in the same layer. */
174 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** How much to increment the layer for each window, to reserve room
177 * for effect surfaces between them.
178 */
179 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /** The maximum length we will accept for a loaded animation duration:
182 * this is 10 seconds.
183 */
184 static final int MAX_ANIMATION_DURATION = 10*1000;
185
186 /** Amount of time (in milliseconds) to animate the dim surface from one
187 * value to another, when no window animation is driving it.
188 */
189 static final int DEFAULT_DIM_DURATION = 200;
190
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700191 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
192 * compatible windows.
193 */
194 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 /** Adjustment to time to perform a dim, to make it more dramatic.
197 */
198 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700199
200 // Maximum number of milliseconds to wait for input event injection.
201 // FIXME is this value reasonable?
202 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700203
204 // Default input dispatching timeout in nanoseconds.
205 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 static final int UPDATE_FOCUS_NORMAL = 0;
208 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
209 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
210 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700213 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214
215 /**
216 * Condition waited on by {@link #reenableKeyguard} to know the call to
217 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500218 * This is set to true only if mKeyguardTokenWatcher.acquired() has
219 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500221 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222
Jim Miller284b62e2010-06-08 14:27:42 -0700223 private static final int ALLOW_DISABLE_YES = 1;
224 private static final int ALLOW_DISABLE_NO = 0;
225 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
226 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
227
Mike Lockwood983ee092009-11-22 01:42:24 -0500228 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
229 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700231 if (shouldAllowDisableKeyguard()) {
232 mPolicy.enableKeyguard(false);
233 mKeyguardDisabled = true;
234 } else {
235 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 }
238 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700239 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500240 synchronized (mKeyguardTokenWatcher) {
241 mKeyguardDisabled = false;
242 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 }
244 }
245 };
246
Jim Miller284b62e2010-06-08 14:27:42 -0700247 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
248 @Override
249 public void onReceive(Context context, Intent intent) {
250 mPolicy.enableKeyguard(true);
251 synchronized(mKeyguardTokenWatcher) {
252 // lazily evaluate this next time we're asked to disable keyguard
253 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
254 mKeyguardDisabled = false;
255 }
256 }
257 };
258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 final Context mContext;
260
261 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
266
267 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 /**
272 * All currently active sessions with clients.
273 */
274 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 /**
277 * Mapping from an IWindow IBinder to the server's Window object.
278 * This is also used as the lock for all of our state.
279 */
280 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
281
282 /**
283 * Mapping from a token IBinder to a WindowToken object.
284 */
285 final HashMap<IBinder, WindowToken> mTokenMap =
286 new HashMap<IBinder, WindowToken>();
287
288 /**
289 * The same tokens as mTokenMap, stored in a list for efficient iteration
290 * over them.
291 */
292 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 /**
295 * Window tokens that are in the process of exiting, but still
296 * on screen for animations.
297 */
298 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
299
300 /**
301 * Z-ordered (bottom-most first) list of all application tokens, for
302 * controlling the ordering of windows in different applications. This
303 * contains WindowToken objects.
304 */
305 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
306
307 /**
308 * Application tokens that are in the process of exiting, but still
309 * on screen for animations.
310 */
311 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
312
313 /**
314 * List of window tokens that have finished starting their application,
315 * and now need to have the policy remove their windows.
316 */
317 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
318
319 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700320 * This was the app token that was used to retrieve the last enter
321 * animation. It will be used for the next exit animation.
322 */
323 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800324
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700325 /**
326 * These were the layout params used to retrieve the last enter animation.
327 * They will be used for the next exit animation.
328 */
329 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800330
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700331 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 * Z-ordered (bottom-most first) list of all Window objects.
333 */
Jeff Browne33348b2010-07-15 23:54:05 -0700334 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335
336 /**
337 * Windows that are being resized. Used so we can tell the client about
338 * the resize after closing the transaction in which we resized the
339 * underlying surface.
340 */
341 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
342
343 /**
344 * Windows whose animations have ended and now must be removed.
345 */
346 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
347
348 /**
349 * Windows whose surface should be destroyed.
350 */
351 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
352
353 /**
354 * Windows that have lost input focus and are waiting for the new
355 * focus window to be displayed before they are told about this.
356 */
357 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
358
359 /**
360 * This is set when we have run out of memory, and will either be an empty
361 * list or contain windows that need to be force removed.
362 */
363 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700368 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 Surface mBlurSurface;
370 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 final float[] mTmpFloats = new float[9];
375
376 boolean mSafeMode;
377 boolean mDisplayEnabled = false;
378 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700379 int mInitialDisplayWidth = 0;
380 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 int mRotation = 0;
382 int mRequestedRotation = 0;
383 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700384 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 ArrayList<IRotationWatcher> mRotationWatchers
386 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 boolean mLayoutNeeded = true;
389 boolean mAnimationPending = false;
390 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800391 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 boolean mWindowsFreezingScreen = false;
393 long mFreezeGcPending = 0;
394 int mAppsFreezingScreen = 0;
395
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800396 int mLayoutSeq = 0;
397
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800398 // State while inside of layoutAndPlaceSurfacesLocked().
399 boolean mFocusMayChange;
400
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800401 Configuration mCurConfiguration = new Configuration();
402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 // This is held as long as we have the screen frozen, to give us time to
404 // perform a rotation animation when turning off shows the lock screen which
405 // changes the orientation.
406 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 // State management of app transitions. When we are preparing for a
409 // transition, mNextAppTransition will be the kind of transition to
410 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
411 // mOpeningApps and mClosingApps are the lists of tokens that will be
412 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700413 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700414 String mNextAppTransitionPackage;
415 int mNextAppTransitionEnter;
416 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700418 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 boolean mAppTransitionTimeout = false;
420 boolean mStartingIconInTransition = false;
421 boolean mSkipAppTransitionAnimation = false;
422 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
423 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700424 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
425 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 H mH = new H();
430
431 WindowState mCurrentFocus = null;
432 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 // This just indicates the window the input method is on top of, not
435 // necessarily the window its input is going to.
436 WindowState mInputMethodTarget = null;
437 WindowState mUpcomingInputMethodTarget = null;
438 boolean mInputMethodTargetWaitingAnim;
439 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 WindowState mInputMethodWindow = null;
442 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
443
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700444 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800445
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700446 // If non-null, this is the currently visible window that is associated
447 // with the wallpaper.
448 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700449 // If non-null, we are in the middle of animating from one wallpaper target
450 // to another, and this is the lower one in Z-order.
451 WindowState mLowerWallpaperTarget = null;
452 // If non-null, we are in the middle of animating from one wallpaper target
453 // to another, and this is the higher one in Z-order.
454 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700455 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700456 float mLastWallpaperX = -1;
457 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800458 float mLastWallpaperXStep = -1;
459 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700460 // This is set when we are waiting for a wallpaper to tell us it is done
461 // changing its scroll position.
462 WindowState mWaitingOnWallpaper;
463 // The last time we had a timeout when waiting for a wallpaper.
464 long mLastWallpaperTimeoutTime;
465 // We give a wallpaper up to 150ms to finish scrolling.
466 static final long WALLPAPER_TIMEOUT = 150;
467 // Time we wait after a timeout before trying to wait again.
468 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 AppWindowToken mFocusedApp = null;
471
472 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 float mWindowAnimationScale = 1.0f;
475 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700476
Jeff Brown46b9ac02010-04-22 18:58:52 -0700477 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478
479 // Who is holding the screen on.
480 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700481 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700482
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700483 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 /**
486 * Whether the UI is currently running in touch mode (not showing
487 * navigational focus because the user is directly pressing the screen).
488 */
489 boolean mInTouchMode = false;
490
491 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700492 private ArrayList<WindowChangeListener> mWindowChangeListeners =
493 new ArrayList<WindowChangeListener>();
494 private boolean mWindowsChanged = false;
495
496 public interface WindowChangeListener {
497 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700498 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700499 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500
Dianne Hackbornc485a602009-03-24 22:39:49 -0700501 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700502 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700503
504 // The frame use to limit the size of the app running in compatibility mode.
505 Rect mCompatibleScreenFrame = new Rect();
506 // The surface used to fill the outer rim of the app running in compatibility mode.
507 Surface mBackgroundFillerSurface = null;
508 boolean mBackgroundFillerShown = false;
509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 public static WindowManagerService main(Context context,
511 PowerManagerService pm, boolean haveInputMethods) {
512 WMThread thr = new WMThread(context, pm, haveInputMethods);
513 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 synchronized (thr) {
516 while (thr.mService == null) {
517 try {
518 thr.wait();
519 } catch (InterruptedException e) {
520 }
521 }
522 }
Romain Guy06882f82009-06-10 13:36:04 -0700523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 return thr.mService;
525 }
Romain Guy06882f82009-06-10 13:36:04 -0700526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 static class WMThread extends Thread {
528 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 private final Context mContext;
531 private final PowerManagerService mPM;
532 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 public WMThread(Context context, PowerManagerService pm,
535 boolean haveInputMethods) {
536 super("WindowManager");
537 mContext = context;
538 mPM = pm;
539 mHaveInputMethods = haveInputMethods;
540 }
Romain Guy06882f82009-06-10 13:36:04 -0700541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 public void run() {
543 Looper.prepare();
544 WindowManagerService s = new WindowManagerService(mContext, mPM,
545 mHaveInputMethods);
546 android.os.Process.setThreadPriority(
547 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700548 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 synchronized (this) {
551 mService = s;
552 notifyAll();
553 }
Romain Guy06882f82009-06-10 13:36:04 -0700554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 Looper.loop();
556 }
557 }
558
559 static class PolicyThread extends Thread {
560 private final WindowManagerPolicy mPolicy;
561 private final WindowManagerService mService;
562 private final Context mContext;
563 private final PowerManagerService mPM;
564 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 public PolicyThread(WindowManagerPolicy policy,
567 WindowManagerService service, Context context,
568 PowerManagerService pm) {
569 super("WindowManagerPolicy");
570 mPolicy = policy;
571 mService = service;
572 mContext = context;
573 mPM = pm;
574 }
Romain Guy06882f82009-06-10 13:36:04 -0700575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 public void run() {
577 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800578 WindowManagerPolicyThread.set(this, Looper.myLooper());
579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800581 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 android.os.Process.setThreadPriority(
583 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700584 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 synchronized (this) {
588 mRunning = true;
589 notifyAll();
590 }
Romain Guy06882f82009-06-10 13:36:04 -0700591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 Looper.loop();
593 }
594 }
595
596 private WindowManagerService(Context context, PowerManagerService pm,
597 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700598 if (MEASURE_LATENCY) {
599 lt = new LatencyTimer(100, 1000);
600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 mContext = context;
603 mHaveInputMethods = haveInputMethods;
604 mLimitedAlphaCompositing = context.getResources().getBoolean(
605 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 mPowerManager = pm;
608 mPowerManager.setPolicy(mPolicy);
609 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
610 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
611 "SCREEN_FROZEN");
612 mScreenFrozenLock.setReferenceCounted(false);
613
614 mActivityManager = ActivityManagerNative.getDefault();
615 mBatteryStats = BatteryStatsService.getService();
616
617 // Get persisted window scale setting
618 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
619 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
620 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
621 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700622
Jim Miller284b62e2010-06-08 14:27:42 -0700623 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
624 IntentFilter filter = new IntentFilter();
625 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
626 mContext.registerReceiver(mBroadcastReceiver, filter);
627
Jeff Brown46b9ac02010-04-22 18:58:52 -0700628 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
629 "KEEP_SCREEN_ON_FLAG");
630 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631
Jeff Browne33348b2010-07-15 23:54:05 -0700632 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
635 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 synchronized (thr) {
638 while (!thr.mRunning) {
639 try {
640 thr.wait();
641 } catch (InterruptedException e) {
642 }
643 }
644 }
Romain Guy06882f82009-06-10 13:36:04 -0700645
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700646 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 // Add ourself to the Watchdog monitors.
649 Watchdog.getInstance().addMonitor(this);
650 }
651
652 @Override
653 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
654 throws RemoteException {
655 try {
656 return super.onTransact(code, data, reply, flags);
657 } catch (RuntimeException e) {
658 // The window manager only throws security exceptions, so let's
659 // log all others.
660 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800661 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 }
663 throw e;
664 }
665 }
666
Jeff Browne33348b2010-07-15 23:54:05 -0700667 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800669 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 TAG, "Adding window " + window + " at "
671 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
672 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700673 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 }
675
Jeff Browne33348b2010-07-15 23:54:05 -0700676 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800678 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 TAG, "Adding window " + window + " at "
680 + i + " of " + mWindows.size() + " (before " + pos + ")");
681 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700682 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 }
684
685 //This method finds out the index of a window that has the same app token as
686 //win. used for z ordering the windows in mWindows
687 private int findIdxBasedOnAppTokens(WindowState win) {
688 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700689 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 int jmax = localmWindows.size();
691 if(jmax == 0) {
692 return -1;
693 }
694 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700695 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 if(wentry.mAppToken == win.mAppToken) {
697 return j;
698 }
699 }
700 return -1;
701 }
Romain Guy06882f82009-06-10 13:36:04 -0700702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
704 final IWindow client = win.mClient;
705 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700706 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 final int N = localmWindows.size();
709 final WindowState attached = win.mAttachedWindow;
710 int i;
711 if (attached == null) {
712 int tokenWindowsPos = token.windows.size();
713 if (token.appWindowToken != null) {
714 int index = tokenWindowsPos-1;
715 if (index >= 0) {
716 // If this application has existing windows, we
717 // simply place the new window on top of them... but
718 // keep the starting window on top.
719 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
720 // Base windows go behind everything else.
721 placeWindowBefore(token.windows.get(0), win);
722 tokenWindowsPos = 0;
723 } else {
724 AppWindowToken atoken = win.mAppToken;
725 if (atoken != null &&
726 token.windows.get(index) == atoken.startingWindow) {
727 placeWindowBefore(token.windows.get(index), win);
728 tokenWindowsPos--;
729 } else {
730 int newIdx = findIdxBasedOnAppTokens(win);
731 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700732 //there is a window above this one associated with the same
733 //apptoken note that the window could be a floating window
734 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800736 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700737 TAG, "Adding window " + win + " at "
738 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700740 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700741 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 }
743 }
744 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800745 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 TAG, "Figuring out where to add app window "
747 + client.asBinder() + " (token=" + token + ")");
748 // Figure out where the window should go, based on the
749 // order of applications.
750 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700751 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 for (i=NA-1; i>=0; i--) {
753 AppWindowToken t = mAppTokens.get(i);
754 if (t == token) {
755 i--;
756 break;
757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800758
Dianne Hackborna8f60182009-09-01 19:01:50 -0700759 // We haven't reached the token yet; if this token
760 // is not going to the bottom and has windows, we can
761 // use it as an anchor for when we do reach the token.
762 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 pos = t.windows.get(0);
764 }
765 }
766 // We now know the index into the apps. If we found
767 // an app window above, that gives us the position; else
768 // we need to look some more.
769 if (pos != null) {
770 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700771 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 if (atoken != null) {
773 final int NC = atoken.windows.size();
774 if (NC > 0) {
775 WindowState bottom = atoken.windows.get(0);
776 if (bottom.mSubLayer < 0) {
777 pos = bottom;
778 }
779 }
780 }
781 placeWindowBefore(pos, win);
782 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700783 // Continue looking down until we find the first
784 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 while (i >= 0) {
786 AppWindowToken t = mAppTokens.get(i);
787 final int NW = t.windows.size();
788 if (NW > 0) {
789 pos = t.windows.get(NW-1);
790 break;
791 }
792 i--;
793 }
794 if (pos != null) {
795 // Move in front of any windows attached to this
796 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700797 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 if (atoken != null) {
799 final int NC = atoken.windows.size();
800 if (NC > 0) {
801 WindowState top = atoken.windows.get(NC-1);
802 if (top.mSubLayer >= 0) {
803 pos = top;
804 }
805 }
806 }
807 placeWindowAfter(pos, win);
808 } else {
809 // Just search for the start of this layer.
810 final int myLayer = win.mBaseLayer;
811 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700812 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 if (w.mBaseLayer > myLayer) {
814 break;
815 }
816 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800817 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700818 TAG, "Adding window " + win + " at "
819 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700821 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 }
823 }
824 }
825 } else {
826 // Figure out where window should go, based on layer.
827 final int myLayer = win.mBaseLayer;
828 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700829 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 i++;
831 break;
832 }
833 }
834 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800835 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700836 TAG, "Adding window " + win + " at "
837 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700839 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 }
841 if (addToToken) {
842 token.windows.add(tokenWindowsPos, win);
843 }
844
845 } else {
846 // Figure out this window's ordering relative to the window
847 // it is attached to.
848 final int NA = token.windows.size();
849 final int sublayer = win.mSubLayer;
850 int largestSublayer = Integer.MIN_VALUE;
851 WindowState windowWithLargestSublayer = null;
852 for (i=0; i<NA; i++) {
853 WindowState w = token.windows.get(i);
854 final int wSublayer = w.mSubLayer;
855 if (wSublayer >= largestSublayer) {
856 largestSublayer = wSublayer;
857 windowWithLargestSublayer = w;
858 }
859 if (sublayer < 0) {
860 // For negative sublayers, we go below all windows
861 // in the same sublayer.
862 if (wSublayer >= sublayer) {
863 if (addToToken) {
864 token.windows.add(i, win);
865 }
866 placeWindowBefore(
867 wSublayer >= 0 ? attached : w, win);
868 break;
869 }
870 } else {
871 // For positive sublayers, we go above all windows
872 // in the same sublayer.
873 if (wSublayer > sublayer) {
874 if (addToToken) {
875 token.windows.add(i, win);
876 }
877 placeWindowBefore(w, win);
878 break;
879 }
880 }
881 }
882 if (i >= NA) {
883 if (addToToken) {
884 token.windows.add(win);
885 }
886 if (sublayer < 0) {
887 placeWindowBefore(attached, win);
888 } else {
889 placeWindowAfter(largestSublayer >= 0
890 ? windowWithLargestSublayer
891 : attached,
892 win);
893 }
894 }
895 }
Romain Guy06882f82009-06-10 13:36:04 -0700896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 if (win.mAppToken != null && addToToken) {
898 win.mAppToken.allAppWindows.add(win);
899 }
900 }
Romain Guy06882f82009-06-10 13:36:04 -0700901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 static boolean canBeImeTarget(WindowState w) {
903 final int fl = w.mAttrs.flags
904 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
905 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
906 return w.isVisibleOrAdding();
907 }
908 return false;
909 }
Romain Guy06882f82009-06-10 13:36:04 -0700910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700912 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 final int N = localmWindows.size();
914 WindowState w = null;
915 int i = N;
916 while (i > 0) {
917 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700918 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700919
Joe Onorato8a9b2202010-02-26 18:56:32 -0800920 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 // + Integer.toHexString(w.mAttrs.flags));
922 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800923 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 // Yet more tricksyness! If this window is a "starting"
926 // window, we do actually want to be on top of it, but
927 // it is not -really- where input will go. So if the caller
928 // is not actually looking to move the IME, look down below
929 // for a real window to target...
930 if (!willMove
931 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
932 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700933 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
935 i--;
936 w = wb;
937 }
938 }
939 break;
940 }
941 }
Romain Guy06882f82009-06-10 13:36:04 -0700942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700944
Joe Onorato8a9b2202010-02-26 18:56:32 -0800945 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 if (willMove && w != null) {
949 final WindowState curTarget = mInputMethodTarget;
950 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 // Now some fun for dealing with window animations that
953 // modify the Z order. We need to look at all windows below
954 // the current target that are in this app, finding the highest
955 // visible one in layering.
956 AppWindowToken token = curTarget.mAppToken;
957 WindowState highestTarget = null;
958 int highestPos = 0;
959 if (token.animating || token.animation != null) {
960 int pos = 0;
961 pos = localmWindows.indexOf(curTarget);
962 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700963 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 if (win.mAppToken != token) {
965 break;
966 }
967 if (!win.mRemoved) {
968 if (highestTarget == null || win.mAnimLayer >
969 highestTarget.mAnimLayer) {
970 highestTarget = win;
971 highestPos = pos;
972 }
973 }
974 pos--;
975 }
976 }
Romain Guy06882f82009-06-10 13:36:04 -0700977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800979 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 + mNextAppTransition + " " + highestTarget
981 + " animating=" + highestTarget.isAnimating()
982 + " layer=" + highestTarget.mAnimLayer
983 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700984
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700985 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 // If we are currently setting up for an animation,
987 // hold everything until we can find out what will happen.
988 mInputMethodTargetWaitingAnim = true;
989 mInputMethodTarget = highestTarget;
990 return highestPos + 1;
991 } else if (highestTarget.isAnimating() &&
992 highestTarget.mAnimLayer > w.mAnimLayer) {
993 // If the window we are currently targeting is involved
994 // with an animation, and it is on top of the next target
995 // we will be over, then hold off on moving until
996 // that is done.
997 mInputMethodTarget = highestTarget;
998 return highestPos + 1;
999 }
1000 }
1001 }
1002 }
Romain Guy06882f82009-06-10 13:36:04 -07001003
Joe Onorato8a9b2202010-02-26 18:56:32 -08001004 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 if (w != null) {
1006 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001007 if (DEBUG_INPUT_METHOD) {
1008 RuntimeException e = null;
1009 if (!HIDE_STACK_CRAWLS) {
1010 e = new RuntimeException();
1011 e.fillInStackTrace();
1012 }
1013 Slog.w(TAG, "Moving IM target from "
1014 + mInputMethodTarget + " to " + w, e);
1015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 mInputMethodTarget = w;
1017 if (w.mAppToken != null) {
1018 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1019 } else {
1020 setInputMethodAnimLayerAdjustment(0);
1021 }
1022 }
1023 return i+1;
1024 }
1025 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001026 if (DEBUG_INPUT_METHOD) {
1027 RuntimeException e = null;
1028 if (!HIDE_STACK_CRAWLS) {
1029 e = new RuntimeException();
1030 e.fillInStackTrace();
1031 }
1032 Slog.w(TAG, "Moving IM target from "
1033 + mInputMethodTarget + " to null", e);
1034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 mInputMethodTarget = null;
1036 setInputMethodAnimLayerAdjustment(0);
1037 }
1038 return -1;
1039 }
Romain Guy06882f82009-06-10 13:36:04 -07001040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 void addInputMethodWindowToListLocked(WindowState win) {
1042 int pos = findDesiredInputMethodWindowIndexLocked(true);
1043 if (pos >= 0) {
1044 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001045 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001046 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001048 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 moveInputMethodDialogsLocked(pos+1);
1050 return;
1051 }
1052 win.mTargetAppToken = null;
1053 addWindowToListInOrderLocked(win, true);
1054 moveInputMethodDialogsLocked(pos);
1055 }
Romain Guy06882f82009-06-10 13:36:04 -07001056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001058 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 mInputMethodAnimLayerAdjustment = adj;
1060 WindowState imw = mInputMethodWindow;
1061 if (imw != null) {
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 int wi = imw.mChildWindows.size();
1066 while (wi > 0) {
1067 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001068 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001070 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 + " anim layer: " + cw.mAnimLayer);
1072 }
1073 }
1074 int di = mInputMethodDialogs.size();
1075 while (di > 0) {
1076 di --;
1077 imw = mInputMethodDialogs.get(di);
1078 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001079 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 + " anim layer: " + imw.mAnimLayer);
1081 }
1082 }
Romain Guy06882f82009-06-10 13:36:04 -07001083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1085 int wpos = mWindows.indexOf(win);
1086 if (wpos >= 0) {
1087 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001088 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001090 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 int NC = win.mChildWindows.size();
1092 while (NC > 0) {
1093 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001094 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 int cpos = mWindows.indexOf(cw);
1096 if (cpos >= 0) {
1097 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001098 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001099 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 mWindows.remove(cpos);
1101 }
1102 }
1103 }
1104 return interestingPos;
1105 }
Romain Guy06882f82009-06-10 13:36:04 -07001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 private void reAddWindowToListInOrderLocked(WindowState win) {
1108 addWindowToListInOrderLocked(win, false);
1109 // This is a hack to get all of the child windows added as well
1110 // at the right position. Child windows should be rare and
1111 // this case should be rare, so it shouldn't be that big a deal.
1112 int wpos = mWindows.indexOf(win);
1113 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001114 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001115 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001117 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 reAddWindowLocked(wpos, win);
1119 }
1120 }
Romain Guy06882f82009-06-10 13:36:04 -07001121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 void logWindowList(String prefix) {
1123 int N = mWindows.size();
1124 while (N > 0) {
1125 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001126 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 }
1128 }
Romain Guy06882f82009-06-10 13:36:04 -07001129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 void moveInputMethodDialogsLocked(int pos) {
1131 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001134 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 for (int i=0; i<N; i++) {
1136 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1137 }
1138 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001139 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 logWindowList(" ");
1141 }
Romain Guy06882f82009-06-10 13:36:04 -07001142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 if (pos >= 0) {
1144 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1145 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001146 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 if (wp == mInputMethodWindow) {
1148 pos++;
1149 }
1150 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001151 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 for (int i=0; i<N; i++) {
1153 WindowState win = dialogs.get(i);
1154 win.mTargetAppToken = targetAppToken;
1155 pos = reAddWindowLocked(pos, win);
1156 }
1157 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001158 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 logWindowList(" ");
1160 }
1161 return;
1162 }
1163 for (int i=0; i<N; i++) {
1164 WindowState win = dialogs.get(i);
1165 win.mTargetAppToken = null;
1166 reAddWindowToListInOrderLocked(win);
1167 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001168 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 logWindowList(" ");
1170 }
1171 }
1172 }
Romain Guy06882f82009-06-10 13:36:04 -07001173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1175 final WindowState imWin = mInputMethodWindow;
1176 final int DN = mInputMethodDialogs.size();
1177 if (imWin == null && DN == 0) {
1178 return false;
1179 }
Romain Guy06882f82009-06-10 13:36:04 -07001180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1182 if (imPos >= 0) {
1183 // In this case, the input method windows are to be placed
1184 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 // First check to see if the input method windows are already
1187 // located here, and contiguous.
1188 final int N = mWindows.size();
1189 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001190 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 // Figure out the actual input method window that should be
1193 // at the bottom of their stack.
1194 WindowState baseImWin = imWin != null
1195 ? imWin : mInputMethodDialogs.get(0);
1196 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001197 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 if (cw.mSubLayer < 0) baseImWin = cw;
1199 }
Romain Guy06882f82009-06-10 13:36:04 -07001200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 if (firstImWin == baseImWin) {
1202 // The windows haven't moved... but are they still contiguous?
1203 // First find the top IM window.
1204 int pos = imPos+1;
1205 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001206 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 break;
1208 }
1209 pos++;
1210 }
1211 pos++;
1212 // Now there should be no more input method windows above.
1213 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001214 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 break;
1216 }
1217 pos++;
1218 }
1219 if (pos >= N) {
1220 // All is good!
1221 return false;
1222 }
1223 }
Romain Guy06882f82009-06-10 13:36:04 -07001224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 if (imWin != null) {
1226 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001227 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 logWindowList(" ");
1229 }
1230 imPos = tmpRemoveWindowLocked(imPos, imWin);
1231 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001232 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 logWindowList(" ");
1234 }
1235 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1236 reAddWindowLocked(imPos, imWin);
1237 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001238 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 logWindowList(" ");
1240 }
1241 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1242 } else {
1243 moveInputMethodDialogsLocked(imPos);
1244 }
Romain Guy06882f82009-06-10 13:36:04 -07001245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 } else {
1247 // In this case, the input method windows go in a fixed layer,
1248 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001251 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 tmpRemoveWindowLocked(0, imWin);
1253 imWin.mTargetAppToken = null;
1254 reAddWindowToListInOrderLocked(imWin);
1255 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001256 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 logWindowList(" ");
1258 }
1259 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1260 } else {
1261 moveInputMethodDialogsLocked(-1);;
1262 }
Romain Guy06882f82009-06-10 13:36:04 -07001263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 }
Romain Guy06882f82009-06-10 13:36:04 -07001265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 if (needAssignLayers) {
1267 assignLayersLocked();
1268 }
Romain Guy06882f82009-06-10 13:36:04 -07001269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 return true;
1271 }
Romain Guy06882f82009-06-10 13:36:04 -07001272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 void adjustInputMethodDialogsLocked() {
1274 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1275 }
Romain Guy06882f82009-06-10 13:36:04 -07001276
Dianne Hackborn25994b42009-09-04 14:21:19 -07001277 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001278 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001279 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1280 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1281 ? wallpaperTarget.mAppToken.animation : null)
1282 + " upper=" + mUpperWallpaperTarget
1283 + " lower=" + mLowerWallpaperTarget);
1284 return (wallpaperTarget != null
1285 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1286 && wallpaperTarget.mAppToken.animation != null)))
1287 || mUpperWallpaperTarget != null
1288 || mLowerWallpaperTarget != null;
1289 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001290
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001291 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1292 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001293
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001294 int adjustWallpaperWindowsLocked() {
1295 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001296
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001297 final int dw = mDisplay.getWidth();
1298 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001299
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001300 // First find top-most window that has asked to be on top of the
1301 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001302 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001303 int N = localmWindows.size();
1304 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001305 WindowState foundW = null;
1306 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001307 WindowState topCurW = null;
1308 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001309 int i = N;
1310 while (i > 0) {
1311 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001312 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001313 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1314 if (topCurW == null) {
1315 topCurW = w;
1316 topCurI = i;
1317 }
1318 continue;
1319 }
1320 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001321 if (w.mAppToken != null) {
1322 // If this window's app token is hidden and not animating,
1323 // it is of no interest to us.
1324 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001325 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001326 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001327 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001328 continue;
1329 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001330 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001331 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001332 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1333 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001334 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001335 && (mWallpaperTarget == w
1336 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001337 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001338 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001339 foundW = w;
1340 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001341 if (w == mWallpaperTarget && ((w.mAppToken != null
1342 && w.mAppToken.animation != null)
1343 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001344 // The current wallpaper target is animating, so we'll
1345 // look behind it for another possible target and figure
1346 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001347 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001348 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001349 continue;
1350 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001351 break;
1352 }
1353 }
1354
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001355 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001356 // If we are currently waiting for an app transition, and either
1357 // the current target or the next target are involved with it,
1358 // then hold off on doing anything with the wallpaper.
1359 // Note that we are checking here for just whether the target
1360 // is part of an app token... which is potentially overly aggressive
1361 // (the app token may not be involved in the transition), but good
1362 // enough (we'll just wait until whatever transition is pending
1363 // executes).
1364 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001365 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001366 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001367 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001368 }
1369 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001370 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001371 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001372 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001373 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001374 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001375
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001376 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001377 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001378 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001379 + " oldTarget: " + mWallpaperTarget);
1380 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001381
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001382 mLowerWallpaperTarget = null;
1383 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001384
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001385 WindowState oldW = mWallpaperTarget;
1386 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001387
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001388 // Now what is happening... if the current and new targets are
1389 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001390 if (foundW != null && oldW != null) {
1391 boolean oldAnim = oldW.mAnimation != null
1392 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1393 boolean foundAnim = foundW.mAnimation != null
1394 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001395 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001396 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001397 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001398 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001399 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001400 int oldI = localmWindows.indexOf(oldW);
1401 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001402 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001403 }
1404 if (oldI >= 0) {
1405 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001406 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001407 + "=" + oldW + "; new#" + foundI
1408 + "=" + foundW);
1409 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001410
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001411 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001412 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001413 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001414 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001415 }
1416 mWallpaperTarget = oldW;
1417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001418
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001419 // Now set the upper and lower wallpaper targets
1420 // correctly, and make sure that we are positioning
1421 // the wallpaper below the lower.
1422 if (foundI > oldI) {
1423 // The new target is on top of the old one.
1424 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001425 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001426 }
1427 mUpperWallpaperTarget = foundW;
1428 mLowerWallpaperTarget = oldW;
1429 foundW = oldW;
1430 foundI = oldI;
1431 } else {
1432 // The new target is below the old one.
1433 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001434 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001435 }
1436 mUpperWallpaperTarget = oldW;
1437 mLowerWallpaperTarget = foundW;
1438 }
1439 }
1440 }
1441 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001442
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001443 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001444 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001445 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1446 || (mLowerWallpaperTarget.mAppToken != null
1447 && mLowerWallpaperTarget.mAppToken.animation != null);
1448 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1449 || (mUpperWallpaperTarget.mAppToken != null
1450 && mUpperWallpaperTarget.mAppToken.animation != null);
1451 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001452 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001453 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001454 }
1455 mLowerWallpaperTarget = null;
1456 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001457 }
1458 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001459
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001460 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001461 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001462 // The window is visible to the compositor... but is it visible
1463 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001464 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001465 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001466
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001467 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001468 // its layer adjustment. Only do this if we are not transfering
1469 // between two wallpaper targets.
1470 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001471 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001472 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001473
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001474 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1475 * TYPE_LAYER_MULTIPLIER
1476 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001477
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001478 // Now w is the window we are supposed to be behind... but we
1479 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001480 // AND any starting window associated with it, AND below the
1481 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001482 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001483 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001484 if (wb.mBaseLayer < maxLayer &&
1485 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001486 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001487 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001488 // This window is not related to the previous one in any
1489 // interesting way, so stop here.
1490 break;
1491 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001492 foundW = wb;
1493 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001494 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001495 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001496 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001497 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001498
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001499 if (foundW == null && topCurW != null) {
1500 // There is no wallpaper target, so it goes at the bottom.
1501 // We will assume it is the same place as last time, if known.
1502 foundW = topCurW;
1503 foundI = topCurI+1;
1504 } else {
1505 // Okay i is the position immediately above the wallpaper. Look at
1506 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001507 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001509
Dianne Hackborn284ac932009-08-28 10:34:25 -07001510 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001511 if (mWallpaperTarget.mWallpaperX >= 0) {
1512 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001513 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001514 }
1515 if (mWallpaperTarget.mWallpaperY >= 0) {
1516 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001517 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001518 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001519 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001520
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001521 // Start stepping backwards from here, ensuring that our wallpaper windows
1522 // are correctly placed.
1523 int curTokenIndex = mWallpaperTokens.size();
1524 while (curTokenIndex > 0) {
1525 curTokenIndex--;
1526 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001527 if (token.hidden == visible) {
1528 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1529 token.hidden = !visible;
1530 // Need to do a layout to ensure the wallpaper now has the
1531 // correct size.
1532 mLayoutNeeded = true;
1533 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001534
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001535 int curWallpaperIndex = token.windows.size();
1536 while (curWallpaperIndex > 0) {
1537 curWallpaperIndex--;
1538 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001539
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001540 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001541 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001542 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001543
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001544 // First, make sure the client has the current visibility
1545 // state.
1546 if (wallpaper.mWallpaperVisible != visible) {
1547 wallpaper.mWallpaperVisible = visible;
1548 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001549 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001550 "Setting visibility of wallpaper " + wallpaper
1551 + ": " + visible);
1552 wallpaper.mClient.dispatchAppVisibility(visible);
1553 } catch (RemoteException e) {
1554 }
1555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001556
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001557 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001558 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001559 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001560
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001561 // First, if this window is at the current index, then all
1562 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001563 if (wallpaper == foundW) {
1564 foundI--;
1565 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001566 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001567 continue;
1568 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001569
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001570 // The window didn't match... the current wallpaper window,
1571 // wherever it is, is in the wrong place, so make sure it is
1572 // not in the list.
1573 int oldIndex = localmWindows.indexOf(wallpaper);
1574 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001575 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001576 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001577 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001578 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001579 if (oldIndex < foundI) {
1580 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001581 }
1582 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001583
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001584 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001585 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001586 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001587 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001588
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001589 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001590 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001591 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001592 }
1593 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001594
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001595 return changed;
1596 }
1597
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001598 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001599 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001600 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001601 mWallpaperAnimLayerAdjustment = adj;
1602 int curTokenIndex = mWallpaperTokens.size();
1603 while (curTokenIndex > 0) {
1604 curTokenIndex--;
1605 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1606 int curWallpaperIndex = token.windows.size();
1607 while (curWallpaperIndex > 0) {
1608 curWallpaperIndex--;
1609 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1610 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001611 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001612 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001613 }
1614 }
1615 }
1616
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001617 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1618 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001619 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001620 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001621 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001622 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1624 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1625 changed = wallpaperWin.mXOffset != offset;
1626 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001627 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001628 + wallpaperWin + " x: " + offset);
1629 wallpaperWin.mXOffset = offset;
1630 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001631 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001632 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001636
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001637 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001638 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001639 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1640 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1641 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001642 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001643 + wallpaperWin + " y: " + offset);
1644 changed = true;
1645 wallpaperWin.mYOffset = offset;
1646 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001647 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001648 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001649 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001651 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001652
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001653 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001654 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001655 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001656 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1657 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001658 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001659 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001661 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001662 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1663 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001664 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001665 if (mWaitingOnWallpaper != null) {
1666 long start = SystemClock.uptimeMillis();
1667 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1668 < start) {
1669 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001670 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001671 "Waiting for offset complete...");
1672 mWindowMap.wait(WALLPAPER_TIMEOUT);
1673 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001674 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001675 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001676 if ((start+WALLPAPER_TIMEOUT)
1677 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001678 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001679 + wallpaperWin);
1680 mLastWallpaperTimeoutTime = start;
1681 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001682 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001683 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001684 }
1685 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001686 } catch (RemoteException e) {
1687 }
1688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001689
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001690 return changed;
1691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001693 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001694 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001695 if (mWaitingOnWallpaper != null &&
1696 mWaitingOnWallpaper.mClient.asBinder() == window) {
1697 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001698 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001699 }
1700 }
1701 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001702
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001703 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001704 final int dw = mDisplay.getWidth();
1705 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001706
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001707 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001709 WindowState target = mWallpaperTarget;
1710 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001711 if (target.mWallpaperX >= 0) {
1712 mLastWallpaperX = target.mWallpaperX;
1713 } else if (changingTarget.mWallpaperX >= 0) {
1714 mLastWallpaperX = changingTarget.mWallpaperX;
1715 }
1716 if (target.mWallpaperY >= 0) {
1717 mLastWallpaperY = target.mWallpaperY;
1718 } else if (changingTarget.mWallpaperY >= 0) {
1719 mLastWallpaperY = changingTarget.mWallpaperY;
1720 }
1721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001723 int curTokenIndex = mWallpaperTokens.size();
1724 while (curTokenIndex > 0) {
1725 curTokenIndex--;
1726 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1727 int curWallpaperIndex = token.windows.size();
1728 while (curWallpaperIndex > 0) {
1729 curWallpaperIndex--;
1730 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1731 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1732 wallpaper.computeShownFrameLocked();
1733 changed = true;
1734 // We only want to be synchronous with one wallpaper.
1735 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001736 }
1737 }
1738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001740 return changed;
1741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001743 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001744 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001745 final int dw = mDisplay.getWidth();
1746 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001747
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001748 int curTokenIndex = mWallpaperTokens.size();
1749 while (curTokenIndex > 0) {
1750 curTokenIndex--;
1751 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001752 if (token.hidden == visible) {
1753 token.hidden = !visible;
1754 // Need to do a layout to ensure the wallpaper now has the
1755 // correct size.
1756 mLayoutNeeded = true;
1757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001758
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001759 int curWallpaperIndex = token.windows.size();
1760 while (curWallpaperIndex > 0) {
1761 curWallpaperIndex--;
1762 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1763 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001764 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001765 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001766
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001767 if (wallpaper.mWallpaperVisible != visible) {
1768 wallpaper.mWallpaperVisible = visible;
1769 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001770 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001771 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001772 + ": " + visible);
1773 wallpaper.mClient.dispatchAppVisibility(visible);
1774 } catch (RemoteException e) {
1775 }
1776 }
1777 }
1778 }
1779 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001781 public int addWindow(Session session, IWindow client,
1782 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001783 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001784 int res = mPolicy.checkAddPermission(attrs);
1785 if (res != WindowManagerImpl.ADD_OKAY) {
1786 return res;
1787 }
Romain Guy06882f82009-06-10 13:36:04 -07001788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789 boolean reportNewConfig = false;
1790 WindowState attachedWindow = null;
1791 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 synchronized(mWindowMap) {
1794 // Instantiating a Display requires talking with the simulator,
1795 // so don't do it until we know the system is mostly up and
1796 // running.
1797 if (mDisplay == null) {
1798 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1799 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001800 mInitialDisplayWidth = mDisplay.getWidth();
1801 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001802 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 reportNewConfig = true;
1804 }
Romain Guy06882f82009-06-10 13:36:04 -07001805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001807 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1809 }
1810
1811 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001812 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001814 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 + attrs.token + ". Aborting.");
1816 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1817 }
1818 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1819 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001820 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 + attrs.token + ". Aborting.");
1822 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1823 }
1824 }
1825
1826 boolean addToken = false;
1827 WindowToken token = mTokenMap.get(attrs.token);
1828 if (token == null) {
1829 if (attrs.type >= FIRST_APPLICATION_WINDOW
1830 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001831 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001832 + attrs.token + ". Aborting.");
1833 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1834 }
1835 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001836 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001837 + attrs.token + ". Aborting.");
1838 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1839 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001840 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001841 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001842 + attrs.token + ". Aborting.");
1843 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1844 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 token = new WindowToken(attrs.token, -1, false);
1846 addToken = true;
1847 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1848 && attrs.type <= LAST_APPLICATION_WINDOW) {
1849 AppWindowToken atoken = token.appWindowToken;
1850 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001851 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 + token + ". Aborting.");
1853 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1854 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001855 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 + token + ". Aborting.");
1857 return WindowManagerImpl.ADD_APP_EXITING;
1858 }
1859 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1860 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001861 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1863 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1864 }
1865 } else if (attrs.type == TYPE_INPUT_METHOD) {
1866 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001867 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001868 + attrs.token + ". Aborting.");
1869 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1870 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001871 } else if (attrs.type == TYPE_WALLPAPER) {
1872 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001873 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001874 + attrs.token + ". Aborting.");
1875 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1876 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 }
1878
1879 win = new WindowState(session, client, token,
1880 attachedWindow, attrs, viewVisibility);
1881 if (win.mDeathRecipient == null) {
1882 // Client has apparently died, so there is no reason to
1883 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001884 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 + " that is dead, aborting.");
1886 return WindowManagerImpl.ADD_APP_EXITING;
1887 }
1888
1889 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 res = mPolicy.prepareAddWindowLw(win, attrs);
1892 if (res != WindowManagerImpl.ADD_OKAY) {
1893 return res;
1894 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001895
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001896 if (outInputChannel != null) {
1897 String name = win.makeInputChannelName();
1898 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1899 win.mInputChannel = inputChannels[0];
1900 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1901
1902 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904
1905 // From now on, no exceptions or errors allowed!
1906
1907 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 if (addToken) {
1912 mTokenMap.put(attrs.token, token);
1913 mTokenList.add(token);
1914 }
1915 win.attach();
1916 mWindowMap.put(client.asBinder(), win);
1917
1918 if (attrs.type == TYPE_APPLICATION_STARTING &&
1919 token.appWindowToken != null) {
1920 token.appWindowToken.startingWindow = win;
1921 }
1922
1923 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001925 if (attrs.type == TYPE_INPUT_METHOD) {
1926 mInputMethodWindow = win;
1927 addInputMethodWindowToListLocked(win);
1928 imMayMove = false;
1929 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1930 mInputMethodDialogs.add(win);
1931 addWindowToListInOrderLocked(win, true);
1932 adjustInputMethodDialogsLocked();
1933 imMayMove = false;
1934 } else {
1935 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001936 if (attrs.type == TYPE_WALLPAPER) {
1937 mLastWallpaperTimeoutTime = 0;
1938 adjustWallpaperWindowsLocked();
1939 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001940 adjustWallpaperWindowsLocked();
1941 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 }
Romain Guy06882f82009-06-10 13:36:04 -07001943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 if (mInTouchMode) {
1949 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1950 }
1951 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1952 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1953 }
Romain Guy06882f82009-06-10 13:36:04 -07001954
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001955 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001956 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001957 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1958 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 imMayMove = false;
1960 }
1961 }
Romain Guy06882f82009-06-10 13:36:04 -07001962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001964 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 }
Romain Guy06882f82009-06-10 13:36:04 -07001966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 assignLayersLocked();
1968 // Don't do layout here, the window must call
1969 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 //dump();
1972
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001973 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001974 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001975 }
Jeff Brown349703e2010-06-22 01:27:15 -07001976
Joe Onorato8a9b2202010-02-26 18:56:32 -08001977 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 TAG, "New client " + client.asBinder()
1979 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001980
1981 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1982 reportNewConfig = true;
1983 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 }
1985
1986 // sendNewConfiguration() checks caller permissions so we must call it with
1987 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1988 // identity anyway, so it's safe to just clear & restore around this whole
1989 // block.
1990 final long origId = Binder.clearCallingIdentity();
1991 if (reportNewConfig) {
1992 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 }
1994 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 return res;
1997 }
Romain Guy06882f82009-06-10 13:36:04 -07001998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 public void removeWindow(Session session, IWindow client) {
2000 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002001 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 if (win == null) {
2003 return;
2004 }
2005 removeWindowLocked(session, win);
2006 }
2007 }
Romain Guy06882f82009-06-10 13:36:04 -07002008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 public void removeWindowLocked(Session session, WindowState win) {
2010
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 TAG, "Remove " + win + " client="
2013 + Integer.toHexString(System.identityHashCode(
2014 win.mClient.asBinder()))
2015 + ", surface=" + win.mSurface);
2016
2017 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002018
2019 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002020
Joe Onorato8a9b2202010-02-26 18:56:32 -08002021 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002022 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2023 + " mExiting=" + win.mExiting
2024 + " isAnimating=" + win.isAnimating()
2025 + " app-animation="
2026 + (win.mAppToken != null ? win.mAppToken.animation : null)
2027 + " inPendingTransaction="
2028 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2029 + " mDisplayFrozen=" + mDisplayFrozen);
2030 // Visibility of the removed window. Will be used later to update orientation later on.
2031 boolean wasVisible = false;
2032 // First, see if we need to run an animation. If we do, we have
2033 // to hold off on removing the window until the animation is done.
2034 // If the display is frozen, just remove immediately, since the
2035 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002036 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037 // If we are not currently running the exit animation, we
2038 // need to see about starting one.
2039 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2042 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2043 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2044 }
2045 // Try starting an animation.
2046 if (applyAnimationLocked(win, transit, false)) {
2047 win.mExiting = true;
2048 }
2049 }
2050 if (win.mExiting || win.isAnimating()) {
2051 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002052 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 win.mExiting = true;
2054 win.mRemoveOnExit = true;
2055 mLayoutNeeded = true;
2056 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2057 performLayoutAndPlaceSurfacesLocked();
2058 if (win.mAppToken != null) {
2059 win.mAppToken.updateReportedVisibilityLocked();
2060 }
2061 //dump();
2062 Binder.restoreCallingIdentity(origId);
2063 return;
2064 }
2065 }
2066
2067 removeWindowInnerLocked(session, win);
2068 // Removing a visible window will effect the computed orientation
2069 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002070 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002071 != mForcedAppOrientation
2072 && updateOrientationFromAppTokensLocked()) {
2073 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 }
2075 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2076 Binder.restoreCallingIdentity(origId);
2077 }
Romain Guy06882f82009-06-10 13:36:04 -07002078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 if (mInputMethodTarget == win) {
2083 moveInputMethodWindowsIfNeededLocked(false);
2084 }
Romain Guy06882f82009-06-10 13:36:04 -07002085
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002086 if (false) {
2087 RuntimeException e = new RuntimeException("here");
2088 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002089 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002090 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 mPolicy.removeWindowLw(win);
2093 win.removeLocked();
2094
2095 mWindowMap.remove(win.mClient.asBinder());
2096 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002097 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002098 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002099
2100 if (mInputMethodWindow == win) {
2101 mInputMethodWindow = null;
2102 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2103 mInputMethodDialogs.remove(win);
2104 }
Romain Guy06882f82009-06-10 13:36:04 -07002105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 final WindowToken token = win.mToken;
2107 final AppWindowToken atoken = win.mAppToken;
2108 token.windows.remove(win);
2109 if (atoken != null) {
2110 atoken.allAppWindows.remove(win);
2111 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002112 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002113 TAG, "**** Removing window " + win + ": count="
2114 + token.windows.size());
2115 if (token.windows.size() == 0) {
2116 if (!token.explicit) {
2117 mTokenMap.remove(token.token);
2118 mTokenList.remove(token);
2119 } else if (atoken != null) {
2120 atoken.firstWindowDrawn = false;
2121 }
2122 }
2123
2124 if (atoken != null) {
2125 if (atoken.startingWindow == win) {
2126 atoken.startingWindow = null;
2127 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2128 // If this is the last window and we had requested a starting
2129 // transition window, well there is no point now.
2130 atoken.startingData = null;
2131 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2132 // If this is the last window except for a starting transition
2133 // window, we need to get rid of the starting transition.
2134 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002135 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136 + ": no more real windows");
2137 }
2138 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2139 mH.sendMessage(m);
2140 }
2141 }
Romain Guy06882f82009-06-10 13:36:04 -07002142
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002143 if (win.mAttrs.type == TYPE_WALLPAPER) {
2144 mLastWallpaperTimeoutTime = 0;
2145 adjustWallpaperWindowsLocked();
2146 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002147 adjustWallpaperWindowsLocked();
2148 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 if (!mInLayout) {
2151 assignLayersLocked();
2152 mLayoutNeeded = true;
2153 performLayoutAndPlaceSurfacesLocked();
2154 if (win.mAppToken != null) {
2155 win.mAppToken.updateReportedVisibilityLocked();
2156 }
2157 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002158
2159 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 }
2161
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002162 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2163 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2164 + ": " + msg + " / " + w.mAttrs.getTitle();
2165 if (where != null) {
2166 Slog.i(TAG, str, where);
2167 } else {
2168 Slog.i(TAG, str);
2169 }
2170 }
2171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2173 long origId = Binder.clearCallingIdentity();
2174 try {
2175 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002176 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002177 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002178 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 Surface.openTransaction();
2180 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002181 if (SHOW_TRANSACTIONS) logSurface(w,
2182 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 w.mSurface.setTransparentRegionHint(region);
2184 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002185 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 Surface.closeTransaction();
2187 }
2188 }
2189 }
2190 } finally {
2191 Binder.restoreCallingIdentity(origId);
2192 }
2193 }
2194
2195 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002196 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 Rect visibleInsets) {
2198 long origId = Binder.clearCallingIdentity();
2199 try {
2200 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002201 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 if (w != null) {
2203 w.mGivenInsetsPending = false;
2204 w.mGivenContentInsets.set(contentInsets);
2205 w.mGivenVisibleInsets.set(visibleInsets);
2206 w.mTouchableInsets = touchableInsets;
2207 mLayoutNeeded = true;
2208 performLayoutAndPlaceSurfacesLocked();
2209 }
2210 }
2211 } finally {
2212 Binder.restoreCallingIdentity(origId);
2213 }
2214 }
Romain Guy06882f82009-06-10 13:36:04 -07002215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 public void getWindowDisplayFrame(Session session, IWindow client,
2217 Rect outDisplayFrame) {
2218 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002219 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 if (win == null) {
2221 outDisplayFrame.setEmpty();
2222 return;
2223 }
2224 outDisplayFrame.set(win.mDisplayFrame);
2225 }
2226 }
2227
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002228 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2229 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002230 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2231 window.mWallpaperX = x;
2232 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002233 window.mWallpaperXStep = xStep;
2234 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002235 if (updateWallpaperOffsetLocked(window, true)) {
2236 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002237 }
2238 }
2239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002240
Dianne Hackborn75804932009-10-20 20:15:20 -07002241 void wallpaperCommandComplete(IBinder window, Bundle result) {
2242 synchronized (mWindowMap) {
2243 if (mWaitingOnWallpaper != null &&
2244 mWaitingOnWallpaper.mClient.asBinder() == window) {
2245 mWaitingOnWallpaper = null;
2246 mWindowMap.notifyAll();
2247 }
2248 }
2249 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002250
Dianne Hackborn75804932009-10-20 20:15:20 -07002251 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2252 String action, int x, int y, int z, Bundle extras, boolean sync) {
2253 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2254 || window == mUpperWallpaperTarget) {
2255 boolean doWait = sync;
2256 int curTokenIndex = mWallpaperTokens.size();
2257 while (curTokenIndex > 0) {
2258 curTokenIndex--;
2259 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2260 int curWallpaperIndex = token.windows.size();
2261 while (curWallpaperIndex > 0) {
2262 curWallpaperIndex--;
2263 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2264 try {
2265 wallpaper.mClient.dispatchWallpaperCommand(action,
2266 x, y, z, extras, sync);
2267 // We only want to be synchronous with one wallpaper.
2268 sync = false;
2269 } catch (RemoteException e) {
2270 }
2271 }
2272 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002273
Dianne Hackborn75804932009-10-20 20:15:20 -07002274 if (doWait) {
2275 // XXX Need to wait for result.
2276 }
2277 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002278
Dianne Hackborn75804932009-10-20 20:15:20 -07002279 return null;
2280 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 public int relayoutWindow(Session session, IWindow client,
2283 WindowManager.LayoutParams attrs, int requestedWidth,
2284 int requestedHeight, int viewVisibility, boolean insetsPending,
2285 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002286 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 boolean displayed = false;
2288 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002289 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002293 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 if (win == null) {
2295 return 0;
2296 }
2297 win.mRequestedWidth = requestedWidth;
2298 win.mRequestedHeight = requestedHeight;
2299
2300 if (attrs != null) {
2301 mPolicy.adjustWindowParamsLw(attrs);
2302 }
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 int attrChanges = 0;
2305 int flagChanges = 0;
2306 if (attrs != null) {
2307 flagChanges = win.mAttrs.flags ^= attrs.flags;
2308 attrChanges = win.mAttrs.copyFrom(attrs);
2309 }
2310
Joe Onorato8a9b2202010-02-26 18:56:32 -08002311 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312
2313 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2314 win.mAlpha = attrs.alpha;
2315 }
2316
2317 final boolean scaledWindow =
2318 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2319
2320 if (scaledWindow) {
2321 // requested{Width|Height} Surface's physical size
2322 // attrs.{width|height} Size on screen
2323 win.mHScale = (attrs.width != requestedWidth) ?
2324 (attrs.width / (float)requestedWidth) : 1.0f;
2325 win.mVScale = (attrs.height != requestedHeight) ?
2326 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002327 } else {
2328 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 }
2330
2331 boolean imMayMove = (flagChanges&(
2332 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2333 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 boolean focusMayChange = win.mViewVisibility != viewVisibility
2336 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2337 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002338
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002339 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2340 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 win.mRelayoutCalled = true;
2343 final int oldVisibility = win.mViewVisibility;
2344 win.mViewVisibility = viewVisibility;
2345 if (viewVisibility == View.VISIBLE &&
2346 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2347 displayed = !win.isVisibleLw();
2348 if (win.mExiting) {
2349 win.mExiting = false;
2350 win.mAnimation = null;
2351 }
2352 if (win.mDestroying) {
2353 win.mDestroying = false;
2354 mDestroySurface.remove(win);
2355 }
2356 if (oldVisibility == View.GONE) {
2357 win.mEnterAnimationPending = true;
2358 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002359 if (displayed) {
2360 if (win.mSurface != null && !win.mDrawPending
2361 && !win.mCommitDrawPending && !mDisplayFrozen
2362 && mPolicy.isScreenOn()) {
2363 applyEnterAnimationLocked(win);
2364 }
2365 if ((win.mAttrs.flags
2366 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2367 if (DEBUG_VISIBILITY) Slog.v(TAG,
2368 "Relayout window turning screen on: " + win);
2369 win.mTurnOnScreen = true;
2370 }
2371 int diff = 0;
2372 if (win.mConfiguration != mCurConfiguration
2373 && (win.mConfiguration == null
2374 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2375 win.mConfiguration = mCurConfiguration;
2376 if (DEBUG_CONFIGURATION) {
2377 Slog.i(TAG, "Window " + win + " visible with new config: "
2378 + win.mConfiguration + " / 0x"
2379 + Integer.toHexString(diff));
2380 }
2381 outConfig.setTo(mCurConfiguration);
2382 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2385 // To change the format, we need to re-build the surface.
2386 win.destroySurfaceLocked();
2387 displayed = true;
2388 }
2389 try {
2390 Surface surface = win.createSurfaceLocked();
2391 if (surface != null) {
2392 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002393 win.mReportDestroySurface = false;
2394 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002395 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002396 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002398 // For some reason there isn't a surface. Clear the
2399 // caller's object so they see the same state.
2400 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 }
2402 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002403 mInputMonitor.updateInputWindowsLw();
2404
Joe Onorato8a9b2202010-02-26 18:56:32 -08002405 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002406 + client + " (" + win.mAttrs.getTitle() + ")",
2407 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 Binder.restoreCallingIdentity(origId);
2409 return 0;
2410 }
2411 if (displayed) {
2412 focusMayChange = true;
2413 }
2414 if (win.mAttrs.type == TYPE_INPUT_METHOD
2415 && mInputMethodWindow == null) {
2416 mInputMethodWindow = win;
2417 imMayMove = true;
2418 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002419 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2420 && win.mAppToken != null
2421 && win.mAppToken.startingWindow != null) {
2422 // Special handling of starting window over the base
2423 // window of the app: propagate lock screen flags to it,
2424 // to provide the correct semantics while starting.
2425 final int mask =
2426 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002427 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2428 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002429 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2430 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2431 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 } else {
2433 win.mEnterAnimationPending = false;
2434 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002435 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002436 + ": mExiting=" + win.mExiting
2437 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 // If we are not currently running the exit animation, we
2439 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002440 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 // Try starting an animation; if there isn't one, we
2442 // can destroy the surface right away.
2443 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2444 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2445 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2446 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002447 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002449 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 } else if (win.isAnimating()) {
2452 // Currently in a hide animation... turn this into
2453 // an exit.
2454 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002455 } else if (win == mWallpaperTarget) {
2456 // If the wallpaper is currently behind this
2457 // window, we need to change both of them inside
2458 // of a transaction to avoid artifacts.
2459 win.mExiting = true;
2460 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 } else {
2462 if (mInputMethodWindow == win) {
2463 mInputMethodWindow = null;
2464 }
2465 win.destroySurfaceLocked();
2466 }
2467 }
2468 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002469
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002470 if (win.mSurface == null || (win.getAttrs().flags
2471 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2472 || win.mSurfacePendingDestroy) {
2473 // We are being called from a local process, which
2474 // means outSurface holds its current surface. Ensure the
2475 // surface object is cleared, but we don't want it actually
2476 // destroyed at this point.
2477 win.mSurfacePendingDestroy = false;
2478 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002479 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002480 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002481 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002482 "Keeping surface, will report destroy: " + win);
2483 win.mReportDestroySurface = true;
2484 outSurface.copyFrom(win.mSurface);
2485 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 }
2487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 if (focusMayChange) {
2489 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2490 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 imMayMove = false;
2492 }
2493 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2494 }
Romain Guy06882f82009-06-10 13:36:04 -07002495
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002496 // updateFocusedWindowLocked() already assigned layers so we only need to
2497 // reassign them at this point if the IM window state gets shuffled
2498 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002501 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2502 // Little hack here -- we -should- be able to rely on the
2503 // function to return true if the IME has moved and needs
2504 // its layer recomputed. However, if the IME was hidden
2505 // and isn't actually moved in the list, its layer may be
2506 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 assignLayers = true;
2508 }
2509 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002510 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002511 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002512 assignLayers = true;
2513 }
2514 }
Romain Guy06882f82009-06-10 13:36:04 -07002515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 mLayoutNeeded = true;
2517 win.mGivenInsetsPending = insetsPending;
2518 if (assignLayers) {
2519 assignLayersLocked();
2520 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002521 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002523 if (displayed && win.mIsWallpaper) {
2524 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002525 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 if (win.mAppToken != null) {
2528 win.mAppToken.updateReportedVisibilityLocked();
2529 }
2530 outFrame.set(win.mFrame);
2531 outContentInsets.set(win.mContentInsets);
2532 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002533 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002535 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 + ", requestedHeight=" + requestedHeight
2537 + ", viewVisibility=" + viewVisibility
2538 + "\nRelayout returning frame=" + outFrame
2539 + ", surface=" + outSurface);
2540
Joe Onorato8a9b2202010-02-26 18:56:32 -08002541 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2543
2544 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002545
2546 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 }
2548
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002549 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 sendNewConfiguration();
2551 }
Romain Guy06882f82009-06-10 13:36:04 -07002552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2556 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2557 }
2558
2559 public void finishDrawingWindow(Session session, IWindow client) {
2560 final long origId = Binder.clearCallingIdentity();
2561 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002562 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002564 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2565 adjustWallpaperWindowsLocked();
2566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 mLayoutNeeded = true;
2568 performLayoutAndPlaceSurfacesLocked();
2569 }
2570 }
2571 Binder.restoreCallingIdentity(origId);
2572 }
2573
2574 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002575 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 + (lp != null ? lp.packageName : null)
2577 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2578 if (lp != null && lp.windowAnimations != 0) {
2579 // If this is a system resource, don't try to load it from the
2580 // application resources. It is nice to avoid loading application
2581 // resources if we can.
2582 String packageName = lp.packageName != null ? lp.packageName : "android";
2583 int resId = lp.windowAnimations;
2584 if ((resId&0xFF000000) == 0x01000000) {
2585 packageName = "android";
2586 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002587 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 + packageName);
2589 return AttributeCache.instance().get(packageName, resId,
2590 com.android.internal.R.styleable.WindowAnimation);
2591 }
2592 return null;
2593 }
Romain Guy06882f82009-06-10 13:36:04 -07002594
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002595 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002596 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002597 + packageName + " resId=0x" + Integer.toHexString(resId));
2598 if (packageName != null) {
2599 if ((resId&0xFF000000) == 0x01000000) {
2600 packageName = "android";
2601 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002602 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002603 + packageName);
2604 return AttributeCache.instance().get(packageName, resId,
2605 com.android.internal.R.styleable.WindowAnimation);
2606 }
2607 return null;
2608 }
2609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 private void applyEnterAnimationLocked(WindowState win) {
2611 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2612 if (win.mEnterAnimationPending) {
2613 win.mEnterAnimationPending = false;
2614 transit = WindowManagerPolicy.TRANSIT_ENTER;
2615 }
2616
2617 applyAnimationLocked(win, transit, true);
2618 }
2619
2620 private boolean applyAnimationLocked(WindowState win,
2621 int transit, boolean isEntrance) {
2622 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2623 // If we are trying to apply an animation, but already running
2624 // an animation of the same type, then just leave that one alone.
2625 return true;
2626 }
Romain Guy06882f82009-06-10 13:36:04 -07002627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 // Only apply an animation if the display isn't frozen. If it is
2629 // frozen, there is no reason to animate and it can cause strange
2630 // artifacts when we unfreeze the display if some different animation
2631 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002632 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 int anim = mPolicy.selectAnimationLw(win, transit);
2634 int attr = -1;
2635 Animation a = null;
2636 if (anim != 0) {
2637 a = AnimationUtils.loadAnimation(mContext, anim);
2638 } else {
2639 switch (transit) {
2640 case WindowManagerPolicy.TRANSIT_ENTER:
2641 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2642 break;
2643 case WindowManagerPolicy.TRANSIT_EXIT:
2644 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2645 break;
2646 case WindowManagerPolicy.TRANSIT_SHOW:
2647 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2648 break;
2649 case WindowManagerPolicy.TRANSIT_HIDE:
2650 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2651 break;
2652 }
2653 if (attr >= 0) {
2654 a = loadAnimation(win.mAttrs, attr);
2655 }
2656 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002657 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2659 + " mAnimation=" + win.mAnimation
2660 + " isEntrance=" + isEntrance);
2661 if (a != null) {
2662 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002663 RuntimeException e = null;
2664 if (!HIDE_STACK_CRAWLS) {
2665 e = new RuntimeException();
2666 e.fillInStackTrace();
2667 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002668 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 }
2670 win.setAnimation(a);
2671 win.mAnimationIsEntrance = isEntrance;
2672 }
2673 } else {
2674 win.clearAnimation();
2675 }
2676
2677 return win.mAnimation != null;
2678 }
2679
2680 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2681 int anim = 0;
2682 Context context = mContext;
2683 if (animAttr >= 0) {
2684 AttributeCache.Entry ent = getCachedAnimations(lp);
2685 if (ent != null) {
2686 context = ent.context;
2687 anim = ent.array.getResourceId(animAttr, 0);
2688 }
2689 }
2690 if (anim != 0) {
2691 return AnimationUtils.loadAnimation(context, anim);
2692 }
2693 return null;
2694 }
Romain Guy06882f82009-06-10 13:36:04 -07002695
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002696 private Animation loadAnimation(String packageName, int resId) {
2697 int anim = 0;
2698 Context context = mContext;
2699 if (resId >= 0) {
2700 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2701 if (ent != null) {
2702 context = ent.context;
2703 anim = resId;
2704 }
2705 }
2706 if (anim != 0) {
2707 return AnimationUtils.loadAnimation(context, anim);
2708 }
2709 return null;
2710 }
2711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 private boolean applyAnimationLocked(AppWindowToken wtoken,
2713 WindowManager.LayoutParams lp, int transit, boolean enter) {
2714 // Only apply an animation if the display isn't frozen. If it is
2715 // frozen, there is no reason to animate and it can cause strange
2716 // artifacts when we unfreeze the display if some different animation
2717 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002718 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002719 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002720 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002721 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002722 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002723 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002724 } else if (mNextAppTransitionPackage != null) {
2725 a = loadAnimation(mNextAppTransitionPackage, enter ?
2726 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002727 } else {
2728 int animAttr = 0;
2729 switch (transit) {
2730 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2731 animAttr = enter
2732 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2733 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2734 break;
2735 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2736 animAttr = enter
2737 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2738 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2739 break;
2740 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2741 animAttr = enter
2742 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2743 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2744 break;
2745 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2746 animAttr = enter
2747 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2748 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2749 break;
2750 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2751 animAttr = enter
2752 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2753 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2754 break;
2755 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2756 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002757 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002758 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2759 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002760 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002761 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002762 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2763 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002764 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002765 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002766 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002767 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2768 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2769 break;
2770 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2771 animAttr = enter
2772 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2773 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2774 break;
2775 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2776 animAttr = enter
2777 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2778 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002779 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002780 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002781 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002782 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002783 + " anim=" + a
2784 + " animAttr=0x" + Integer.toHexString(animAttr)
2785 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 if (a != null) {
2788 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002789 RuntimeException e = null;
2790 if (!HIDE_STACK_CRAWLS) {
2791 e = new RuntimeException();
2792 e.fillInStackTrace();
2793 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002794 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 }
2796 wtoken.setAnimation(a);
2797 }
2798 } else {
2799 wtoken.clearAnimation();
2800 }
2801
2802 return wtoken.animation != null;
2803 }
2804
2805 // -------------------------------------------------------------
2806 // Application Window Tokens
2807 // -------------------------------------------------------------
2808
2809 public void validateAppTokens(List tokens) {
2810 int v = tokens.size()-1;
2811 int m = mAppTokens.size()-1;
2812 while (v >= 0 && m >= 0) {
2813 AppWindowToken wtoken = mAppTokens.get(m);
2814 if (wtoken.removed) {
2815 m--;
2816 continue;
2817 }
2818 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002819 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2821 }
2822 v--;
2823 m--;
2824 }
2825 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002826 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 v--;
2828 }
2829 while (m >= 0) {
2830 AppWindowToken wtoken = mAppTokens.get(m);
2831 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002832 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 }
2834 m--;
2835 }
2836 }
2837
2838 boolean checkCallingPermission(String permission, String func) {
2839 // Quick check: if the calling permission is me, it's all okay.
2840 if (Binder.getCallingPid() == Process.myPid()) {
2841 return true;
2842 }
Romain Guy06882f82009-06-10 13:36:04 -07002843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 if (mContext.checkCallingPermission(permission)
2845 == PackageManager.PERMISSION_GRANTED) {
2846 return true;
2847 }
2848 String msg = "Permission Denial: " + func + " from pid="
2849 + Binder.getCallingPid()
2850 + ", uid=" + Binder.getCallingUid()
2851 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002852 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 return false;
2854 }
Romain Guy06882f82009-06-10 13:36:04 -07002855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 AppWindowToken findAppWindowToken(IBinder token) {
2857 WindowToken wtoken = mTokenMap.get(token);
2858 if (wtoken == null) {
2859 return null;
2860 }
2861 return wtoken.appWindowToken;
2862 }
Romain Guy06882f82009-06-10 13:36:04 -07002863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 public void addWindowToken(IBinder token, int type) {
2865 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2866 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002867 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 }
Romain Guy06882f82009-06-10 13:36:04 -07002869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 synchronized(mWindowMap) {
2871 WindowToken wtoken = mTokenMap.get(token);
2872 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002873 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 return;
2875 }
2876 wtoken = new WindowToken(token, type, true);
2877 mTokenMap.put(token, wtoken);
2878 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002879 if (type == TYPE_WALLPAPER) {
2880 mWallpaperTokens.add(wtoken);
2881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 }
2883 }
Romain Guy06882f82009-06-10 13:36:04 -07002884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 public void removeWindowToken(IBinder token) {
2886 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2887 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002888 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 }
2890
2891 final long origId = Binder.clearCallingIdentity();
2892 synchronized(mWindowMap) {
2893 WindowToken wtoken = mTokenMap.remove(token);
2894 mTokenList.remove(wtoken);
2895 if (wtoken != null) {
2896 boolean delayed = false;
2897 if (!wtoken.hidden) {
2898 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 final int N = wtoken.windows.size();
2901 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 for (int i=0; i<N; i++) {
2904 WindowState win = wtoken.windows.get(i);
2905
2906 if (win.isAnimating()) {
2907 delayed = true;
2908 }
Romain Guy06882f82009-06-10 13:36:04 -07002909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 if (win.isVisibleNow()) {
2911 applyAnimationLocked(win,
2912 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 changed = true;
2914 }
2915 }
2916
2917 if (changed) {
2918 mLayoutNeeded = true;
2919 performLayoutAndPlaceSurfacesLocked();
2920 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2921 }
Romain Guy06882f82009-06-10 13:36:04 -07002922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 if (delayed) {
2924 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002925 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2926 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 }
2928 }
Romain Guy06882f82009-06-10 13:36:04 -07002929
Jeff Brownc5ed5912010-07-14 18:48:53 -07002930 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002932 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 }
2934 }
2935 Binder.restoreCallingIdentity(origId);
2936 }
2937
2938 public void addAppToken(int addPos, IApplicationToken token,
2939 int groupId, int requestedOrientation, boolean fullscreen) {
2940 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2941 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002942 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 }
Jeff Brown349703e2010-06-22 01:27:15 -07002944
2945 // Get the dispatching timeout here while we are not holding any locks so that it
2946 // can be cached by the AppWindowToken. The timeout value is used later by the
2947 // input dispatcher in code that does hold locks. If we did not cache the value
2948 // here we would run the chance of introducing a deadlock between the window manager
2949 // (which holds locks while updating the input dispatcher state) and the activity manager
2950 // (which holds locks while querying the application token).
2951 long inputDispatchingTimeoutNanos;
2952 try {
2953 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2954 } catch (RemoteException ex) {
2955 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2956 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2957 }
Romain Guy06882f82009-06-10 13:36:04 -07002958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 synchronized(mWindowMap) {
2960 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2961 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002962 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 return;
2964 }
2965 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002966 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 wtoken.groupId = groupId;
2968 wtoken.appFullscreen = fullscreen;
2969 wtoken.requestedOrientation = requestedOrientation;
2970 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 mTokenMap.put(token.asBinder(), wtoken);
2973 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 // Application tokens start out hidden.
2976 wtoken.hidden = true;
2977 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 //dump();
2980 }
2981 }
Romain Guy06882f82009-06-10 13:36:04 -07002982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 public void setAppGroupId(IBinder token, int groupId) {
2984 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2985 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002986 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 }
2988
2989 synchronized(mWindowMap) {
2990 AppWindowToken wtoken = findAppWindowToken(token);
2991 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002992 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 return;
2994 }
2995 wtoken.groupId = groupId;
2996 }
2997 }
Romain Guy06882f82009-06-10 13:36:04 -07002998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 public int getOrientationFromWindowsLocked() {
3000 int pos = mWindows.size() - 1;
3001 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003002 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003 pos--;
3004 if (wtoken.mAppToken != null) {
3005 // We hit an application window. so the orientation will be determined by the
3006 // app window. No point in continuing further.
3007 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3008 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003009 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 continue;
3011 }
3012 int req = wtoken.mAttrs.screenOrientation;
3013 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3014 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3015 continue;
3016 } else {
3017 return req;
3018 }
3019 }
3020 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003024 int pos = mAppTokens.size() - 1;
3025 int curGroup = 0;
3026 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3027 boolean findingBehind = false;
3028 boolean haveGroup = false;
3029 boolean lastFullscreen = false;
3030 while (pos >= 0) {
3031 AppWindowToken wtoken = mAppTokens.get(pos);
3032 pos--;
3033 // if we're about to tear down this window and not seek for
3034 // the behind activity, don't use it for orientation
3035 if (!findingBehind
3036 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3037 continue;
3038 }
3039
3040 if (!haveGroup) {
3041 // We ignore any hidden applications on the top.
3042 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003043 continue;
3044 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003045 haveGroup = true;
3046 curGroup = wtoken.groupId;
3047 lastOrientation = wtoken.requestedOrientation;
3048 } else if (curGroup != wtoken.groupId) {
3049 // If we have hit a new application group, and the bottom
3050 // of the previous group didn't explicitly say to use
3051 // the orientation behind it, and the last app was
3052 // full screen, then we'll stick with the
3053 // user's orientation.
3054 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3055 && lastFullscreen) {
3056 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003059 int or = wtoken.requestedOrientation;
3060 // If this application is fullscreen, and didn't explicitly say
3061 // to use the orientation behind it, then just take whatever
3062 // orientation it has and ignores whatever is under it.
3063 lastFullscreen = wtoken.appFullscreen;
3064 if (lastFullscreen
3065 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3066 return or;
3067 }
3068 // If this application has requested an explicit orientation,
3069 // then use it.
3070 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3071 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3072 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3074 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3075 return or;
3076 }
3077 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3078 }
3079 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 }
Romain Guy06882f82009-06-10 13:36:04 -07003081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003083 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003084 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3085 "updateOrientationFromAppTokens()")) {
3086 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3087 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003088
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003089 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003091
3092 synchronized(mWindowMap) {
3093 if (updateOrientationFromAppTokensLocked()) {
3094 if (freezeThisOneIfNeeded != null) {
3095 AppWindowToken wtoken = findAppWindowToken(
3096 freezeThisOneIfNeeded);
3097 if (wtoken != null) {
3098 startAppFreezingScreenLocked(wtoken,
3099 ActivityInfo.CONFIG_ORIENTATION);
3100 }
3101 }
3102 config = computeNewConfigurationLocked();
3103
3104 } else if (currentConfig != null) {
3105 // No obvious action we need to take, but if our current
3106 // state mismatches the activity maanager's, update it
3107 mTempConfiguration.setToDefaults();
3108 if (computeNewConfigurationLocked(mTempConfiguration)) {
3109 if (currentConfig.diff(mTempConfiguration) != 0) {
3110 mWaitingForConfig = true;
3111 mLayoutNeeded = true;
3112 startFreezingDisplayLocked();
3113 config = new Configuration(mTempConfiguration);
3114 }
3115 }
3116 }
3117 }
3118
Dianne Hackborncfaef692009-06-15 14:24:44 -07003119 Binder.restoreCallingIdentity(ident);
3120 return config;
3121 }
3122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003124 * Determine the new desired orientation of the display, returning
3125 * a non-null new Configuration if it has changed from the current
3126 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3127 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3128 * SCREEN. This will typically be done for you if you call
3129 * sendNewConfiguration().
3130 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 * The orientation is computed from non-application windows first. If none of
3132 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003133 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3135 * android.os.IBinder)
3136 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003137 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003138 if (mDisplayFrozen) {
3139 // If the display is frozen, some activities may be in the middle
3140 // of restarting, and thus have removed their old window. If the
3141 // window has the flag to hide the lock screen, then the lock screen
3142 // can re-appear and inflict its own orientation on us. Keep the
3143 // orientation stable until this all settles down.
3144 return false;
3145 }
3146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 long ident = Binder.clearCallingIdentity();
3149 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003150 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 mForcedAppOrientation = req;
3154 //send a message to Policy indicating orientation change to take
3155 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003156 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003157 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3158 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3159 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 }
3161 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003162
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003163 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 } finally {
3165 Binder.restoreCallingIdentity(ident);
3166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 }
Romain Guy06882f82009-06-10 13:36:04 -07003168
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003169 int computeForcedAppOrientationLocked() {
3170 int req = getOrientationFromWindowsLocked();
3171 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3172 req = getOrientationFromAppTokensLocked();
3173 }
3174 return req;
3175 }
Romain Guy06882f82009-06-10 13:36:04 -07003176
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003177 public void setNewConfiguration(Configuration config) {
3178 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3179 "setNewConfiguration()")) {
3180 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3181 }
3182
3183 synchronized(mWindowMap) {
3184 mCurConfiguration = new Configuration(config);
3185 mWaitingForConfig = false;
3186 performLayoutAndPlaceSurfacesLocked();
3187 }
3188 }
3189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3191 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3192 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003193 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 }
Romain Guy06882f82009-06-10 13:36:04 -07003195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 synchronized(mWindowMap) {
3197 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3198 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003199 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 return;
3201 }
Romain Guy06882f82009-06-10 13:36:04 -07003202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003203 wtoken.requestedOrientation = requestedOrientation;
3204 }
3205 }
Romain Guy06882f82009-06-10 13:36:04 -07003206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 public int getAppOrientation(IApplicationToken token) {
3208 synchronized(mWindowMap) {
3209 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3210 if (wtoken == null) {
3211 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3212 }
Romain Guy06882f82009-06-10 13:36:04 -07003213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 return wtoken.requestedOrientation;
3215 }
3216 }
Romain Guy06882f82009-06-10 13:36:04 -07003217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3219 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3220 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003221 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 }
3223
3224 synchronized(mWindowMap) {
3225 boolean changed = false;
3226 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003227 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 changed = mFocusedApp != null;
3229 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003230 if (changed) {
3231 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 } else {
3234 AppWindowToken newFocus = findAppWindowToken(token);
3235 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003236 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 return;
3238 }
3239 changed = mFocusedApp != newFocus;
3240 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003241 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003242 if (changed) {
3243 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 }
3246
3247 if (moveFocusNow && changed) {
3248 final long origId = Binder.clearCallingIdentity();
3249 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3250 Binder.restoreCallingIdentity(origId);
3251 }
3252 }
3253 }
3254
3255 public void prepareAppTransition(int transit) {
3256 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3257 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003258 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 }
Romain Guy06882f82009-06-10 13:36:04 -07003260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003262 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 TAG, "Prepare app transition: transit=" + transit
3264 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003265 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003266 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3267 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003269 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3270 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3271 // Opening a new task always supersedes a close for the anim.
3272 mNextAppTransition = transit;
3273 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3274 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3275 // Opening a new activity always supersedes a close for the anim.
3276 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003277 }
3278 mAppTransitionReady = false;
3279 mAppTransitionTimeout = false;
3280 mStartingIconInTransition = false;
3281 mSkipAppTransitionAnimation = false;
3282 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3283 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3284 5000);
3285 }
3286 }
3287 }
3288
3289 public int getPendingAppTransition() {
3290 return mNextAppTransition;
3291 }
Romain Guy06882f82009-06-10 13:36:04 -07003292
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003293 public void overridePendingAppTransition(String packageName,
3294 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003295 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003296 mNextAppTransitionPackage = packageName;
3297 mNextAppTransitionEnter = enterAnim;
3298 mNextAppTransitionExit = exitAnim;
3299 }
3300 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 public void executeAppTransition() {
3303 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3304 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003305 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 }
Romain Guy06882f82009-06-10 13:36:04 -07003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003309 if (DEBUG_APP_TRANSITIONS) {
3310 RuntimeException e = new RuntimeException("here");
3311 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003312 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003313 + mNextAppTransition, e);
3314 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003315 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 mAppTransitionReady = true;
3317 final long origId = Binder.clearCallingIdentity();
3318 performLayoutAndPlaceSurfacesLocked();
3319 Binder.restoreCallingIdentity(origId);
3320 }
3321 }
3322 }
3323
3324 public void setAppStartingWindow(IBinder token, String pkg,
3325 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3326 IBinder transferFrom, boolean createIfNeeded) {
3327 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3328 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003329 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 }
3331
3332 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003333 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3335 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 AppWindowToken wtoken = findAppWindowToken(token);
3338 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003339 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 return;
3341 }
3342
3343 // If the display is frozen, we won't do anything until the
3344 // actual window is displayed so there is no reason to put in
3345 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003346 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 return;
3348 }
Romain Guy06882f82009-06-10 13:36:04 -07003349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 if (wtoken.startingData != null) {
3351 return;
3352 }
Romain Guy06882f82009-06-10 13:36:04 -07003353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 if (transferFrom != null) {
3355 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3356 if (ttoken != null) {
3357 WindowState startingWindow = ttoken.startingWindow;
3358 if (startingWindow != null) {
3359 if (mStartingIconInTransition) {
3360 // In this case, the starting icon has already
3361 // been displayed, so start letting windows get
3362 // shown immediately without any more transitions.
3363 mSkipAppTransitionAnimation = true;
3364 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003365 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 "Moving existing starting from " + ttoken
3367 + " to " + wtoken);
3368 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 // Transfer the starting window over to the new
3371 // token.
3372 wtoken.startingData = ttoken.startingData;
3373 wtoken.startingView = ttoken.startingView;
3374 wtoken.startingWindow = startingWindow;
3375 ttoken.startingData = null;
3376 ttoken.startingView = null;
3377 ttoken.startingWindow = null;
3378 ttoken.startingMoved = true;
3379 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003380 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003382 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003383 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003385 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 ttoken.windows.remove(startingWindow);
3387 ttoken.allAppWindows.remove(startingWindow);
3388 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 // Propagate other interesting state between the
3391 // tokens. If the old token is displayed, we should
3392 // immediately force the new one to be displayed. If
3393 // it is animating, we need to move that animation to
3394 // the new one.
3395 if (ttoken.allDrawn) {
3396 wtoken.allDrawn = true;
3397 }
3398 if (ttoken.firstWindowDrawn) {
3399 wtoken.firstWindowDrawn = true;
3400 }
3401 if (!ttoken.hidden) {
3402 wtoken.hidden = false;
3403 wtoken.hiddenRequested = false;
3404 wtoken.willBeHidden = false;
3405 }
3406 if (wtoken.clientHidden != ttoken.clientHidden) {
3407 wtoken.clientHidden = ttoken.clientHidden;
3408 wtoken.sendAppVisibilityToClients();
3409 }
3410 if (ttoken.animation != null) {
3411 wtoken.animation = ttoken.animation;
3412 wtoken.animating = ttoken.animating;
3413 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3414 ttoken.animation = null;
3415 ttoken.animLayerAdjustment = 0;
3416 wtoken.updateLayers();
3417 ttoken.updateLayers();
3418 }
Romain Guy06882f82009-06-10 13:36:04 -07003419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 mLayoutNeeded = true;
3422 performLayoutAndPlaceSurfacesLocked();
3423 Binder.restoreCallingIdentity(origId);
3424 return;
3425 } else if (ttoken.startingData != null) {
3426 // The previous app was getting ready to show a
3427 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003428 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 "Moving pending starting from " + ttoken
3430 + " to " + wtoken);
3431 wtoken.startingData = ttoken.startingData;
3432 ttoken.startingData = null;
3433 ttoken.startingMoved = true;
3434 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3435 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3436 // want to process the message ASAP, before any other queued
3437 // messages.
3438 mH.sendMessageAtFrontOfQueue(m);
3439 return;
3440 }
3441 }
3442 }
3443
3444 // There is no existing starting window, and the caller doesn't
3445 // want us to create one, so that's it!
3446 if (!createIfNeeded) {
3447 return;
3448 }
Romain Guy06882f82009-06-10 13:36:04 -07003449
Dianne Hackborn284ac932009-08-28 10:34:25 -07003450 // If this is a translucent or wallpaper window, then don't
3451 // show a starting window -- the current effect (a full-screen
3452 // opaque starting window that fades away to the real contents
3453 // when it is ready) does not work for this.
3454 if (theme != 0) {
3455 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3456 com.android.internal.R.styleable.Window);
3457 if (ent.array.getBoolean(
3458 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3459 return;
3460 }
3461 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003462 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3463 return;
3464 }
3465 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003466 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3467 return;
3468 }
3469 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003471 mStartingIconInTransition = true;
3472 wtoken.startingData = new StartingData(
3473 pkg, theme, nonLocalizedLabel,
3474 labelRes, icon);
3475 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3476 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3477 // want to process the message ASAP, before any other queued
3478 // messages.
3479 mH.sendMessageAtFrontOfQueue(m);
3480 }
3481 }
3482
3483 public void setAppWillBeHidden(IBinder token) {
3484 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3485 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003486 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 }
3488
3489 AppWindowToken wtoken;
3490
3491 synchronized(mWindowMap) {
3492 wtoken = findAppWindowToken(token);
3493 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003494 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 -08003495 return;
3496 }
3497 wtoken.willBeHidden = true;
3498 }
3499 }
Romain Guy06882f82009-06-10 13:36:04 -07003500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3502 boolean visible, int transit, boolean performLayout) {
3503 boolean delayed = false;
3504
3505 if (wtoken.clientHidden == visible) {
3506 wtoken.clientHidden = !visible;
3507 wtoken.sendAppVisibilityToClients();
3508 }
Romain Guy06882f82009-06-10 13:36:04 -07003509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 wtoken.willBeHidden = false;
3511 if (wtoken.hidden == visible) {
3512 final int N = wtoken.allAppWindows.size();
3513 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003514 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3516 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003519
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003520 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 if (wtoken.animation == sDummyAnimation) {
3522 wtoken.animation = null;
3523 }
3524 applyAnimationLocked(wtoken, lp, transit, visible);
3525 changed = true;
3526 if (wtoken.animation != null) {
3527 delayed = runningAppAnimation = true;
3528 }
3529 }
Romain Guy06882f82009-06-10 13:36:04 -07003530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 for (int i=0; i<N; i++) {
3532 WindowState win = wtoken.allAppWindows.get(i);
3533 if (win == wtoken.startingWindow) {
3534 continue;
3535 }
3536
3537 if (win.isAnimating()) {
3538 delayed = true;
3539 }
Romain Guy06882f82009-06-10 13:36:04 -07003540
Joe Onorato8a9b2202010-02-26 18:56:32 -08003541 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 //win.dump(" ");
3543 if (visible) {
3544 if (!win.isVisibleNow()) {
3545 if (!runningAppAnimation) {
3546 applyAnimationLocked(win,
3547 WindowManagerPolicy.TRANSIT_ENTER, true);
3548 }
3549 changed = true;
3550 }
3551 } else if (win.isVisibleNow()) {
3552 if (!runningAppAnimation) {
3553 applyAnimationLocked(win,
3554 WindowManagerPolicy.TRANSIT_EXIT, false);
3555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 changed = true;
3557 }
3558 }
3559
3560 wtoken.hidden = wtoken.hiddenRequested = !visible;
3561 if (!visible) {
3562 unsetAppFreezingScreenLocked(wtoken, true, true);
3563 } else {
3564 // If we are being set visible, and the starting window is
3565 // not yet displayed, then make sure it doesn't get displayed.
3566 WindowState swin = wtoken.startingWindow;
3567 if (swin != null && (swin.mDrawPending
3568 || swin.mCommitDrawPending)) {
3569 swin.mPolicyVisibility = false;
3570 swin.mPolicyVisibilityAfterAnim = false;
3571 }
3572 }
Romain Guy06882f82009-06-10 13:36:04 -07003573
Joe Onorato8a9b2202010-02-26 18:56:32 -08003574 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3576 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003577
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003578 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003580 if (performLayout) {
3581 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3582 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003583 } else {
3584 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 }
3587 }
3588
3589 if (wtoken.animation != null) {
3590 delayed = true;
3591 }
Romain Guy06882f82009-06-10 13:36:04 -07003592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 return delayed;
3594 }
3595
3596 public void setAppVisibility(IBinder token, boolean visible) {
3597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3598 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 }
3601
3602 AppWindowToken wtoken;
3603
3604 synchronized(mWindowMap) {
3605 wtoken = findAppWindowToken(token);
3606 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003607 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 return;
3609 }
3610
3611 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003612 RuntimeException e = null;
3613 if (!HIDE_STACK_CRAWLS) {
3614 e = new RuntimeException();
3615 e.fillInStackTrace();
3616 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003617 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 + "): mNextAppTransition=" + mNextAppTransition
3619 + " hidden=" + wtoken.hidden
3620 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3621 }
Romain Guy06882f82009-06-10 13:36:04 -07003622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 // If we are preparing an app transition, then delay changing
3624 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003625 if (!mDisplayFrozen && mPolicy.isScreenOn()
3626 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 // Already in requested state, don't do anything more.
3628 if (wtoken.hiddenRequested != visible) {
3629 return;
3630 }
3631 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003632
Joe Onorato8a9b2202010-02-26 18:56:32 -08003633 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 TAG, "Setting dummy animation on: " + wtoken);
3635 wtoken.setDummyAnimation();
3636 mOpeningApps.remove(wtoken);
3637 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003638 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 wtoken.inPendingTransaction = true;
3640 if (visible) {
3641 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 wtoken.startingDisplayed = false;
3643 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003644
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003645 // If the token is currently hidden (should be the
3646 // common case), then we need to set up to wait for
3647 // its windows to be ready.
3648 if (wtoken.hidden) {
3649 wtoken.allDrawn = false;
3650 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003651
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003652 if (wtoken.clientHidden) {
3653 // In the case where we are making an app visible
3654 // but holding off for a transition, we still need
3655 // to tell the client to make its windows visible so
3656 // they get drawn. Otherwise, we will wait on
3657 // performing the transition until all windows have
3658 // been drawn, they never will be, and we are sad.
3659 wtoken.clientHidden = false;
3660 wtoken.sendAppVisibilityToClients();
3661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 }
3663 } else {
3664 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003665
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003666 // If the token is currently visible (should be the
3667 // common case), then set up to wait for it to be hidden.
3668 if (!wtoken.hidden) {
3669 wtoken.waitingToHide = true;
3670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 }
3672 return;
3673 }
Romain Guy06882f82009-06-10 13:36:04 -07003674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003676 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 wtoken.updateReportedVisibilityLocked();
3678 Binder.restoreCallingIdentity(origId);
3679 }
3680 }
3681
3682 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3683 boolean unfreezeSurfaceNow, boolean force) {
3684 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003685 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 + " force=" + force);
3687 final int N = wtoken.allAppWindows.size();
3688 boolean unfrozeWindows = false;
3689 for (int i=0; i<N; i++) {
3690 WindowState w = wtoken.allAppWindows.get(i);
3691 if (w.mAppFreezing) {
3692 w.mAppFreezing = false;
3693 if (w.mSurface != null && !w.mOrientationChanging) {
3694 w.mOrientationChanging = true;
3695 }
3696 unfrozeWindows = true;
3697 }
3698 }
3699 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003700 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 wtoken.freezingScreen = false;
3702 mAppsFreezingScreen--;
3703 }
3704 if (unfreezeSurfaceNow) {
3705 if (unfrozeWindows) {
3706 mLayoutNeeded = true;
3707 performLayoutAndPlaceSurfacesLocked();
3708 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003709 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 }
3711 }
3712 }
Romain Guy06882f82009-06-10 13:36:04 -07003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3715 int configChanges) {
3716 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003717 RuntimeException e = null;
3718 if (!HIDE_STACK_CRAWLS) {
3719 e = new RuntimeException();
3720 e.fillInStackTrace();
3721 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003722 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 + ": hidden=" + wtoken.hidden + " freezing="
3724 + wtoken.freezingScreen, e);
3725 }
3726 if (!wtoken.hiddenRequested) {
3727 if (!wtoken.freezingScreen) {
3728 wtoken.freezingScreen = true;
3729 mAppsFreezingScreen++;
3730 if (mAppsFreezingScreen == 1) {
3731 startFreezingDisplayLocked();
3732 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3733 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3734 5000);
3735 }
3736 }
3737 final int N = wtoken.allAppWindows.size();
3738 for (int i=0; i<N; i++) {
3739 WindowState w = wtoken.allAppWindows.get(i);
3740 w.mAppFreezing = true;
3741 }
3742 }
3743 }
Romain Guy06882f82009-06-10 13:36:04 -07003744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 public void startAppFreezingScreen(IBinder token, int configChanges) {
3746 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3747 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003748 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 }
3750
3751 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003752 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003753 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 return;
3755 }
Romain Guy06882f82009-06-10 13:36:04 -07003756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003757 AppWindowToken wtoken = findAppWindowToken(token);
3758 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003759 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 return;
3761 }
3762 final long origId = Binder.clearCallingIdentity();
3763 startAppFreezingScreenLocked(wtoken, configChanges);
3764 Binder.restoreCallingIdentity(origId);
3765 }
3766 }
Romain Guy06882f82009-06-10 13:36:04 -07003767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 public void stopAppFreezingScreen(IBinder token, boolean force) {
3769 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3770 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003771 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 }
3773
3774 synchronized(mWindowMap) {
3775 AppWindowToken wtoken = findAppWindowToken(token);
3776 if (wtoken == null || wtoken.appToken == null) {
3777 return;
3778 }
3779 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003780 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3782 unsetAppFreezingScreenLocked(wtoken, true, force);
3783 Binder.restoreCallingIdentity(origId);
3784 }
3785 }
Romain Guy06882f82009-06-10 13:36:04 -07003786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 public void removeAppToken(IBinder token) {
3788 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3789 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003790 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 }
3792
3793 AppWindowToken wtoken = null;
3794 AppWindowToken startingToken = null;
3795 boolean delayed = false;
3796
3797 final long origId = Binder.clearCallingIdentity();
3798 synchronized(mWindowMap) {
3799 WindowToken basewtoken = mTokenMap.remove(token);
3800 mTokenList.remove(basewtoken);
3801 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003802 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003803 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 wtoken.inPendingTransaction = false;
3805 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003806 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 if (mClosingApps.contains(wtoken)) {
3808 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003809 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003811 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 delayed = true;
3813 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003814 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 TAG, "Removing app " + wtoken + " delayed=" + delayed
3816 + " animation=" + wtoken.animation
3817 + " animating=" + wtoken.animating);
3818 if (delayed) {
3819 // set the token aside because it has an active animation to be finished
3820 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003821 } else {
3822 // Make sure there is no animation running on this token,
3823 // so any windows associated with it will be removed as
3824 // soon as their animations are complete
3825 wtoken.animation = null;
3826 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003827 }
3828 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003829 if (mLastEnterAnimToken == wtoken) {
3830 mLastEnterAnimToken = null;
3831 mLastEnterAnimParams = null;
3832 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 wtoken.removed = true;
3834 if (wtoken.startingData != null) {
3835 startingToken = wtoken;
3836 }
3837 unsetAppFreezingScreenLocked(wtoken, true, true);
3838 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003839 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 mFocusedApp = null;
3841 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003842 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 }
3844 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003845 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 }
Romain Guy06882f82009-06-10 13:36:04 -07003847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 if (!delayed && wtoken != null) {
3849 wtoken.updateReportedVisibilityLocked();
3850 }
3851 }
3852 Binder.restoreCallingIdentity(origId);
3853
3854 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003855 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 + startingToken + ": app token removed");
3857 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3858 mH.sendMessage(m);
3859 }
3860 }
3861
3862 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3863 final int NW = token.windows.size();
3864 for (int i=0; i<NW; i++) {
3865 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003866 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003868 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 int j = win.mChildWindows.size();
3870 while (j > 0) {
3871 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003872 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003873 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003874 "Tmp removing child window " + cwin);
3875 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 }
3877 }
3878 return NW > 0;
3879 }
3880
3881 void dumpAppTokensLocked() {
3882 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003883 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884 }
3885 }
Romain Guy06882f82009-06-10 13:36:04 -07003886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003887 void dumpWindowsLocked() {
3888 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003889 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 }
3891 }
Romain Guy06882f82009-06-10 13:36:04 -07003892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 private int findWindowOffsetLocked(int tokenPos) {
3894 final int NW = mWindows.size();
3895
3896 if (tokenPos >= mAppTokens.size()) {
3897 int i = NW;
3898 while (i > 0) {
3899 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003900 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003901 if (win.getAppToken() != null) {
3902 return i+1;
3903 }
3904 }
3905 }
3906
3907 while (tokenPos > 0) {
3908 // Find the first app token below the new position that has
3909 // a window displayed.
3910 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003911 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003912 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003913 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003914 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003915 "Skipping token -- currently sending to bottom");
3916 tokenPos--;
3917 continue;
3918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 int i = wtoken.windows.size();
3920 while (i > 0) {
3921 i--;
3922 WindowState win = wtoken.windows.get(i);
3923 int j = win.mChildWindows.size();
3924 while (j > 0) {
3925 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003926 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003927 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003928 for (int pos=NW-1; pos>=0; pos--) {
3929 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003930 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 "Found child win @" + (pos+1));
3932 return pos+1;
3933 }
3934 }
3935 }
3936 }
3937 for (int pos=NW-1; pos>=0; pos--) {
3938 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003939 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 return pos+1;
3941 }
3942 }
3943 }
3944 tokenPos--;
3945 }
3946
3947 return 0;
3948 }
3949
3950 private final int reAddWindowLocked(int index, WindowState win) {
3951 final int NCW = win.mChildWindows.size();
3952 boolean added = false;
3953 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003954 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003955 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003956 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003957 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 mWindows.add(index, win);
3959 index++;
3960 added = true;
3961 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003962 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003963 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 mWindows.add(index, cwin);
3965 index++;
3966 }
3967 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003968 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003969 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 mWindows.add(index, win);
3971 index++;
3972 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003973 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003974 return index;
3975 }
Romain Guy06882f82009-06-10 13:36:04 -07003976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3978 final int NW = token.windows.size();
3979 for (int i=0; i<NW; i++) {
3980 index = reAddWindowLocked(index, token.windows.get(i));
3981 }
3982 return index;
3983 }
3984
3985 public void moveAppToken(int index, IBinder token) {
3986 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3987 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003988 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 }
3990
3991 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003992 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 if (DEBUG_REORDER) dumpAppTokensLocked();
3994 final AppWindowToken wtoken = findAppWindowToken(token);
3995 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003996 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 + token + " (" + wtoken + ")");
3998 return;
3999 }
4000 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004001 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004005 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 if (DEBUG_REORDER) dumpWindowsLocked();
4007 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004008 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 if (DEBUG_REORDER) dumpWindowsLocked();
4010 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004011 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 if (DEBUG_REORDER) dumpWindowsLocked();
4013 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 mLayoutNeeded = true;
4015 performLayoutAndPlaceSurfacesLocked();
4016 }
4017 Binder.restoreCallingIdentity(origId);
4018 }
4019 }
4020
4021 private void removeAppTokensLocked(List<IBinder> tokens) {
4022 // XXX This should be done more efficiently!
4023 // (take advantage of the fact that both lists should be
4024 // ordered in the same way.)
4025 int N = tokens.size();
4026 for (int i=0; i<N; i++) {
4027 IBinder token = tokens.get(i);
4028 final AppWindowToken wtoken = findAppWindowToken(token);
4029 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004030 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 + token + " (" + wtoken + ")");
4032 i--;
4033 N--;
4034 }
4035 }
4036 }
4037
Dianne Hackborna8f60182009-09-01 19:01:50 -07004038 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4039 boolean updateFocusAndLayout) {
4040 // First remove all of the windows from the list.
4041 tmpRemoveAppWindowsLocked(wtoken);
4042
4043 // Where to start adding?
4044 int pos = findWindowOffsetLocked(tokenPos);
4045
4046 // And now add them back at the correct place.
4047 pos = reAddAppWindowsLocked(pos, wtoken);
4048
4049 if (updateFocusAndLayout) {
4050 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4051 assignLayersLocked();
4052 }
4053 mLayoutNeeded = true;
4054 performLayoutAndPlaceSurfacesLocked();
4055 }
4056 }
4057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004058 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4059 // First remove all of the windows from the list.
4060 final int N = tokens.size();
4061 int i;
4062 for (i=0; i<N; i++) {
4063 WindowToken token = mTokenMap.get(tokens.get(i));
4064 if (token != null) {
4065 tmpRemoveAppWindowsLocked(token);
4066 }
4067 }
4068
4069 // Where to start adding?
4070 int pos = findWindowOffsetLocked(tokenPos);
4071
4072 // And now add them back at the correct place.
4073 for (i=0; i<N; i++) {
4074 WindowToken token = mTokenMap.get(tokens.get(i));
4075 if (token != null) {
4076 pos = reAddAppWindowsLocked(pos, token);
4077 }
4078 }
4079
Dianne Hackborna8f60182009-09-01 19:01:50 -07004080 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4081 assignLayersLocked();
4082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 mLayoutNeeded = true;
4084 performLayoutAndPlaceSurfacesLocked();
4085
4086 //dump();
4087 }
4088
4089 public void moveAppTokensToTop(List<IBinder> tokens) {
4090 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4091 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004092 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 }
4094
4095 final long origId = Binder.clearCallingIdentity();
4096 synchronized(mWindowMap) {
4097 removeAppTokensLocked(tokens);
4098 final int N = tokens.size();
4099 for (int i=0; i<N; i++) {
4100 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4101 if (wt != null) {
4102 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004103 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004104 mToTopApps.remove(wt);
4105 mToBottomApps.remove(wt);
4106 mToTopApps.add(wt);
4107 wt.sendingToBottom = false;
4108 wt.sendingToTop = true;
4109 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 }
4111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004112
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004113 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004114 moveAppWindowsLocked(tokens, mAppTokens.size());
4115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 }
4117 Binder.restoreCallingIdentity(origId);
4118 }
4119
4120 public void moveAppTokensToBottom(List<IBinder> tokens) {
4121 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4122 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004123 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004124 }
4125
4126 final long origId = Binder.clearCallingIdentity();
4127 synchronized(mWindowMap) {
4128 removeAppTokensLocked(tokens);
4129 final int N = tokens.size();
4130 int pos = 0;
4131 for (int i=0; i<N; i++) {
4132 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4133 if (wt != null) {
4134 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004135 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004136 mToTopApps.remove(wt);
4137 mToBottomApps.remove(wt);
4138 mToBottomApps.add(i, wt);
4139 wt.sendingToTop = false;
4140 wt.sendingToBottom = true;
4141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004142 pos++;
4143 }
4144 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004145
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004146 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004147 moveAppWindowsLocked(tokens, 0);
4148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 }
4150 Binder.restoreCallingIdentity(origId);
4151 }
4152
4153 // -------------------------------------------------------------
4154 // Misc IWindowSession methods
4155 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004156
Jim Miller284b62e2010-06-08 14:27:42 -07004157 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004158 {
Jim Miller284b62e2010-06-08 14:27:42 -07004159 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4160 // called before DevicePolicyManagerService has started.
4161 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4162 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4163 Context.DEVICE_POLICY_SERVICE);
4164 if (dpm != null) {
4165 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4166 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4167 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4168 }
Jim Millerd6b57052010-06-07 17:52:42 -07004169 }
Jim Miller284b62e2010-06-08 14:27:42 -07004170 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004171 }
4172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004174 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 != PackageManager.PERMISSION_GRANTED) {
4176 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4177 }
Jim Millerd6b57052010-06-07 17:52:42 -07004178
Jim Miller284b62e2010-06-08 14:27:42 -07004179 synchronized (mKeyguardTokenWatcher) {
4180 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 }
4183
4184 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004185 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 != PackageManager.PERMISSION_GRANTED) {
4187 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4188 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189
Jim Miller284b62e2010-06-08 14:27:42 -07004190 synchronized (mKeyguardTokenWatcher) {
4191 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004192
Jim Miller284b62e2010-06-08 14:27:42 -07004193 if (!mKeyguardTokenWatcher.isAcquired()) {
4194 // If we are the last one to reenable the keyguard wait until
4195 // we have actually finished reenabling until returning.
4196 // It is possible that reenableKeyguard() can be called before
4197 // the previous disableKeyguard() is handled, in which case
4198 // neither mKeyguardTokenWatcher.acquired() or released() would
4199 // be called. In that case mKeyguardDisabled will be false here
4200 // and we have nothing to wait for.
4201 while (mKeyguardDisabled) {
4202 try {
4203 mKeyguardTokenWatcher.wait();
4204 } catch (InterruptedException e) {
4205 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004206 }
4207 }
4208 }
4209 }
4210 }
4211
4212 /**
4213 * @see android.app.KeyguardManager#exitKeyguardSecurely
4214 */
4215 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004216 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004217 != PackageManager.PERMISSION_GRANTED) {
4218 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4219 }
4220 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4221 public void onKeyguardExitResult(boolean success) {
4222 try {
4223 callback.onKeyguardExitResult(success);
4224 } catch (RemoteException e) {
4225 // Client has died, we don't care.
4226 }
4227 }
4228 });
4229 }
4230
4231 public boolean inKeyguardRestrictedInputMode() {
4232 return mPolicy.inKeyguardRestrictedKeyInputMode();
4233 }
Romain Guy06882f82009-06-10 13:36:04 -07004234
Dianne Hackbornffa42482009-09-23 22:20:11 -07004235 public void closeSystemDialogs(String reason) {
4236 synchronized(mWindowMap) {
4237 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004238 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004239 if (w.mSurface != null) {
4240 try {
4241 w.mClient.closeSystemDialogs(reason);
4242 } catch (RemoteException e) {
4243 }
4244 }
4245 }
4246 }
4247 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 static float fixScale(float scale) {
4250 if (scale < 0) scale = 0;
4251 else if (scale > 20) scale = 20;
4252 return Math.abs(scale);
4253 }
Romain Guy06882f82009-06-10 13:36:04 -07004254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 public void setAnimationScale(int which, float scale) {
4256 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4257 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004258 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004259 }
4260
4261 if (scale < 0) scale = 0;
4262 else if (scale > 20) scale = 20;
4263 scale = Math.abs(scale);
4264 switch (which) {
4265 case 0: mWindowAnimationScale = fixScale(scale); break;
4266 case 1: mTransitionAnimationScale = fixScale(scale); break;
4267 }
Romain Guy06882f82009-06-10 13:36:04 -07004268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 // Persist setting
4270 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4271 }
Romain Guy06882f82009-06-10 13:36:04 -07004272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 public void setAnimationScales(float[] scales) {
4274 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4275 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004276 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004277 }
4278
4279 if (scales != null) {
4280 if (scales.length >= 1) {
4281 mWindowAnimationScale = fixScale(scales[0]);
4282 }
4283 if (scales.length >= 2) {
4284 mTransitionAnimationScale = fixScale(scales[1]);
4285 }
4286 }
Romain Guy06882f82009-06-10 13:36:04 -07004287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 // Persist setting
4289 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4290 }
Romain Guy06882f82009-06-10 13:36:04 -07004291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 public float getAnimationScale(int which) {
4293 switch (which) {
4294 case 0: return mWindowAnimationScale;
4295 case 1: return mTransitionAnimationScale;
4296 }
4297 return 0;
4298 }
Romain Guy06882f82009-06-10 13:36:04 -07004299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 public float[] getAnimationScales() {
4301 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4302 }
Romain Guy06882f82009-06-10 13:36:04 -07004303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 public int getSwitchState(int sw) {
4305 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4306 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004307 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004309 return mInputManager.getSwitchState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 }
Romain Guy06882f82009-06-10 13:36:04 -07004311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 public int getSwitchStateForDevice(int devid, int sw) {
4313 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4314 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004315 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004317 return mInputManager.getSwitchState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
Romain Guy06882f82009-06-10 13:36:04 -07004319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 public int getScancodeState(int sw) {
4321 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4322 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004323 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004325 return mInputManager.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 }
Romain Guy06882f82009-06-10 13:36:04 -07004327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 public int getScancodeStateForDevice(int devid, int sw) {
4329 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4330 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004331 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004333 return mInputManager.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 }
Romain Guy06882f82009-06-10 13:36:04 -07004335
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004336 public int getTrackballScancodeState(int sw) {
4337 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4338 "getTrackballScancodeState()")) {
4339 throw new SecurityException("Requires READ_INPUT_STATE permission");
4340 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004341 return mInputManager.getTrackballScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004342 }
4343
4344 public int getDPadScancodeState(int sw) {
4345 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4346 "getDPadScancodeState()")) {
4347 throw new SecurityException("Requires READ_INPUT_STATE permission");
4348 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004349 return mInputManager.getDPadScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004350 }
4351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 public int getKeycodeState(int sw) {
4353 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4354 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004355 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004357 return mInputManager.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 }
Romain Guy06882f82009-06-10 13:36:04 -07004359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 public int getKeycodeStateForDevice(int devid, int sw) {
4361 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4362 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004363 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004365 return mInputManager.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 }
Romain Guy06882f82009-06-10 13:36:04 -07004367
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004368 public int getTrackballKeycodeState(int sw) {
4369 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4370 "getTrackballKeycodeState()")) {
4371 throw new SecurityException("Requires READ_INPUT_STATE permission");
4372 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004373 return mInputManager.getTrackballKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004374 }
4375
4376 public int getDPadKeycodeState(int sw) {
4377 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4378 "getDPadKeycodeState()")) {
4379 throw new SecurityException("Requires READ_INPUT_STATE permission");
4380 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004381 return mInputManager.getDPadKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004382 }
4383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004385 return mInputManager.hasKeys(keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 }
Romain Guy06882f82009-06-10 13:36:04 -07004387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004388 public void enableScreenAfterBoot() {
4389 synchronized(mWindowMap) {
4390 if (mSystemBooted) {
4391 return;
4392 }
4393 mSystemBooted = true;
4394 }
Romain Guy06882f82009-06-10 13:36:04 -07004395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 performEnableScreen();
4397 }
Romain Guy06882f82009-06-10 13:36:04 -07004398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004399 public void enableScreenIfNeededLocked() {
4400 if (mDisplayEnabled) {
4401 return;
4402 }
4403 if (!mSystemBooted) {
4404 return;
4405 }
4406 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4407 }
Romain Guy06882f82009-06-10 13:36:04 -07004408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 public void performEnableScreen() {
4410 synchronized(mWindowMap) {
4411 if (mDisplayEnabled) {
4412 return;
4413 }
4414 if (!mSystemBooted) {
4415 return;
4416 }
Romain Guy06882f82009-06-10 13:36:04 -07004417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 // Don't enable the screen until all existing windows
4419 // have been drawn.
4420 final int N = mWindows.size();
4421 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004422 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004423 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 return;
4425 }
4426 }
Romain Guy06882f82009-06-10 13:36:04 -07004427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 mDisplayEnabled = true;
4429 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004430 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004431 StringWriter sw = new StringWriter();
4432 PrintWriter pw = new PrintWriter(sw);
4433 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004434 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 }
4436 try {
4437 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4438 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004439 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 Parcel data = Parcel.obtain();
4441 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4442 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4443 data, null, 0);
4444 data.recycle();
4445 }
4446 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 }
4449 }
Romain Guy06882f82009-06-10 13:36:04 -07004450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004454 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4455 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
Romain Guy06882f82009-06-10 13:36:04 -07004457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 public void setInTouchMode(boolean mode) {
4459 synchronized(mWindowMap) {
4460 mInTouchMode = mode;
4461 }
4462 }
4463
Romain Guy06882f82009-06-10 13:36:04 -07004464 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004465 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004467 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004468 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
4470
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004471 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
Romain Guy06882f82009-06-10 13:36:04 -07004473
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004474 public void setRotationUnchecked(int rotation,
4475 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004476 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 long origId = Binder.clearCallingIdentity();
4480 boolean changed;
4481 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004482 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 }
Romain Guy06882f82009-06-10 13:36:04 -07004484
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004485 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 sendNewConfiguration();
4487 }
Romain Guy06882f82009-06-10 13:36:04 -07004488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 Binder.restoreCallingIdentity(origId);
4490 }
Romain Guy06882f82009-06-10 13:36:04 -07004491
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004492 /**
4493 * Apply a new rotation to the screen, respecting the requests of
4494 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4495 * re-evaluate the desired rotation.
4496 *
4497 * Returns null if the rotation has been changed. In this case YOU
4498 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4499 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004500 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 boolean changed;
4502 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4503 rotation = mRequestedRotation;
4504 } else {
4505 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004506 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004508 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004509 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004511 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004515 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 "Rotation changed to " + rotation
4517 + " from " + mRotation
4518 + " (forceApp=" + mForcedAppOrientation
4519 + ", req=" + mRequestedRotation + ")");
4520 mRotation = rotation;
4521 mWindowsFreezingScreen = true;
4522 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4523 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4524 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004525 mWaitingForConfig = true;
4526 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004528 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004529 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004531 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 }
4533 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004534 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 if (w.mSurface != null) {
4536 w.mOrientationChanging = true;
4537 }
4538 }
4539 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4540 try {
4541 mRotationWatchers.get(i).onRotationChanged(rotation);
4542 } catch (RemoteException e) {
4543 }
4544 }
4545 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 return changed;
4548 }
Romain Guy06882f82009-06-10 13:36:04 -07004549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 public int getRotation() {
4551 return mRotation;
4552 }
4553
4554 public int watchRotation(IRotationWatcher watcher) {
4555 final IBinder watcherBinder = watcher.asBinder();
4556 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4557 public void binderDied() {
4558 synchronized (mWindowMap) {
4559 for (int i=0; i<mRotationWatchers.size(); i++) {
4560 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004561 IRotationWatcher removed = mRotationWatchers.remove(i);
4562 if (removed != null) {
4563 removed.asBinder().unlinkToDeath(this, 0);
4564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 i--;
4566 }
4567 }
4568 }
4569 }
4570 };
Romain Guy06882f82009-06-10 13:36:04 -07004571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004572 synchronized (mWindowMap) {
4573 try {
4574 watcher.asBinder().linkToDeath(dr, 0);
4575 mRotationWatchers.add(watcher);
4576 } catch (RemoteException e) {
4577 // Client died, no cleanup needed.
4578 }
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 return mRotation;
4581 }
4582 }
4583
4584 /**
4585 * Starts the view server on the specified port.
4586 *
4587 * @param port The port to listener to.
4588 *
4589 * @return True if the server was successfully started, false otherwise.
4590 *
4591 * @see com.android.server.ViewServer
4592 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4593 */
4594 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004595 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596 return false;
4597 }
4598
4599 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4600 return false;
4601 }
4602
4603 if (port < 1024) {
4604 return false;
4605 }
4606
4607 if (mViewServer != null) {
4608 if (!mViewServer.isRunning()) {
4609 try {
4610 return mViewServer.start();
4611 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004612 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 }
4614 }
4615 return false;
4616 }
4617
4618 try {
4619 mViewServer = new ViewServer(this, port);
4620 return mViewServer.start();
4621 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004622 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 }
4624 return false;
4625 }
4626
Romain Guy06882f82009-06-10 13:36:04 -07004627 private boolean isSystemSecure() {
4628 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4629 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4630 }
4631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632 /**
4633 * Stops the view server if it exists.
4634 *
4635 * @return True if the server stopped, false if it wasn't started or
4636 * couldn't be stopped.
4637 *
4638 * @see com.android.server.ViewServer
4639 */
4640 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004641 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 return false;
4643 }
4644
4645 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4646 return false;
4647 }
4648
4649 if (mViewServer != null) {
4650 return mViewServer.stop();
4651 }
4652 return false;
4653 }
4654
4655 /**
4656 * Indicates whether the view server is running.
4657 *
4658 * @return True if the server is running, false otherwise.
4659 *
4660 * @see com.android.server.ViewServer
4661 */
4662 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004663 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 return false;
4665 }
4666
4667 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4668 return false;
4669 }
4670
4671 return mViewServer != null && mViewServer.isRunning();
4672 }
4673
4674 /**
4675 * Lists all availble windows in the system. The listing is written in the
4676 * specified Socket's output stream with the following syntax:
4677 * windowHashCodeInHexadecimal windowName
4678 * Each line of the ouput represents a different window.
4679 *
4680 * @param client The remote client to send the listing to.
4681 * @return False if an error occured, true otherwise.
4682 */
4683 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004684 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 return false;
4686 }
4687
4688 boolean result = true;
4689
Jeff Browne33348b2010-07-15 23:54:05 -07004690 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004691 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004692 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004693 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004694 }
4695
4696 BufferedWriter out = null;
4697
4698 // Any uncaught exception will crash the system process
4699 try {
4700 OutputStream clientStream = client.getOutputStream();
4701 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4702
4703 final int count = windows.length;
4704 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004705 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 out.write(Integer.toHexString(System.identityHashCode(w)));
4707 out.write(' ');
4708 out.append(w.mAttrs.getTitle());
4709 out.write('\n');
4710 }
4711
4712 out.write("DONE.\n");
4713 out.flush();
4714 } catch (Exception e) {
4715 result = false;
4716 } finally {
4717 if (out != null) {
4718 try {
4719 out.close();
4720 } catch (IOException e) {
4721 result = false;
4722 }
4723 }
4724 }
4725
4726 return result;
4727 }
4728
4729 /**
4730 * Sends a command to a target window. The result of the command, if any, will be
4731 * written in the output stream of the specified socket.
4732 *
4733 * The parameters must follow this syntax:
4734 * windowHashcode extra
4735 *
4736 * Where XX is the length in characeters of the windowTitle.
4737 *
4738 * The first parameter is the target window. The window with the specified hashcode
4739 * will be the target. If no target can be found, nothing happens. The extra parameters
4740 * will be delivered to the target window and as parameters to the command itself.
4741 *
4742 * @param client The remote client to sent the result, if any, to.
4743 * @param command The command to execute.
4744 * @param parameters The command parameters.
4745 *
4746 * @return True if the command was successfully delivered, false otherwise. This does
4747 * not indicate whether the command itself was successful.
4748 */
4749 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004750 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004751 return false;
4752 }
4753
4754 boolean success = true;
4755 Parcel data = null;
4756 Parcel reply = null;
4757
4758 // Any uncaught exception will crash the system process
4759 try {
4760 // Find the hashcode of the window
4761 int index = parameters.indexOf(' ');
4762 if (index == -1) {
4763 index = parameters.length();
4764 }
4765 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004766 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767
4768 // Extract the command's parameter after the window description
4769 if (index < parameters.length()) {
4770 parameters = parameters.substring(index + 1);
4771 } else {
4772 parameters = "";
4773 }
4774
4775 final WindowManagerService.WindowState window = findWindow(hashCode);
4776 if (window == null) {
4777 return false;
4778 }
4779
4780 data = Parcel.obtain();
4781 data.writeInterfaceToken("android.view.IWindow");
4782 data.writeString(command);
4783 data.writeString(parameters);
4784 data.writeInt(1);
4785 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4786
4787 reply = Parcel.obtain();
4788
4789 final IBinder binder = window.mClient.asBinder();
4790 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4791 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4792
4793 reply.readException();
4794
4795 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004796 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 success = false;
4798 } finally {
4799 if (data != null) {
4800 data.recycle();
4801 }
4802 if (reply != null) {
4803 reply.recycle();
4804 }
4805 }
4806
4807 return success;
4808 }
4809
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004810 public void addWindowChangeListener(WindowChangeListener listener) {
4811 synchronized(mWindowMap) {
4812 mWindowChangeListeners.add(listener);
4813 }
4814 }
4815
4816 public void removeWindowChangeListener(WindowChangeListener listener) {
4817 synchronized(mWindowMap) {
4818 mWindowChangeListeners.remove(listener);
4819 }
4820 }
4821
4822 private void notifyWindowsChanged() {
4823 WindowChangeListener[] windowChangeListeners;
4824 synchronized(mWindowMap) {
4825 if(mWindowChangeListeners.isEmpty()) {
4826 return;
4827 }
4828 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4829 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4830 }
4831 int N = windowChangeListeners.length;
4832 for(int i = 0; i < N; i++) {
4833 windowChangeListeners[i].windowsChanged();
4834 }
4835 }
4836
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004837 private void notifyFocusChanged() {
4838 WindowChangeListener[] windowChangeListeners;
4839 synchronized(mWindowMap) {
4840 if(mWindowChangeListeners.isEmpty()) {
4841 return;
4842 }
4843 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4844 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4845 }
4846 int N = windowChangeListeners.length;
4847 for(int i = 0; i < N; i++) {
4848 windowChangeListeners[i].focusChanged();
4849 }
4850 }
4851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 private WindowState findWindow(int hashCode) {
4853 if (hashCode == -1) {
4854 return getFocusedWindow();
4855 }
4856
4857 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004858 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859 final int count = windows.size();
4860
4861 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004862 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 if (System.identityHashCode(w) == hashCode) {
4864 return w;
4865 }
4866 }
4867 }
4868
4869 return null;
4870 }
4871
4872 /*
4873 * Instruct the Activity Manager to fetch the current configuration and broadcast
4874 * that to config-changed listeners if appropriate.
4875 */
4876 void sendNewConfiguration() {
4877 try {
4878 mActivityManager.updateConfiguration(null);
4879 } catch (RemoteException e) {
4880 }
4881 }
Romain Guy06882f82009-06-10 13:36:04 -07004882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 public Configuration computeNewConfiguration() {
4884 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004885 return computeNewConfigurationLocked();
4886 }
4887 }
Romain Guy06882f82009-06-10 13:36:04 -07004888
Dianne Hackbornc485a602009-03-24 22:39:49 -07004889 Configuration computeNewConfigurationLocked() {
4890 Configuration config = new Configuration();
4891 if (!computeNewConfigurationLocked(config)) {
4892 return null;
4893 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004894 return config;
4895 }
Romain Guy06882f82009-06-10 13:36:04 -07004896
Dianne Hackbornc485a602009-03-24 22:39:49 -07004897 boolean computeNewConfigurationLocked(Configuration config) {
4898 if (mDisplay == null) {
4899 return false;
4900 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004901
4902 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004903
4904 // Use the effective "visual" dimensions based on current rotation
4905 final boolean rotated = (mRotation == Surface.ROTATION_90
4906 || mRotation == Surface.ROTATION_270);
4907 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4908 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4909
Dianne Hackbornc485a602009-03-24 22:39:49 -07004910 int orientation = Configuration.ORIENTATION_SQUARE;
4911 if (dw < dh) {
4912 orientation = Configuration.ORIENTATION_PORTRAIT;
4913 } else if (dw > dh) {
4914 orientation = Configuration.ORIENTATION_LANDSCAPE;
4915 }
4916 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004917
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004918 DisplayMetrics dm = new DisplayMetrics();
4919 mDisplay.getMetrics(dm);
4920 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4921
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004922 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004923 // Note we only do this once because at this point we don't
4924 // expect the screen to change in this way at runtime, and want
4925 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004926 int longSize = dw;
4927 int shortSize = dh;
4928 if (longSize < shortSize) {
4929 int tmp = longSize;
4930 longSize = shortSize;
4931 shortSize = tmp;
4932 }
4933 longSize = (int)(longSize/dm.density);
4934 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004935
Dianne Hackborn723738c2009-06-25 19:48:04 -07004936 // These semi-magic numbers define our compatibility modes for
4937 // applications with different screens. Don't change unless you
4938 // make sure to test lots and lots of apps!
4939 if (longSize < 470) {
4940 // This is shorter than an HVGA normal density screen (which
4941 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004942 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4943 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004944 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004945 // What size is this screen screen?
4946 if (longSize >= 800 && shortSize >= 600) {
4947 // SVGA or larger screens at medium density are the point
4948 // at which we consider it to be an extra large screen.
4949 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4950 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004951 // VGA or larger screens at medium density are the point
4952 // at which we consider it to be a large screen.
4953 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4954 } else {
4955 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004956
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004957 // If this screen is wider than normal HVGA, or taller
4958 // than FWVGA, then for old apps we want to run in size
4959 // compatibility mode.
4960 if (shortSize > 321 || longSize > 570) {
4961 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4962 }
4963 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004964
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004965 // Is this a long screen?
4966 if (((longSize*3)/5) >= (shortSize-1)) {
4967 // Anything wider than WVGA (5:3) is considering to be long.
4968 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4969 } else {
4970 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4971 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004972 }
4973 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004974 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004975
Dianne Hackbornc485a602009-03-24 22:39:49 -07004976 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4977 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4978 mPolicy.adjustConfigurationLw(config);
4979 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982 // -------------------------------------------------------------
4983 // Input Events and Focus Management
4984 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07004985
Jeff Brown349703e2010-06-22 01:27:15 -07004986 InputMonitor mInputMonitor = new InputMonitor();
4987
4988 /* Tracks the progress of input dispatch and ensures that input dispatch state
4989 * is kept in sync with changes in window focus, visibility, registration, and
4990 * other relevant Window Manager state transitions. */
4991 final class InputMonitor {
4992 // Current window with input focus for keys and other non-touch events. May be null.
4993 private WindowState mInputFocus;
4994
4995 // When true, prevents input dispatch from proceeding until set to false again.
4996 private boolean mInputDispatchFrozen;
4997
4998 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
4999 private boolean mInputDispatchEnabled = true;
5000
5001 // Temporary list of windows information to provide to the input dispatcher.
5002 private InputWindowList mTempInputWindows = new InputWindowList();
5003
5004 // Temporary input application object to provide to the input dispatcher.
5005 private InputApplication mTempInputApplication = new InputApplication();
5006
5007 /* Notifies the window manager about a broken input channel.
5008 *
5009 * Called by the InputManager.
5010 */
5011 public void notifyInputChannelBroken(InputChannel inputChannel) {
5012 synchronized (mWindowMap) {
5013 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5014 if (windowState == null) {
5015 return; // irrelevant
5016 }
5017
5018 Slog.i(TAG, "WINDOW DIED " + windowState);
5019 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005020 }
5021 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005022
Jeff Brown349703e2010-06-22 01:27:15 -07005023 /* Notifies the window manager about an input channel that is not responding.
5024 * The method can either cause dispatching to be aborted by returning -2 or
5025 * return a new timeout in nanoseconds.
5026 *
5027 * Called by the InputManager.
5028 */
5029 public long notifyInputChannelANR(InputChannel inputChannel) {
5030 AppWindowToken token;
5031 synchronized (mWindowMap) {
5032 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5033 if (windowState == null) {
5034 return -2; // irrelevant, abort dispatching (-2)
5035 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005036
Jeff Brown349703e2010-06-22 01:27:15 -07005037 Slog.i(TAG, "Input event dispatching timed out sending to "
5038 + windowState.mAttrs.getTitle());
5039 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005040 }
5041
Jeff Brown349703e2010-06-22 01:27:15 -07005042 return notifyANRInternal(token);
5043 }
5044
5045 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5046 * by successfully delivering the event that originally timed out.
5047 *
5048 * Called by the InputManager.
5049 */
5050 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5051 // Nothing to do just now.
5052 // Just wait for the user to dismiss the ANR dialog.
5053 }
5054
5055 /* Notifies the window manager about an application that is not responding
5056 * in general rather than with respect to a particular input channel.
5057 * The method can either cause dispatching to be aborted by returning -2 or
5058 * return a new timeout in nanoseconds.
5059 *
5060 * Called by the InputManager.
5061 */
5062 public long notifyANR(Object token) {
5063 AppWindowToken appWindowToken = (AppWindowToken) token;
5064
5065 Slog.i(TAG, "Input event dispatching timed out sending to application "
5066 + appWindowToken.stringName);
5067 return notifyANRInternal(appWindowToken);
5068 }
5069
5070 private long notifyANRInternal(AppWindowToken token) {
5071 if (token != null && token.appToken != null) {
5072 try {
5073 // Notify the activity manager about the timeout and let it decide whether
5074 // to abort dispatching or keep waiting.
5075 boolean abort = token.appToken.keyDispatchingTimedOut();
5076 if (! abort) {
5077 // The activity manager declined to abort dispatching.
5078 // Wait a bit longer and timeout again later.
5079 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005080 }
Jeff Brown349703e2010-06-22 01:27:15 -07005081 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005082 }
5083 }
Jeff Brown349703e2010-06-22 01:27:15 -07005084 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005085 }
5086
Jeff Brown349703e2010-06-22 01:27:15 -07005087 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5088 synchronized (mWindowMap) {
5089 return getWindowStateForInputChannelLocked(inputChannel);
5090 }
5091 }
5092
5093 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5094 int windowCount = mWindows.size();
5095 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005096 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005097 if (windowState.mInputChannel == inputChannel) {
5098 return windowState;
5099 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005100 }
5101
Jeff Brown349703e2010-06-22 01:27:15 -07005102 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005103 }
5104
Jeff Brown349703e2010-06-22 01:27:15 -07005105 /* Updates the cached window information provided to the input dispatcher. */
5106 public void updateInputWindowsLw() {
5107 // Populate the input window list with information about all of the windows that
5108 // could potentially receive input.
5109 // As an optimization, we could try to prune the list of windows but this turns
5110 // out to be difficult because only the native code knows for sure which window
5111 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005112 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005113 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005114 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005115 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005116 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005117 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005118 continue;
5119 }
5120
Jeff Brown349703e2010-06-22 01:27:15 -07005121 final int flags = child.mAttrs.flags;
5122 final int type = child.mAttrs.type;
5123
5124 final boolean hasFocus = (child == mInputFocus);
5125 final boolean isVisible = child.isVisibleLw();
5126 final boolean hasWallpaper = (child == mWallpaperTarget)
5127 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5128
5129 // Add a window to our list of input windows.
5130 final InputWindow inputWindow = mTempInputWindows.add();
5131 inputWindow.inputChannel = child.mInputChannel;
5132 inputWindow.layoutParamsFlags = flags;
5133 inputWindow.layoutParamsType = type;
5134 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5135 inputWindow.visible = isVisible;
5136 inputWindow.hasFocus = hasFocus;
5137 inputWindow.hasWallpaper = hasWallpaper;
5138 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5139 inputWindow.ownerPid = child.mSession.mPid;
5140 inputWindow.ownerUid = child.mSession.mUid;
5141
5142 final Rect frame = child.mFrame;
5143 inputWindow.frameLeft = frame.left;
5144 inputWindow.frameTop = frame.top;
5145
5146 switch (child.mTouchableInsets) {
5147 default:
5148 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5149 inputWindow.touchableAreaLeft = frame.left;
5150 inputWindow.touchableAreaTop = frame.top;
5151 inputWindow.touchableAreaRight = frame.right;
5152 inputWindow.touchableAreaBottom = frame.bottom;
5153 break;
5154
5155 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5156 Rect inset = child.mGivenContentInsets;
5157 inputWindow.touchableAreaLeft = frame.left + inset.left;
5158 inputWindow.touchableAreaTop = frame.top + inset.top;
5159 inputWindow.touchableAreaRight = frame.right - inset.right;
5160 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5161 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005162 }
Jeff Brown349703e2010-06-22 01:27:15 -07005163
5164 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5165 Rect inset = child.mGivenVisibleInsets;
5166 inputWindow.touchableAreaLeft = frame.left + inset.left;
5167 inputWindow.touchableAreaTop = frame.top + inset.top;
5168 inputWindow.touchableAreaRight = frame.right - inset.right;
5169 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005170 break;
5171 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005172 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005173 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005174
Jeff Brown349703e2010-06-22 01:27:15 -07005175 // Send windows to native code.
5176 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005177
Jeff Brown349703e2010-06-22 01:27:15 -07005178 // Clear the list in preparation for the next round.
5179 // Also avoids keeping InputChannel objects referenced unnecessarily.
5180 mTempInputWindows.clear();
5181 }
5182
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005183 /* Provides feedback for a virtual key down. */
5184 public void virtualKeyDownFeedback() {
5185 synchronized (mWindowMap) {
5186 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5187 }
5188 }
5189
Jeff Brown349703e2010-06-22 01:27:15 -07005190 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5191 * This essentially starts a .5 second timeout for the application to process
5192 * subsequent input events while waiting for the app switch to occur. If it takes longer
5193 * than this, the pending events will be dropped.
5194 */
5195 public void notifyAppSwitchComing() {
5196 // TODO Not implemented yet. Should go in the native side.
5197 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005198
5199 /* Notifies that the lid switch changed state. */
5200 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5201 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5202 }
5203
Jeff Brown349703e2010-06-22 01:27:15 -07005204 /* Provides an opportunity for the window manager policy to intercept early key
5205 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005206 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5207 int policyFlags, boolean isScreenOn) {
5208 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5209 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005210 }
5211
5212 /* Provides an opportunity for the window manager policy to process a key before
5213 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005214 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5215 int action, int flags, int keyCode, int metaState, int repeatCount,
5216 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005217 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005218 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5219 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005220 }
5221
5222 /* Called when the current input focus changes.
5223 * Layer assignment is assumed to be complete by the time this is called.
5224 */
5225 public void setInputFocusLw(WindowState newWindow) {
5226 if (DEBUG_INPUT) {
5227 Slog.d(TAG, "Input focus has changed to " + newWindow);
5228 }
5229
5230 if (newWindow != mInputFocus) {
5231 if (newWindow != null && newWindow.canReceiveKeys()) {
5232 // If the new input focus is an error window or appears above the current
5233 // input focus, preempt any pending synchronous dispatch so that we can
5234 // start delivering events to the new input focus as soon as possible.
5235 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5236 if (DEBUG_INPUT) {
5237 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac02010-04-22 18:58:52 -07005238 }
Jeff Brown349703e2010-06-22 01:27:15 -07005239 preemptInputDispatchLw();
5240 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5241 if (DEBUG_INPUT) {
5242 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5243 + "old win layer=" + mInputFocus.mLayer
5244 + ", new win layer=" + newWindow.mLayer);
5245 }
5246 preemptInputDispatchLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005247 }
Jeff Brown349703e2010-06-22 01:27:15 -07005248
5249 // Displaying a window implicitly causes dispatching to be unpaused.
5250 // This is to protect against bugs if someone pauses dispatching but
5251 // forgets to resume.
5252 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005253 }
Jeff Brown349703e2010-06-22 01:27:15 -07005254
5255 mInputFocus = newWindow;
5256 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005257 }
5258 }
5259
Jeff Brown349703e2010-06-22 01:27:15 -07005260 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5261 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5262 * can begin.
5263 */
5264 private void preemptInputDispatchLw() {
5265 mInputManager.preemptInputDispatch();
5266 }
5267
5268 public void setFocusedAppLw(AppWindowToken newApp) {
5269 // Focused app has changed.
5270 if (newApp == null) {
5271 mInputManager.setFocusedApplication(null);
5272 } else {
5273 mTempInputApplication.name = newApp.toString();
5274 mTempInputApplication.dispatchingTimeoutNanos =
5275 newApp.inputDispatchingTimeoutNanos;
5276 mTempInputApplication.token = newApp;
5277
5278 mInputManager.setFocusedApplication(mTempInputApplication);
5279 }
5280 }
5281
Jeff Brown349703e2010-06-22 01:27:15 -07005282 public void pauseDispatchingLw(WindowToken window) {
5283 if (! window.paused) {
5284 if (DEBUG_INPUT) {
5285 Slog.v(TAG, "Pausing WindowToken " + window);
5286 }
5287
5288 window.paused = true;
5289 updateInputWindowsLw();
5290 }
5291 }
5292
5293 public void resumeDispatchingLw(WindowToken window) {
5294 if (window.paused) {
5295 if (DEBUG_INPUT) {
5296 Slog.v(TAG, "Resuming WindowToken " + window);
5297 }
5298
5299 window.paused = false;
5300 updateInputWindowsLw();
5301 }
5302 }
5303
5304 public void freezeInputDispatchingLw() {
5305 if (! mInputDispatchFrozen) {
5306 if (DEBUG_INPUT) {
5307 Slog.v(TAG, "Freezing input dispatching");
5308 }
5309
5310 mInputDispatchFrozen = true;
5311 updateInputDispatchModeLw();
5312 }
5313 }
5314
5315 public void thawInputDispatchingLw() {
5316 if (mInputDispatchFrozen) {
5317 if (DEBUG_INPUT) {
5318 Slog.v(TAG, "Thawing input dispatching");
5319 }
5320
5321 mInputDispatchFrozen = false;
5322 updateInputDispatchModeLw();
5323 }
5324 }
5325
5326 public void setEventDispatchingLw(boolean enabled) {
5327 if (mInputDispatchEnabled != enabled) {
5328 if (DEBUG_INPUT) {
5329 Slog.v(TAG, "Setting event dispatching to " + enabled);
5330 }
5331
5332 mInputDispatchEnabled = enabled;
5333 updateInputDispatchModeLw();
5334 }
5335 }
5336
5337 private void updateInputDispatchModeLw() {
5338 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5339 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005340 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005342 public void pauseKeyDispatching(IBinder _token) {
5343 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5344 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005345 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005346 }
5347
5348 synchronized (mWindowMap) {
5349 WindowToken token = mTokenMap.get(_token);
5350 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005351 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005352 }
5353 }
5354 }
5355
5356 public void resumeKeyDispatching(IBinder _token) {
5357 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5358 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005359 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005360 }
5361
5362 synchronized (mWindowMap) {
5363 WindowToken token = mTokenMap.get(_token);
5364 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005365 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005366 }
5367 }
5368 }
5369
5370 public void setEventDispatching(boolean enabled) {
5371 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5372 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005373 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374 }
5375
5376 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005377 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005378 }
5379 }
Romain Guy06882f82009-06-10 13:36:04 -07005380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005381 /**
5382 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005383 *
5384 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 * {@link SystemClock#uptimeMillis()} as the timebase.)
5386 * @param sync If true, wait for the event to be completed before returning to the caller.
5387 * @return Returns true if event was dispatched, false if it was dropped for any reason
5388 */
5389 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5390 long downTime = ev.getDownTime();
5391 long eventTime = ev.getEventTime();
5392
5393 int action = ev.getAction();
5394 int code = ev.getKeyCode();
5395 int repeatCount = ev.getRepeatCount();
5396 int metaState = ev.getMetaState();
5397 int deviceId = ev.getDeviceId();
5398 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005399 int source = ev.getSource();
5400
5401 if (source == InputDevice.SOURCE_UNKNOWN) {
5402 source = InputDevice.SOURCE_KEYBOARD;
5403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005404
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,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005409 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
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();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005414
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005415 final int result = mInputManager.injectKeyEvent(newEvent,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005416 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005417
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005418 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005419 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005420 }
5421
5422 /**
5423 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005424 *
5425 * @param ev A motion event describing the pointer (touch) action. (As noted in
5426 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427 * {@link SystemClock#uptimeMillis()} as the timebase.)
5428 * @param sync If true, wait for the event to be completed before returning to the caller.
5429 * @return Returns true if event was dispatched, false if it was dropped for any reason
5430 */
5431 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005432 final int pid = Binder.getCallingPid();
5433 final int uid = Binder.getCallingUid();
5434 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005435
Jeff Brownc5ed5912010-07-14 18:48:53 -07005436 MotionEvent newEvent = MotionEvent.obtain(ev);
5437 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5438 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5439 }
5440
5441 final int result = mInputManager.injectMotionEvent(newEvent,
5442 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005443
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005444 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005445 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005446 }
Romain Guy06882f82009-06-10 13:36:04 -07005447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005448 /**
5449 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005450 *
5451 * @param ev A motion event describing the trackball action. (As noted in
5452 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005453 * {@link SystemClock#uptimeMillis()} as the timebase.)
5454 * @param sync If true, wait for the event to be completed before returning to the caller.
5455 * @return Returns true if event was dispatched, false if it was dropped for any reason
5456 */
5457 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005458 final int pid = Binder.getCallingPid();
5459 final int uid = Binder.getCallingUid();
5460 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005461
Jeff Brownc5ed5912010-07-14 18:48:53 -07005462 MotionEvent newEvent = MotionEvent.obtain(ev);
5463 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5464 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5465 }
5466
5467 final int result = mInputManager.injectMotionEvent(newEvent,
5468 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005469
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005470 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005471 return reportInjectionResult(result);
5472 }
5473
5474 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005475 switch (result) {
5476 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5477 Slog.w(TAG, "Input event injection permission denied.");
5478 throw new SecurityException(
5479 "Injecting to another application requires INJECT_EVENTS permission");
5480 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
5481 Slog.v(TAG, "Input event injection succeeded.");
5482 return true;
5483 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5484 Slog.w(TAG, "Input event injection timed out.");
5485 return false;
5486 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5487 default:
5488 Slog.w(TAG, "Input event injection failed.");
5489 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005491 }
Romain Guy06882f82009-06-10 13:36:04 -07005492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005493 private WindowState getFocusedWindow() {
5494 synchronized (mWindowMap) {
5495 return getFocusedWindowLocked();
5496 }
5497 }
5498
5499 private WindowState getFocusedWindowLocked() {
5500 return mCurrentFocus;
5501 }
Romain Guy06882f82009-06-10 13:36:04 -07005502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005503 public boolean detectSafeMode() {
5504 mSafeMode = mPolicy.detectSafeMode();
5505 return mSafeMode;
5506 }
Romain Guy06882f82009-06-10 13:36:04 -07005507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005508 public void systemReady() {
5509 mPolicy.systemReady();
5510 }
Romain Guy06882f82009-06-10 13:36:04 -07005511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005512 // -------------------------------------------------------------
5513 // Client Session State
5514 // -------------------------------------------------------------
5515
5516 private final class Session extends IWindowSession.Stub
5517 implements IBinder.DeathRecipient {
5518 final IInputMethodClient mClient;
5519 final IInputContext mInputContext;
5520 final int mUid;
5521 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005522 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005523 SurfaceSession mSurfaceSession;
5524 int mNumWindow = 0;
5525 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005527 public Session(IInputMethodClient client, IInputContext inputContext) {
5528 mClient = client;
5529 mInputContext = inputContext;
5530 mUid = Binder.getCallingUid();
5531 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005532 StringBuilder sb = new StringBuilder();
5533 sb.append("Session{");
5534 sb.append(Integer.toHexString(System.identityHashCode(this)));
5535 sb.append(" uid ");
5536 sb.append(mUid);
5537 sb.append("}");
5538 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005540 synchronized (mWindowMap) {
5541 if (mInputMethodManager == null && mHaveInputMethods) {
5542 IBinder b = ServiceManager.getService(
5543 Context.INPUT_METHOD_SERVICE);
5544 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5545 }
5546 }
5547 long ident = Binder.clearCallingIdentity();
5548 try {
5549 // Note: it is safe to call in to the input method manager
5550 // here because we are not holding our lock.
5551 if (mInputMethodManager != null) {
5552 mInputMethodManager.addClient(client, inputContext,
5553 mUid, mPid);
5554 } else {
5555 client.setUsingInputMethod(false);
5556 }
5557 client.asBinder().linkToDeath(this, 0);
5558 } catch (RemoteException e) {
5559 // The caller has died, so we can just forget about this.
5560 try {
5561 if (mInputMethodManager != null) {
5562 mInputMethodManager.removeClient(client);
5563 }
5564 } catch (RemoteException ee) {
5565 }
5566 } finally {
5567 Binder.restoreCallingIdentity(ident);
5568 }
5569 }
Romain Guy06882f82009-06-10 13:36:04 -07005570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005571 @Override
5572 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5573 throws RemoteException {
5574 try {
5575 return super.onTransact(code, data, reply, flags);
5576 } catch (RuntimeException e) {
5577 // Log all 'real' exceptions thrown to the caller
5578 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005579 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005580 }
5581 throw e;
5582 }
5583 }
5584
5585 public void binderDied() {
5586 // Note: it is safe to call in to the input method manager
5587 // here because we are not holding our lock.
5588 try {
5589 if (mInputMethodManager != null) {
5590 mInputMethodManager.removeClient(mClient);
5591 }
5592 } catch (RemoteException e) {
5593 }
5594 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005595 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005596 mClientDead = true;
5597 killSessionLocked();
5598 }
5599 }
5600
5601 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07005602 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5603 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5604 outInputChannel);
5605 }
5606
5607 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005608 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07005609 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005610 }
Romain Guy06882f82009-06-10 13:36:04 -07005611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005612 public void remove(IWindow window) {
5613 removeWindow(this, window);
5614 }
Romain Guy06882f82009-06-10 13:36:04 -07005615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5617 int requestedWidth, int requestedHeight, int viewFlags,
5618 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005619 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005620 return relayoutWindow(this, window, attrs,
5621 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005622 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005623 }
Romain Guy06882f82009-06-10 13:36:04 -07005624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005625 public void setTransparentRegion(IWindow window, Region region) {
5626 setTransparentRegionWindow(this, window, region);
5627 }
Romain Guy06882f82009-06-10 13:36:04 -07005628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005629 public void setInsets(IWindow window, int touchableInsets,
5630 Rect contentInsets, Rect visibleInsets) {
5631 setInsetsWindow(this, window, touchableInsets, contentInsets,
5632 visibleInsets);
5633 }
Romain Guy06882f82009-06-10 13:36:04 -07005634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005635 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5636 getWindowDisplayFrame(this, window, outDisplayFrame);
5637 }
Romain Guy06882f82009-06-10 13:36:04 -07005638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005639 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005640 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005641 TAG, "IWindow finishDrawing called for " + window);
5642 finishDrawingWindow(this, window);
5643 }
5644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005645 public void setInTouchMode(boolean mode) {
5646 synchronized(mWindowMap) {
5647 mInTouchMode = mode;
5648 }
5649 }
5650
5651 public boolean getInTouchMode() {
5652 synchronized(mWindowMap) {
5653 return mInTouchMode;
5654 }
5655 }
5656
5657 public boolean performHapticFeedback(IWindow window, int effectId,
5658 boolean always) {
5659 synchronized(mWindowMap) {
5660 long ident = Binder.clearCallingIdentity();
5661 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005662 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005663 windowForClientLocked(this, window, true),
5664 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005665 } finally {
5666 Binder.restoreCallingIdentity(ident);
5667 }
5668 }
5669 }
Romain Guy06882f82009-06-10 13:36:04 -07005670
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005671 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005672 synchronized(mWindowMap) {
5673 long ident = Binder.clearCallingIdentity();
5674 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005675 setWindowWallpaperPositionLocked(
5676 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005677 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005678 } finally {
5679 Binder.restoreCallingIdentity(ident);
5680 }
5681 }
5682 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005683
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005684 public void wallpaperOffsetsComplete(IBinder window) {
5685 WindowManagerService.this.wallpaperOffsetsComplete(window);
5686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005687
Dianne Hackborn75804932009-10-20 20:15:20 -07005688 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5689 int z, Bundle extras, boolean sync) {
5690 synchronized(mWindowMap) {
5691 long ident = Binder.clearCallingIdentity();
5692 try {
5693 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005694 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005695 action, x, y, z, extras, sync);
5696 } finally {
5697 Binder.restoreCallingIdentity(ident);
5698 }
5699 }
5700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005701
Dianne Hackborn75804932009-10-20 20:15:20 -07005702 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5703 WindowManagerService.this.wallpaperCommandComplete(window, result);
5704 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005706 void windowAddedLocked() {
5707 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005708 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005709 TAG, "First window added to " + this + ", creating SurfaceSession");
5710 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005711 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005712 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005713 mSessions.add(this);
5714 }
5715 mNumWindow++;
5716 }
5717
5718 void windowRemovedLocked() {
5719 mNumWindow--;
5720 killSessionLocked();
5721 }
Romain Guy06882f82009-06-10 13:36:04 -07005722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005723 void killSessionLocked() {
5724 if (mNumWindow <= 0 && mClientDead) {
5725 mSessions.remove(this);
5726 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005727 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005728 TAG, "Last window removed from " + this
5729 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005730 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005731 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005732 try {
5733 mSurfaceSession.kill();
5734 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005735 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005736 + mSurfaceSession + " in session " + this
5737 + ": " + e.toString());
5738 }
5739 mSurfaceSession = null;
5740 }
5741 }
5742 }
Romain Guy06882f82009-06-10 13:36:04 -07005743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005744 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005745 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5746 pw.print(" mClientDead="); pw.print(mClientDead);
5747 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005748 }
5749
5750 @Override
5751 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005752 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005753 }
5754 }
5755
5756 // -------------------------------------------------------------
5757 // Client Window State
5758 // -------------------------------------------------------------
5759
5760 private final class WindowState implements WindowManagerPolicy.WindowState {
5761 final Session mSession;
5762 final IWindow mClient;
5763 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005764 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005765 AppWindowToken mAppToken;
5766 AppWindowToken mTargetAppToken;
5767 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5768 final DeathRecipient mDeathRecipient;
5769 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005770 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005771 final int mBaseLayer;
5772 final int mSubLayer;
5773 final boolean mLayoutAttached;
5774 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005775 final boolean mIsWallpaper;
5776 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005777 int mViewVisibility;
5778 boolean mPolicyVisibility = true;
5779 boolean mPolicyVisibilityAfterAnim = true;
5780 boolean mAppFreezing;
5781 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005782 boolean mReportDestroySurface;
5783 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005784 boolean mAttachedHidden; // is our parent window hidden?
5785 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005786 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 int mRequestedWidth;
5788 int mRequestedHeight;
5789 int mLastRequestedWidth;
5790 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 int mLayer;
5792 int mAnimLayer;
5793 int mLastLayer;
5794 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005795 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005796 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005797
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005798 int mLayoutSeq = -1;
5799
5800 Configuration mConfiguration = null;
5801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005802 // Actual frame shown on-screen (may be modified by animation)
5803 final Rect mShownFrame = new Rect();
5804 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005806 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005807 * Set when we have changed the size of the surface, to know that
5808 * we must tell them application to resize (and thus redraw itself).
5809 */
5810 boolean mSurfaceResized;
5811
5812 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005813 * Insets that determine the actually visible area
5814 */
5815 final Rect mVisibleInsets = new Rect();
5816 final Rect mLastVisibleInsets = new Rect();
5817 boolean mVisibleInsetsChanged;
5818
5819 /**
5820 * Insets that are covered by system windows
5821 */
5822 final Rect mContentInsets = new Rect();
5823 final Rect mLastContentInsets = new Rect();
5824 boolean mContentInsetsChanged;
5825
5826 /**
5827 * Set to true if we are waiting for this window to receive its
5828 * given internal insets before laying out other windows based on it.
5829 */
5830 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005832 /**
5833 * These are the content insets that were given during layout for
5834 * this window, to be applied to windows behind it.
5835 */
5836 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 /**
5839 * These are the visible insets that were given during layout for
5840 * this window, to be applied to windows behind it.
5841 */
5842 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 /**
5845 * Flag indicating whether the touchable region should be adjusted by
5846 * the visible insets; if false the area outside the visible insets is
5847 * NOT touchable, so we must use those to adjust the frame during hit
5848 * tests.
5849 */
5850 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005852 // Current transformation being applied.
5853 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5854 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5855 float mHScale=1, mVScale=1;
5856 float mLastHScale=1, mLastVScale=1;
5857 final Matrix mTmpMatrix = new Matrix();
5858
5859 // "Real" frame that the application sees.
5860 final Rect mFrame = new Rect();
5861 final Rect mLastFrame = new Rect();
5862
5863 final Rect mContainingFrame = new Rect();
5864 final Rect mDisplayFrame = new Rect();
5865 final Rect mContentFrame = new Rect();
5866 final Rect mVisibleFrame = new Rect();
5867
5868 float mShownAlpha = 1;
5869 float mAlpha = 1;
5870 float mLastAlpha = 1;
5871
5872 // Set to true if, when the window gets displayed, it should perform
5873 // an enter animation.
5874 boolean mEnterAnimationPending;
5875
5876 // Currently running animation.
5877 boolean mAnimating;
5878 boolean mLocalAnimating;
5879 Animation mAnimation;
5880 boolean mAnimationIsEntrance;
5881 boolean mHasTransformation;
5882 boolean mHasLocalTransformation;
5883 final Transformation mTransformation = new Transformation();
5884
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005885 // If a window showing a wallpaper: the requested offset for the
5886 // wallpaper; if a wallpaper window: the currently applied offset.
5887 float mWallpaperX = -1;
5888 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005889
5890 // If a window showing a wallpaper: what fraction of the offset
5891 // range corresponds to a full virtual screen.
5892 float mWallpaperXStep = -1;
5893 float mWallpaperYStep = -1;
5894
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005895 // Wallpaper windows: pixels offset based on above variables.
5896 int mXOffset;
5897 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005899 // This is set after IWindowSession.relayout() has been called at
5900 // least once for the window. It allows us to detect the situation
5901 // where we don't yet have a surface, but should have one soon, so
5902 // we can give the window focus before waiting for the relayout.
5903 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005905 // This is set after the Surface has been created but before the
5906 // window has been drawn. During this time the surface is hidden.
5907 boolean mDrawPending;
5908
5909 // This is set after the window has finished drawing for the first
5910 // time but before its surface is shown. The surface will be
5911 // displayed when the next layout is run.
5912 boolean mCommitDrawPending;
5913
5914 // This is set during the time after the window's drawing has been
5915 // committed, and before its surface is actually shown. It is used
5916 // to delay showing the surface until all windows in a token are ready
5917 // to be shown.
5918 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005920 // Set when the window has been shown in the screen the first time.
5921 boolean mHasDrawn;
5922
5923 // Currently running an exit animation?
5924 boolean mExiting;
5925
5926 // Currently on the mDestroySurface list?
5927 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005929 // Completely remove from window manager after exit animation?
5930 boolean mRemoveOnExit;
5931
5932 // Set when the orientation is changing and this window has not yet
5933 // been updated for the new orientation.
5934 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005936 // Is this window now (or just being) removed?
5937 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005938
Dianne Hackborn16064f92010-03-25 00:47:24 -07005939 // For debugging, this is the last information given to the surface flinger.
5940 boolean mSurfaceShown;
5941 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
5942 int mSurfaceLayer;
5943 float mSurfaceAlpha;
5944
Jeff Brown46b9ac02010-04-22 18:58:52 -07005945 // Input channel
5946 InputChannel mInputChannel;
5947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005948 WindowState(Session s, IWindow c, WindowToken token,
5949 WindowState attachedWindow, WindowManager.LayoutParams a,
5950 int viewVisibility) {
5951 mSession = s;
5952 mClient = c;
5953 mToken = token;
5954 mAttrs.copyFrom(a);
5955 mViewVisibility = viewVisibility;
5956 DeathRecipient deathRecipient = new DeathRecipient();
5957 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005958 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005959 TAG, "Window " + this + " client=" + c.asBinder()
5960 + " token=" + token + " (" + mAttrs.token + ")");
5961 try {
5962 c.asBinder().linkToDeath(deathRecipient, 0);
5963 } catch (RemoteException e) {
5964 mDeathRecipient = null;
5965 mAttachedWindow = null;
5966 mLayoutAttached = false;
5967 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005968 mIsWallpaper = false;
5969 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005970 mBaseLayer = 0;
5971 mSubLayer = 0;
5972 return;
5973 }
5974 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07005975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005976 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
5977 mAttrs.type <= LAST_SUB_WINDOW)) {
5978 // The multiplier here is to reserve space for multiple
5979 // windows in the same type layer.
5980 mBaseLayer = mPolicy.windowTypeToLayerLw(
5981 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
5982 + TYPE_LAYER_OFFSET;
5983 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
5984 mAttachedWindow = attachedWindow;
5985 mAttachedWindow.mChildWindows.add(this);
5986 mLayoutAttached = mAttrs.type !=
5987 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
5988 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
5989 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005990 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
5991 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005992 } else {
5993 // The multiplier here is to reserve space for multiple
5994 // windows in the same type layer.
5995 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
5996 * TYPE_LAYER_MULTIPLIER
5997 + TYPE_LAYER_OFFSET;
5998 mSubLayer = 0;
5999 mAttachedWindow = null;
6000 mLayoutAttached = false;
6001 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6002 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006003 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6004 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006005 }
6006
6007 WindowState appWin = this;
6008 while (appWin.mAttachedWindow != null) {
6009 appWin = mAttachedWindow;
6010 }
6011 WindowToken appToken = appWin.mToken;
6012 while (appToken.appWindowToken == null) {
6013 WindowToken parent = mTokenMap.get(appToken.token);
6014 if (parent == null || appToken == parent) {
6015 break;
6016 }
6017 appToken = parent;
6018 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006019 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006020 mAppToken = appToken.appWindowToken;
6021
6022 mSurface = null;
6023 mRequestedWidth = 0;
6024 mRequestedHeight = 0;
6025 mLastRequestedWidth = 0;
6026 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006027 mXOffset = 0;
6028 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006029 mLayer = 0;
6030 mAnimLayer = 0;
6031 mLastLayer = 0;
6032 }
6033
6034 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006035 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006036 TAG, "Attaching " + this + " token=" + mToken
6037 + ", list=" + mToken.windows);
6038 mSession.windowAddedLocked();
6039 }
6040
6041 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6042 mHaveFrame = true;
6043
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006044 final Rect container = mContainingFrame;
6045 container.set(pf);
6046
6047 final Rect display = mDisplayFrame;
6048 display.set(df);
6049
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006050 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006051 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006052 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6053 display.intersect(mCompatibleScreenFrame);
6054 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006055 }
6056
6057 final int pw = container.right - container.left;
6058 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006059
6060 int w,h;
6061 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6062 w = mAttrs.width < 0 ? pw : mAttrs.width;
6063 h = mAttrs.height< 0 ? ph : mAttrs.height;
6064 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006065 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6066 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006067 }
Romain Guy06882f82009-06-10 13:36:04 -07006068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006069 final Rect content = mContentFrame;
6070 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 final Rect visible = mVisibleFrame;
6073 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006075 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006076 final int fw = frame.width();
6077 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006079 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6080 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6081
6082 Gravity.apply(mAttrs.gravity, w, h, container,
6083 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6084 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6085
6086 //System.out.println("Out: " + mFrame);
6087
6088 // Now make sure the window fits in the overall display.
6089 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006091 // Make sure the content and visible frames are inside of the
6092 // final window frame.
6093 if (content.left < frame.left) content.left = frame.left;
6094 if (content.top < frame.top) content.top = frame.top;
6095 if (content.right > frame.right) content.right = frame.right;
6096 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6097 if (visible.left < frame.left) visible.left = frame.left;
6098 if (visible.top < frame.top) visible.top = frame.top;
6099 if (visible.right > frame.right) visible.right = frame.right;
6100 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006102 final Rect contentInsets = mContentInsets;
6103 contentInsets.left = content.left-frame.left;
6104 contentInsets.top = content.top-frame.top;
6105 contentInsets.right = frame.right-content.right;
6106 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006108 final Rect visibleInsets = mVisibleInsets;
6109 visibleInsets.left = visible.left-frame.left;
6110 visibleInsets.top = visible.top-frame.top;
6111 visibleInsets.right = frame.right-visible.right;
6112 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006113
Dianne Hackborn284ac932009-08-28 10:34:25 -07006114 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6115 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006116 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006117 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006119 if (localLOGV) {
6120 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6121 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006122 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123 + mRequestedWidth + ", mRequestedheight="
6124 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6125 + "): frame=" + mFrame.toShortString()
6126 + " ci=" + contentInsets.toShortString()
6127 + " vi=" + visibleInsets.toShortString());
6128 //}
6129 }
6130 }
Romain Guy06882f82009-06-10 13:36:04 -07006131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132 public Rect getFrameLw() {
6133 return mFrame;
6134 }
6135
6136 public Rect getShownFrameLw() {
6137 return mShownFrame;
6138 }
6139
6140 public Rect getDisplayFrameLw() {
6141 return mDisplayFrame;
6142 }
6143
6144 public Rect getContentFrameLw() {
6145 return mContentFrame;
6146 }
6147
6148 public Rect getVisibleFrameLw() {
6149 return mVisibleFrame;
6150 }
6151
6152 public boolean getGivenInsetsPendingLw() {
6153 return mGivenInsetsPending;
6154 }
6155
6156 public Rect getGivenContentInsetsLw() {
6157 return mGivenContentInsets;
6158 }
Romain Guy06882f82009-06-10 13:36:04 -07006159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006160 public Rect getGivenVisibleInsetsLw() {
6161 return mGivenVisibleInsets;
6162 }
Romain Guy06882f82009-06-10 13:36:04 -07006163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 public WindowManager.LayoutParams getAttrs() {
6165 return mAttrs;
6166 }
6167
6168 public int getSurfaceLayer() {
6169 return mLayer;
6170 }
Romain Guy06882f82009-06-10 13:36:04 -07006171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 public IApplicationToken getAppToken() {
6173 return mAppToken != null ? mAppToken.appToken : null;
6174 }
Jeff Brown349703e2010-06-22 01:27:15 -07006175
6176 public long getInputDispatchingTimeoutNanos() {
6177 return mAppToken != null
6178 ? mAppToken.inputDispatchingTimeoutNanos
6179 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006181
6182 public boolean hasAppShownWindows() {
6183 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6184 }
6185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006187 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006188 TAG, "Setting animation in " + this + ": " + anim);
6189 mAnimating = false;
6190 mLocalAnimating = false;
6191 mAnimation = anim;
6192 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6193 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6194 }
6195
6196 public void clearAnimation() {
6197 if (mAnimation != null) {
6198 mAnimating = true;
6199 mLocalAnimating = false;
6200 mAnimation = null;
6201 }
6202 }
Romain Guy06882f82009-06-10 13:36:04 -07006203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006204 Surface createSurfaceLocked() {
6205 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006206 mReportDestroySurface = false;
6207 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006208 mDrawPending = true;
6209 mCommitDrawPending = false;
6210 mReadyToShow = false;
6211 if (mAppToken != null) {
6212 mAppToken.allDrawn = false;
6213 }
6214
6215 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006216 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006217 flags |= Surface.PUSH_BUFFERS;
6218 }
6219
6220 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6221 flags |= Surface.SECURE;
6222 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006223 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006224 TAG, "Creating surface in session "
6225 + mSession.mSurfaceSession + " window " + this
6226 + " w=" + mFrame.width()
6227 + " h=" + mFrame.height() + " format="
6228 + mAttrs.format + " flags=" + flags);
6229
6230 int w = mFrame.width();
6231 int h = mFrame.height();
6232 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6233 // for a scaled surface, we always want the requested
6234 // size.
6235 w = mRequestedWidth;
6236 h = mRequestedHeight;
6237 }
6238
Romain Guy9825ec62009-10-01 00:58:09 -07006239 // Something is wrong and SurfaceFlinger will not like this,
6240 // try to revert to sane values
6241 if (w <= 0) w = 1;
6242 if (h <= 0) h = 1;
6243
Dianne Hackborn16064f92010-03-25 00:47:24 -07006244 mSurfaceShown = false;
6245 mSurfaceLayer = 0;
6246 mSurfaceAlpha = 1;
6247 mSurfaceX = 0;
6248 mSurfaceY = 0;
6249 mSurfaceW = w;
6250 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006251 try {
6252 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006253 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006254 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006255 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006256 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006257 + mSurface + " IN SESSION "
6258 + mSession.mSurfaceSession
6259 + ": pid=" + mSession.mPid + " format="
6260 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006261 + Integer.toHexString(flags)
6262 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006263 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006264 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006265 reclaimSomeSurfaceMemoryLocked(this, "create");
6266 return null;
6267 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006268 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006269 return null;
6270 }
Romain Guy06882f82009-06-10 13:36:04 -07006271
Joe Onorato8a9b2202010-02-26 18:56:32 -08006272 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006273 TAG, "Got surface: " + mSurface
6274 + ", set left=" + mFrame.left + " top=" + mFrame.top
6275 + ", animLayer=" + mAnimLayer);
6276 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006277 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006278 if (SHOW_TRANSACTIONS) logSurface(this,
6279 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6280 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6281 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006282 }
6283 Surface.openTransaction();
6284 try {
6285 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006286 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006287 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006288 mSurface.setPosition(mSurfaceX, mSurfaceY);
6289 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006290 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006291 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 mSurface.hide();
6293 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006294 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295 mSurface.setFlags(Surface.SURFACE_DITHER,
6296 Surface.SURFACE_DITHER);
6297 }
6298 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006299 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006300 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6301 }
6302 mLastHidden = true;
6303 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006304 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305 Surface.closeTransaction();
6306 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006307 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006308 TAG, "Created surface " + this);
6309 }
6310 return mSurface;
6311 }
Romain Guy06882f82009-06-10 13:36:04 -07006312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006314 if (mAppToken != null && this == mAppToken.startingWindow) {
6315 mAppToken.startingDisplayed = false;
6316 }
Romain Guy06882f82009-06-10 13:36:04 -07006317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006318 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006319 mDrawPending = false;
6320 mCommitDrawPending = false;
6321 mReadyToShow = false;
6322
6323 int i = mChildWindows.size();
6324 while (i > 0) {
6325 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006326 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006327 c.mAttachedHidden = true;
6328 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006329
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006330 if (mReportDestroySurface) {
6331 mReportDestroySurface = false;
6332 mSurfacePendingDestroy = true;
6333 try {
6334 mClient.dispatchGetNewSurface();
6335 // We'll really destroy on the next time around.
6336 return;
6337 } catch (RemoteException e) {
6338 }
6339 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006341 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006342 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006343 RuntimeException e = null;
6344 if (!HIDE_STACK_CRAWLS) {
6345 e = new RuntimeException();
6346 e.fillInStackTrace();
6347 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006348 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006349 + mSurface + ", session " + mSession, e);
6350 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006351 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006352 RuntimeException e = null;
6353 if (!HIDE_STACK_CRAWLS) {
6354 e = new RuntimeException();
6355 e.fillInStackTrace();
6356 }
6357 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006358 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006359 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006361 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006362 + " surface " + mSurface + " session " + mSession
6363 + ": " + e.toString());
6364 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006365
Dianne Hackborn16064f92010-03-25 00:47:24 -07006366 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006367 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 }
6369 }
6370
6371 boolean finishDrawingLocked() {
6372 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006373 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 TAG, "finishDrawingLocked: " + mSurface);
6375 mCommitDrawPending = true;
6376 mDrawPending = false;
6377 return true;
6378 }
6379 return false;
6380 }
6381
6382 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006383 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006384 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006386 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 }
6388 mCommitDrawPending = false;
6389 mReadyToShow = true;
6390 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6391 final AppWindowToken atoken = mAppToken;
6392 if (atoken == null || atoken.allDrawn || starting) {
6393 performShowLocked();
6394 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006395 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 }
6397
6398 // This must be called while inside a transaction.
6399 boolean performShowLocked() {
6400 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006401 RuntimeException e = null;
6402 if (!HIDE_STACK_CRAWLS) {
6403 e = new RuntimeException();
6404 e.fillInStackTrace();
6405 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006406 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006407 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6408 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6409 }
6410 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006411 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6412 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006413 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 + " during animation: policyVis=" + mPolicyVisibility
6415 + " attHidden=" + mAttachedHidden
6416 + " tok.hiddenRequested="
6417 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006418 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 + (mAppToken != null ? mAppToken.hidden : false)
6420 + " animating=" + mAnimating
6421 + " tok animating="
6422 + (mAppToken != null ? mAppToken.animating : false));
6423 if (!showSurfaceRobustlyLocked(this)) {
6424 return false;
6425 }
6426 mLastAlpha = -1;
6427 mHasDrawn = true;
6428 mLastHidden = false;
6429 mReadyToShow = false;
6430 enableScreenIfNeededLocked();
6431
6432 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006434 int i = mChildWindows.size();
6435 while (i > 0) {
6436 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006437 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006438 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006440 if (c.mSurface != null) {
6441 c.performShowLocked();
6442 // It hadn't been shown, which means layout not
6443 // performed on it, so now we want to make sure to
6444 // do a layout. If called from within the transaction
6445 // loop, this will cause it to restart with a new
6446 // layout.
6447 mLayoutNeeded = true;
6448 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006449 }
6450 }
Romain Guy06882f82009-06-10 13:36:04 -07006451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006452 if (mAttrs.type != TYPE_APPLICATION_STARTING
6453 && mAppToken != null) {
6454 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006455
Dianne Hackborn248b1882009-09-16 16:46:44 -07006456 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006457 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006458 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006459 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006460 // If this initial window is animating, stop it -- we
6461 // will do an animation to reveal it from behind the
6462 // starting window, so there is no need for it to also
6463 // be doing its own stuff.
6464 if (mAnimation != null) {
6465 mAnimation = null;
6466 // Make sure we clean up the animation.
6467 mAnimating = true;
6468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 mFinishedStarting.add(mAppToken);
6470 mH.sendEmptyMessage(H.FINISHED_STARTING);
6471 }
6472 mAppToken.updateReportedVisibilityLocked();
6473 }
6474 }
6475 return true;
6476 }
Romain Guy06882f82009-06-10 13:36:04 -07006477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006478 // This must be called while inside a transaction. Returns true if
6479 // there is more animation to run.
6480 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006481 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006484 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6485 mHasTransformation = true;
6486 mHasLocalTransformation = true;
6487 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006488 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006489 TAG, "Starting animation in " + this +
6490 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6491 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6492 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6493 mAnimation.setStartTime(currentTime);
6494 mLocalAnimating = true;
6495 mAnimating = true;
6496 }
6497 mTransformation.clear();
6498 final boolean more = mAnimation.getTransformation(
6499 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006500 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006501 TAG, "Stepped animation in " + this +
6502 ": more=" + more + ", xform=" + mTransformation);
6503 if (more) {
6504 // we're not done!
6505 return true;
6506 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006507 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 TAG, "Finished animation in " + this +
6509 " @ " + currentTime);
6510 mAnimation = null;
6511 //WindowManagerService.this.dump();
6512 }
6513 mHasLocalTransformation = false;
6514 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006515 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006516 // When our app token is animating, we kind-of pretend like
6517 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6518 // part of this check means that we will only do this if
6519 // our window is not currently exiting, or it is not
6520 // locally animating itself. The idea being that one that
6521 // is exiting and doing a local animation should be removed
6522 // once that animation is done.
6523 mAnimating = true;
6524 mHasTransformation = true;
6525 mTransformation.clear();
6526 return false;
6527 } else if (mHasTransformation) {
6528 // Little trick to get through the path below to act like
6529 // we have finished an animation.
6530 mAnimating = true;
6531 } else if (isAnimating()) {
6532 mAnimating = true;
6533 }
6534 } else if (mAnimation != null) {
6535 // If the display is frozen, and there is a pending animation,
6536 // clear it and make sure we run the cleanup code.
6537 mAnimating = true;
6538 mLocalAnimating = true;
6539 mAnimation = null;
6540 }
Romain Guy06882f82009-06-10 13:36:04 -07006541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 if (!mAnimating && !mLocalAnimating) {
6543 return false;
6544 }
6545
Joe Onorato8a9b2202010-02-26 18:56:32 -08006546 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 TAG, "Animation done in " + this + ": exiting=" + mExiting
6548 + ", reportedVisible="
6549 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 mAnimating = false;
6552 mLocalAnimating = false;
6553 mAnimation = null;
6554 mAnimLayer = mLayer;
6555 if (mIsImWindow) {
6556 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006557 } else if (mIsWallpaper) {
6558 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006559 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006560 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 + " anim layer: " + mAnimLayer);
6562 mHasTransformation = false;
6563 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006564 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6565 if (DEBUG_VISIBILITY) {
6566 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6567 + mPolicyVisibilityAfterAnim);
6568 }
6569 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6570 if (!mPolicyVisibility) {
6571 if (mCurrentFocus == this) {
6572 mFocusMayChange = true;
6573 }
6574 // Window is no longer visible -- make sure if we were waiting
6575 // for it to be displayed before enabling the display, that
6576 // we allow the display to be enabled now.
6577 enableScreenIfNeededLocked();
6578 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006580 mTransformation.clear();
6581 if (mHasDrawn
6582 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6583 && mAppToken != null
6584 && mAppToken.firstWindowDrawn
6585 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006586 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 + mToken + ": first real window done animating");
6588 mFinishedStarting.add(mAppToken);
6589 mH.sendEmptyMessage(H.FINISHED_STARTING);
6590 }
Romain Guy06882f82009-06-10 13:36:04 -07006591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006592 finishExit();
6593
6594 if (mAppToken != null) {
6595 mAppToken.updateReportedVisibilityLocked();
6596 }
6597
6598 return false;
6599 }
6600
6601 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006602 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 TAG, "finishExit in " + this
6604 + ": exiting=" + mExiting
6605 + " remove=" + mRemoveOnExit
6606 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006608 final int N = mChildWindows.size();
6609 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006610 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006611 }
Romain Guy06882f82009-06-10 13:36:04 -07006612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 if (!mExiting) {
6614 return;
6615 }
Romain Guy06882f82009-06-10 13:36:04 -07006616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006617 if (isWindowAnimating()) {
6618 return;
6619 }
6620
Joe Onorato8a9b2202010-02-26 18:56:32 -08006621 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006622 TAG, "Exit animation finished in " + this
6623 + ": remove=" + mRemoveOnExit);
6624 if (mSurface != null) {
6625 mDestroySurface.add(this);
6626 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006627 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006628 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 try {
6630 mSurface.hide();
6631 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006632 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006633 }
6634 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 }
6636 mExiting = false;
6637 if (mRemoveOnExit) {
6638 mPendingRemove.add(this);
6639 mRemoveOnExit = false;
6640 }
6641 }
Romain Guy06882f82009-06-10 13:36:04 -07006642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006643 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6644 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6645 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6646 if (dtdx < -.000001f || dtdx > .000001f) return false;
6647 if (dsdy < -.000001f || dsdy > .000001f) return false;
6648 return true;
6649 }
Romain Guy06882f82009-06-10 13:36:04 -07006650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 void computeShownFrameLocked() {
6652 final boolean selfTransformation = mHasLocalTransformation;
6653 Transformation attachedTransformation =
6654 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6655 ? mAttachedWindow.mTransformation : null;
6656 Transformation appTransformation =
6657 (mAppToken != null && mAppToken.hasTransformation)
6658 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006659
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006660 // Wallpapers are animated based on the "real" window they
6661 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006662 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006663 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006664 if (mWallpaperTarget.mHasLocalTransformation &&
6665 mWallpaperTarget.mAnimation != null &&
6666 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006667 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006668 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006669 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006670 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006671 }
6672 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006673 mWallpaperTarget.mAppToken.hasTransformation &&
6674 mWallpaperTarget.mAppToken.animation != null &&
6675 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006676 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006677 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006678 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006679 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006680 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 if (selfTransformation || attachedTransformation != null
6684 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006685 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 final Rect frame = mFrame;
6687 final float tmpFloats[] = mTmpFloats;
6688 final Matrix tmpMatrix = mTmpMatrix;
6689
6690 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006691 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006692 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006693 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006694 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006695 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006696 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006697 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006698 }
6699 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006700 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006701 }
6702
6703 // "convert" it into SurfaceFlinger's format
6704 // (a 2x2 matrix + an offset)
6705 // Here we must not transform the position of the surface
6706 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006707 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709 tmpMatrix.getValues(tmpFloats);
6710 mDsDx = tmpFloats[Matrix.MSCALE_X];
6711 mDtDx = tmpFloats[Matrix.MSKEW_X];
6712 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6713 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006714 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6715 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 int w = frame.width();
6717 int h = frame.height();
6718 mShownFrame.set(x, y, x+w, y+h);
6719
6720 // Now set the alpha... but because our current hardware
6721 // can't do alpha transformation on a non-opaque surface,
6722 // turn it off if we are running an animation that is also
6723 // transforming since it is more important to have that
6724 // animation be smooth.
6725 mShownAlpha = mAlpha;
6726 if (!mLimitedAlphaCompositing
6727 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6728 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6729 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006730 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006731 if (selfTransformation) {
6732 mShownAlpha *= mTransformation.getAlpha();
6733 }
6734 if (attachedTransformation != null) {
6735 mShownAlpha *= attachedTransformation.getAlpha();
6736 }
6737 if (appTransformation != null) {
6738 mShownAlpha *= appTransformation.getAlpha();
6739 }
6740 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006741 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 }
Romain Guy06882f82009-06-10 13:36:04 -07006743
Joe Onorato8a9b2202010-02-26 18:56:32 -08006744 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 TAG, "Continuing animation in " + this +
6746 ": " + mShownFrame +
6747 ", alpha=" + mTransformation.getAlpha());
6748 return;
6749 }
Romain Guy06882f82009-06-10 13:36:04 -07006750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006751 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006752 if (mXOffset != 0 || mYOffset != 0) {
6753 mShownFrame.offset(mXOffset, mYOffset);
6754 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 mShownAlpha = mAlpha;
6756 mDsDx = 1;
6757 mDtDx = 0;
6758 mDsDy = 0;
6759 mDtDy = 1;
6760 }
Romain Guy06882f82009-06-10 13:36:04 -07006761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 /**
6763 * Is this window visible? It is not visible if there is no
6764 * surface, or we are in the process of running an exit animation
6765 * that will remove the surface, or its app token has been hidden.
6766 */
6767 public boolean isVisibleLw() {
6768 final AppWindowToken atoken = mAppToken;
6769 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6770 && (atoken == null || !atoken.hiddenRequested)
6771 && !mExiting && !mDestroying;
6772 }
6773
6774 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006775 * Like {@link #isVisibleLw}, but also counts a window that is currently
6776 * "hidden" behind the keyguard as visible. This allows us to apply
6777 * things like window flags that impact the keyguard.
6778 * XXX I am starting to think we need to have ANOTHER visibility flag
6779 * for this "hidden behind keyguard" state rather than overloading
6780 * mPolicyVisibility. Ungh.
6781 */
6782 public boolean isVisibleOrBehindKeyguardLw() {
6783 final AppWindowToken atoken = mAppToken;
6784 return mSurface != null && !mAttachedHidden
6785 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006786 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006787 && !mExiting && !mDestroying;
6788 }
6789
6790 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 * Is this window visible, ignoring its app token? It is not visible
6792 * if there is no surface, or we are in the process of running an exit animation
6793 * that will remove the surface.
6794 */
6795 public boolean isWinVisibleLw() {
6796 final AppWindowToken atoken = mAppToken;
6797 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6798 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6799 && !mExiting && !mDestroying;
6800 }
6801
6802 /**
6803 * The same as isVisible(), but follows the current hidden state of
6804 * the associated app token, not the pending requested hidden state.
6805 */
6806 boolean isVisibleNow() {
6807 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006808 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006809 }
6810
6811 /**
6812 * Same as isVisible(), but we also count it as visible between the
6813 * call to IWindowSession.add() and the first relayout().
6814 */
6815 boolean isVisibleOrAdding() {
6816 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006817 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6819 && mPolicyVisibility && !mAttachedHidden
6820 && (atoken == null || !atoken.hiddenRequested)
6821 && !mExiting && !mDestroying;
6822 }
6823
6824 /**
6825 * Is this window currently on-screen? It is on-screen either if it
6826 * is visible or it is currently running an animation before no longer
6827 * being visible.
6828 */
6829 boolean isOnScreen() {
6830 final AppWindowToken atoken = mAppToken;
6831 if (atoken != null) {
6832 return mSurface != null && mPolicyVisibility && !mDestroying
6833 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006834 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006835 } else {
6836 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006837 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 }
6839 }
Romain Guy06882f82009-06-10 13:36:04 -07006840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 /**
6842 * Like isOnScreen(), but we don't return true if the window is part
6843 * of a transition that has not yet been started.
6844 */
6845 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006846 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006847 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006848 return false;
6849 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006850 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006851 final boolean animating = atoken != null
6852 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006854 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6855 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006856 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 }
6858
6859 /** Is the window or its container currently animating? */
6860 boolean isAnimating() {
6861 final WindowState attached = mAttachedWindow;
6862 final AppWindowToken atoken = mAppToken;
6863 return mAnimation != null
6864 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006865 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 (atoken.animation != null
6867 || atoken.inPendingTransaction));
6868 }
6869
6870 /** Is this window currently animating? */
6871 boolean isWindowAnimating() {
6872 return mAnimation != null;
6873 }
6874
6875 /**
6876 * Like isOnScreen, but returns false if the surface hasn't yet
6877 * been drawn.
6878 */
6879 public boolean isDisplayedLw() {
6880 final AppWindowToken atoken = mAppToken;
6881 return mSurface != null && mPolicyVisibility && !mDestroying
6882 && !mDrawPending && !mCommitDrawPending
6883 && ((!mAttachedHidden &&
6884 (atoken == null || !atoken.hiddenRequested))
6885 || mAnimating);
6886 }
6887
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006888 /**
6889 * Returns true if the window has a surface that it has drawn a
6890 * complete UI in to.
6891 */
6892 public boolean isDrawnLw() {
6893 final AppWindowToken atoken = mAppToken;
6894 return mSurface != null && !mDestroying
6895 && !mDrawPending && !mCommitDrawPending;
6896 }
6897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006898 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6899 boolean shownFrame, boolean onlyOpaque) {
6900 if (mSurface == null) {
6901 return false;
6902 }
6903 if (mAppToken != null && !mAppToken.appFullscreen) {
6904 return false;
6905 }
6906 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6907 return false;
6908 }
6909 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006910
6911 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6912 return frame.left <= mCompatibleScreenFrame.left &&
6913 frame.top <= mCompatibleScreenFrame.top &&
6914 frame.right >= mCompatibleScreenFrame.right &&
6915 frame.bottom >= mCompatibleScreenFrame.bottom;
6916 } else {
6917 return frame.left <= 0 && frame.top <= 0
6918 && frame.right >= screenWidth
6919 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 }
Romain Guy06882f82009-06-10 13:36:04 -07006922
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006923 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006924 * Return true if the window is opaque and fully drawn. This indicates
6925 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006926 */
6927 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006928 return (mAttrs.format == PixelFormat.OPAQUE
6929 || mAttrs.type == TYPE_WALLPAPER)
6930 && mSurface != null && mAnimation == null
6931 && (mAppToken == null || mAppToken.animation == null)
6932 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006933 }
6934
6935 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6936 return
6937 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006938 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6939 // only if it's visible
6940 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006941 // and only if the application fills the compatible screen
6942 mFrame.left <= mCompatibleScreenFrame.left &&
6943 mFrame.top <= mCompatibleScreenFrame.top &&
6944 mFrame.right >= mCompatibleScreenFrame.right &&
6945 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006946 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006947 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006948 }
6949
6950 boolean isFullscreen(int screenWidth, int screenHeight) {
6951 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006952 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006953 }
6954
6955 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07006956 disposeInputChannel();
6957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958 if (mAttachedWindow != null) {
6959 mAttachedWindow.mChildWindows.remove(this);
6960 }
6961 destroySurfaceLocked();
6962 mSession.windowRemovedLocked();
6963 try {
6964 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
6965 } catch (RuntimeException e) {
6966 // Ignore if it has already been removed (usually because
6967 // we are doing this as part of processing a death note.)
6968 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07006969 }
6970
6971 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006972 if (mInputChannel != null) {
6973 mInputManager.unregisterInputChannel(mInputChannel);
6974
6975 mInputChannel.dispose();
6976 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 }
6979
6980 private class DeathRecipient implements IBinder.DeathRecipient {
6981 public void binderDied() {
6982 try {
6983 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006984 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006985 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006986 if (win != null) {
6987 removeWindowLocked(mSession, win);
6988 }
6989 }
6990 } catch (IllegalArgumentException ex) {
6991 // This will happen if the window has already been
6992 // removed.
6993 }
6994 }
6995 }
6996
6997 /** Returns true if this window desires key events. */
6998 public final boolean canReceiveKeys() {
6999 return isVisibleOrAdding()
7000 && (mViewVisibility == View.VISIBLE)
7001 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7002 }
7003
7004 public boolean hasDrawnLw() {
7005 return mHasDrawn;
7006 }
7007
7008 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007009 return showLw(doAnimation, true);
7010 }
7011
7012 boolean showLw(boolean doAnimation, boolean requestAnim) {
7013 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7014 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007015 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007016 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007017 if (doAnimation) {
7018 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7019 + mPolicyVisibility + " mAnimation=" + mAnimation);
7020 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7021 doAnimation = false;
7022 } else if (mPolicyVisibility && mAnimation == null) {
7023 // Check for the case where we are currently visible and
7024 // not animating; we do not want to do animation at such a
7025 // point to become visible when we already are.
7026 doAnimation = false;
7027 }
7028 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007029 mPolicyVisibility = true;
7030 mPolicyVisibilityAfterAnim = true;
7031 if (doAnimation) {
7032 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7033 }
7034 if (requestAnim) {
7035 requestAnimationLocked(0);
7036 }
7037 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 }
7039
7040 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007041 return hideLw(doAnimation, true);
7042 }
7043
7044 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007045 if (doAnimation) {
7046 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7047 doAnimation = false;
7048 }
7049 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007050 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7051 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007052 if (!current) {
7053 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007055 if (doAnimation) {
7056 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7057 if (mAnimation == null) {
7058 doAnimation = false;
7059 }
7060 }
7061 if (doAnimation) {
7062 mPolicyVisibilityAfterAnim = false;
7063 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007064 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007065 mPolicyVisibilityAfterAnim = false;
7066 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007067 // Window is no longer visible -- make sure if we were waiting
7068 // for it to be displayed before enabling the display, that
7069 // we allow the display to be enabled now.
7070 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007071 if (mCurrentFocus == this) {
7072 mFocusMayChange = true;
7073 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007074 }
7075 if (requestAnim) {
7076 requestAnimationLocked(0);
7077 }
7078 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 }
7080
7081 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007082 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7083 pw.print(" mClient="); pw.println(mClient.asBinder());
7084 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7085 if (mAttachedWindow != null || mLayoutAttached) {
7086 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7087 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7088 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007089 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7090 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7091 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007092 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7093 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007094 }
7095 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7096 pw.print(" mSubLayer="); pw.print(mSubLayer);
7097 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7098 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7099 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7100 pw.print("="); pw.print(mAnimLayer);
7101 pw.print(" mLastLayer="); pw.println(mLastLayer);
7102 if (mSurface != null) {
7103 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007104 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7105 pw.print(" layer="); pw.print(mSurfaceLayer);
7106 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7107 pw.print(" rect=("); pw.print(mSurfaceX);
7108 pw.print(","); pw.print(mSurfaceY);
7109 pw.print(") "); pw.print(mSurfaceW);
7110 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007111 }
7112 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7113 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7114 if (mAppToken != null) {
7115 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7116 }
7117 if (mTargetAppToken != null) {
7118 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7119 }
7120 pw.print(prefix); pw.print("mViewVisibility=0x");
7121 pw.print(Integer.toHexString(mViewVisibility));
7122 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007123 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7124 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007125 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7126 pw.print(prefix); pw.print("mPolicyVisibility=");
7127 pw.print(mPolicyVisibility);
7128 pw.print(" mPolicyVisibilityAfterAnim=");
7129 pw.print(mPolicyVisibilityAfterAnim);
7130 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7131 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007132 if (!mRelayoutCalled) {
7133 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7134 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007135 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007136 pw.print(" h="); pw.print(mRequestedHeight);
7137 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007138 if (mXOffset != 0 || mYOffset != 0) {
7139 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7140 pw.print(" y="); pw.println(mYOffset);
7141 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007142 pw.print(prefix); pw.print("mGivenContentInsets=");
7143 mGivenContentInsets.printShortString(pw);
7144 pw.print(" mGivenVisibleInsets=");
7145 mGivenVisibleInsets.printShortString(pw);
7146 pw.println();
7147 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7148 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7149 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7150 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007151 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007152 pw.print(prefix); pw.print("mShownFrame=");
7153 mShownFrame.printShortString(pw);
7154 pw.print(" last="); mLastShownFrame.printShortString(pw);
7155 pw.println();
7156 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7157 pw.print(" last="); mLastFrame.printShortString(pw);
7158 pw.println();
7159 pw.print(prefix); pw.print("mContainingFrame=");
7160 mContainingFrame.printShortString(pw);
7161 pw.print(" mDisplayFrame=");
7162 mDisplayFrame.printShortString(pw);
7163 pw.println();
7164 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7165 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7166 pw.println();
7167 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7168 pw.print(" last="); mLastContentInsets.printShortString(pw);
7169 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7170 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7171 pw.println();
7172 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7173 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7174 pw.print(" mAlpha="); pw.print(mAlpha);
7175 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7176 }
7177 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7178 || mAnimation != null) {
7179 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7180 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7181 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7182 pw.print(" mAnimation="); pw.println(mAnimation);
7183 }
7184 if (mHasTransformation || mHasLocalTransformation) {
7185 pw.print(prefix); pw.print("XForm: has=");
7186 pw.print(mHasTransformation);
7187 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7188 pw.print(" "); mTransformation.printShortString(pw);
7189 pw.println();
7190 }
7191 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7192 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7193 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7194 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7195 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7196 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7197 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7198 pw.print(" mDestroying="); pw.print(mDestroying);
7199 pw.print(" mRemoved="); pw.println(mRemoved);
7200 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007201 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007202 pw.print(prefix); pw.print("mOrientationChanging=");
7203 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007204 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7205 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007206 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007207 if (mHScale != 1 || mVScale != 1) {
7208 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7209 pw.print(" mVScale="); pw.println(mVScale);
7210 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007211 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007212 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7213 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7214 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007215 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7216 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7217 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7218 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007219 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007220
7221 String makeInputChannelName() {
7222 return Integer.toHexString(System.identityHashCode(this))
7223 + " " + mAttrs.getTitle();
7224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007225
7226 @Override
7227 public String toString() {
7228 return "Window{"
7229 + Integer.toHexString(System.identityHashCode(this))
7230 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7231 }
7232 }
Romain Guy06882f82009-06-10 13:36:04 -07007233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007234 // -------------------------------------------------------------
7235 // Window Token State
7236 // -------------------------------------------------------------
7237
7238 class WindowToken {
7239 // The actual token.
7240 final IBinder token;
7241
7242 // The type of window this token is for, as per WindowManager.LayoutParams.
7243 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007245 // Set if this token was explicitly added by a client, so should
7246 // not be removed when all windows are removed.
7247 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007248
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007249 // For printing.
7250 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 // If this is an AppWindowToken, this is non-null.
7253 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 // All of the windows associated with this token.
7256 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7257
7258 // Is key dispatching paused for this token?
7259 boolean paused = false;
7260
7261 // Should this token's windows be hidden?
7262 boolean hidden;
7263
7264 // Temporary for finding which tokens no longer have visible windows.
7265 boolean hasVisible;
7266
Dianne Hackborna8f60182009-09-01 19:01:50 -07007267 // Set to true when this token is in a pending transaction where it
7268 // will be shown.
7269 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007270
Dianne Hackborna8f60182009-09-01 19:01:50 -07007271 // Set to true when this token is in a pending transaction where it
7272 // will be hidden.
7273 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007274
Dianne Hackborna8f60182009-09-01 19:01:50 -07007275 // Set to true when this token is in a pending transaction where its
7276 // windows will be put to the bottom of the list.
7277 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007278
Dianne Hackborna8f60182009-09-01 19:01:50 -07007279 // Set to true when this token is in a pending transaction where its
7280 // windows will be put to the top of the list.
7281 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 WindowToken(IBinder _token, int type, boolean _explicit) {
7284 token = _token;
7285 windowType = type;
7286 explicit = _explicit;
7287 }
7288
7289 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007290 pw.print(prefix); pw.print("token="); pw.println(token);
7291 pw.print(prefix); pw.print("windows="); pw.println(windows);
7292 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7293 pw.print(" hidden="); pw.print(hidden);
7294 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007295 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7296 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7297 pw.print(" waitingToHide="); pw.print(waitingToHide);
7298 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7299 pw.print(" sendingToTop="); pw.println(sendingToTop);
7300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301 }
7302
7303 @Override
7304 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007305 if (stringName == null) {
7306 StringBuilder sb = new StringBuilder();
7307 sb.append("WindowToken{");
7308 sb.append(Integer.toHexString(System.identityHashCode(this)));
7309 sb.append(" token="); sb.append(token); sb.append('}');
7310 stringName = sb.toString();
7311 }
7312 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007313 }
7314 };
7315
7316 class AppWindowToken extends WindowToken {
7317 // Non-null only for application tokens.
7318 final IApplicationToken appToken;
7319
7320 // All of the windows and child windows that are included in this
7321 // application token. Note this list is NOT sorted!
7322 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7323
7324 int groupId = -1;
7325 boolean appFullscreen;
7326 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007327
7328 // The input dispatching timeout for this application token in nanoseconds.
7329 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 // These are used for determining when all windows associated with
7332 // an activity have been drawn, so they can be made visible together
7333 // at the same time.
7334 int lastTransactionSequence = mTransactionSequence-1;
7335 int numInterestingWindows;
7336 int numDrawnWindows;
7337 boolean inPendingTransaction;
7338 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 // Is this token going to be hidden in a little while? If so, it
7341 // won't be taken into account for setting the screen orientation.
7342 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 // Is this window's surface needed? This is almost like hidden, except
7345 // it will sometimes be true a little earlier: when the token has
7346 // been shown, but is still waiting for its app transition to execute
7347 // before making its windows shown.
7348 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 // Have we told the window clients to hide themselves?
7351 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353 // Last visibility state we reported to the app token.
7354 boolean reportedVisible;
7355
7356 // Set to true when the token has been removed from the window mgr.
7357 boolean removed;
7358
7359 // Have we been asked to have this token keep the screen frozen?
7360 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 boolean animating;
7363 Animation animation;
7364 boolean hasTransformation;
7365 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007367 // Offset to the window of all layers in the token, for use by
7368 // AppWindowToken animations.
7369 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007371 // Information about an application starting window if displayed.
7372 StartingData startingData;
7373 WindowState startingWindow;
7374 View startingView;
7375 boolean startingDisplayed;
7376 boolean startingMoved;
7377 boolean firstWindowDrawn;
7378
7379 AppWindowToken(IApplicationToken _token) {
7380 super(_token.asBinder(),
7381 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7382 appWindowToken = this;
7383 appToken = _token;
7384 }
Romain Guy06882f82009-06-10 13:36:04 -07007385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007387 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007388 TAG, "Setting animation in " + this + ": " + anim);
7389 animation = anim;
7390 animating = false;
7391 anim.restrictDuration(MAX_ANIMATION_DURATION);
7392 anim.scaleCurrentDuration(mTransitionAnimationScale);
7393 int zorder = anim.getZAdjustment();
7394 int adj = 0;
7395 if (zorder == Animation.ZORDER_TOP) {
7396 adj = TYPE_LAYER_OFFSET;
7397 } else if (zorder == Animation.ZORDER_BOTTOM) {
7398 adj = -TYPE_LAYER_OFFSET;
7399 }
Romain Guy06882f82009-06-10 13:36:04 -07007400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401 if (animLayerAdjustment != adj) {
7402 animLayerAdjustment = adj;
7403 updateLayers();
7404 }
7405 }
Romain Guy06882f82009-06-10 13:36:04 -07007406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007407 public void setDummyAnimation() {
7408 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007409 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 TAG, "Setting dummy animation in " + this);
7411 animation = sDummyAnimation;
7412 }
7413 }
7414
7415 public void clearAnimation() {
7416 if (animation != null) {
7417 animation = null;
7418 animating = true;
7419 }
7420 }
Romain Guy06882f82009-06-10 13:36:04 -07007421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 void updateLayers() {
7423 final int N = allAppWindows.size();
7424 final int adj = animLayerAdjustment;
7425 for (int i=0; i<N; i++) {
7426 WindowState w = allAppWindows.get(i);
7427 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007428 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 + w.mAnimLayer);
7430 if (w == mInputMethodTarget) {
7431 setInputMethodAnimLayerAdjustment(adj);
7432 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007433 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007434 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 }
7437 }
Romain Guy06882f82009-06-10 13:36:04 -07007438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007439 void sendAppVisibilityToClients() {
7440 final int N = allAppWindows.size();
7441 for (int i=0; i<N; i++) {
7442 WindowState win = allAppWindows.get(i);
7443 if (win == startingWindow && clientHidden) {
7444 // Don't hide the starting window.
7445 continue;
7446 }
7447 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007448 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 "Setting visibility of " + win + ": " + (!clientHidden));
7450 win.mClient.dispatchAppVisibility(!clientHidden);
7451 } catch (RemoteException e) {
7452 }
7453 }
7454 }
Romain Guy06882f82009-06-10 13:36:04 -07007455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 void showAllWindowsLocked() {
7457 final int NW = allAppWindows.size();
7458 for (int i=0; i<NW; i++) {
7459 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007460 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 "performing show on: " + w);
7462 w.performShowLocked();
7463 }
7464 }
Romain Guy06882f82009-06-10 13:36:04 -07007465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007466 // This must be called while inside a transaction.
7467 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007468 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007469 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007471 if (animation == sDummyAnimation) {
7472 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007473 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 // when it is really time to animate, this will be set to
7475 // a real animation and the next call will execute normally.
7476 return false;
7477 }
Romain Guy06882f82009-06-10 13:36:04 -07007478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007479 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7480 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007481 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007482 TAG, "Starting animation in " + this +
7483 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7484 + " scale=" + mTransitionAnimationScale
7485 + " allDrawn=" + allDrawn + " animating=" + animating);
7486 animation.initialize(dw, dh, dw, dh);
7487 animation.setStartTime(currentTime);
7488 animating = true;
7489 }
7490 transformation.clear();
7491 final boolean more = animation.getTransformation(
7492 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007493 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 TAG, "Stepped animation in " + this +
7495 ": more=" + more + ", xform=" + transformation);
7496 if (more) {
7497 // we're done!
7498 hasTransformation = true;
7499 return true;
7500 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007501 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007502 TAG, "Finished animation in " + this +
7503 " @ " + currentTime);
7504 animation = null;
7505 }
7506 } else if (animation != null) {
7507 // If the display is frozen, and there is a pending animation,
7508 // clear it and make sure we run the cleanup code.
7509 animating = true;
7510 animation = null;
7511 }
7512
7513 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007515 if (!animating) {
7516 return false;
7517 }
7518
7519 clearAnimation();
7520 animating = false;
7521 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7522 moveInputMethodWindowsIfNeededLocked(true);
7523 }
Romain Guy06882f82009-06-10 13:36:04 -07007524
Joe Onorato8a9b2202010-02-26 18:56:32 -08007525 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 TAG, "Animation done in " + this
7527 + ": reportedVisible=" + reportedVisible);
7528
7529 transformation.clear();
7530 if (animLayerAdjustment != 0) {
7531 animLayerAdjustment = 0;
7532 updateLayers();
7533 }
Romain Guy06882f82009-06-10 13:36:04 -07007534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007535 final int N = windows.size();
7536 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007537 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007538 }
7539 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007541 return false;
7542 }
7543
7544 void updateReportedVisibilityLocked() {
7545 if (appToken == null) {
7546 return;
7547 }
Romain Guy06882f82009-06-10 13:36:04 -07007548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007549 int numInteresting = 0;
7550 int numVisible = 0;
7551 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007552
Joe Onorato8a9b2202010-02-26 18:56:32 -08007553 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007554 final int N = allAppWindows.size();
7555 for (int i=0; i<N; i++) {
7556 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007557 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007558 || win.mViewVisibility != View.VISIBLE
7559 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007560 continue;
7561 }
7562 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007563 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007564 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007566 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007567 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007568 + " pv=" + win.mPolicyVisibility
7569 + " dp=" + win.mDrawPending
7570 + " cdp=" + win.mCommitDrawPending
7571 + " ah=" + win.mAttachedHidden
7572 + " th="
7573 + (win.mAppToken != null
7574 ? win.mAppToken.hiddenRequested : false)
7575 + " a=" + win.mAnimating);
7576 }
7577 }
7578 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007579 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 if (!win.isAnimating()) {
7581 numVisible++;
7582 }
7583 nowGone = false;
7584 } else if (win.isAnimating()) {
7585 nowGone = false;
7586 }
7587 }
Romain Guy06882f82009-06-10 13:36:04 -07007588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007589 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007590 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 + numInteresting + " visible=" + numVisible);
7592 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007593 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 TAG, "Visibility changed in " + this
7595 + ": vis=" + nowVisible);
7596 reportedVisible = nowVisible;
7597 Message m = mH.obtainMessage(
7598 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7599 nowVisible ? 1 : 0,
7600 nowGone ? 1 : 0,
7601 this);
7602 mH.sendMessage(m);
7603 }
7604 }
Romain Guy06882f82009-06-10 13:36:04 -07007605
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007606 WindowState findMainWindow() {
7607 int j = windows.size();
7608 while (j > 0) {
7609 j--;
7610 WindowState win = windows.get(j);
7611 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7612 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7613 return win;
7614 }
7615 }
7616 return null;
7617 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007619 void dump(PrintWriter pw, String prefix) {
7620 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007621 if (appToken != null) {
7622 pw.print(prefix); pw.println("app=true");
7623 }
7624 if (allAppWindows.size() > 0) {
7625 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7626 }
7627 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007628 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007629 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7630 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7631 pw.print(" clientHidden="); pw.print(clientHidden);
7632 pw.print(" willBeHidden="); pw.print(willBeHidden);
7633 pw.print(" reportedVisible="); pw.println(reportedVisible);
7634 if (paused || freezingScreen) {
7635 pw.print(prefix); pw.print("paused="); pw.print(paused);
7636 pw.print(" freezingScreen="); pw.println(freezingScreen);
7637 }
7638 if (numInterestingWindows != 0 || numDrawnWindows != 0
7639 || inPendingTransaction || allDrawn) {
7640 pw.print(prefix); pw.print("numInterestingWindows=");
7641 pw.print(numInterestingWindows);
7642 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7643 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7644 pw.print(" allDrawn="); pw.println(allDrawn);
7645 }
7646 if (animating || animation != null) {
7647 pw.print(prefix); pw.print("animating="); pw.print(animating);
7648 pw.print(" animation="); pw.println(animation);
7649 }
7650 if (animLayerAdjustment != 0) {
7651 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7652 }
7653 if (hasTransformation) {
7654 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7655 pw.print(" transformation="); transformation.printShortString(pw);
7656 pw.println();
7657 }
7658 if (startingData != null || removed || firstWindowDrawn) {
7659 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7660 pw.print(" removed="); pw.print(removed);
7661 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7662 }
7663 if (startingWindow != null || startingView != null
7664 || startingDisplayed || startingMoved) {
7665 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7666 pw.print(" startingView="); pw.print(startingView);
7667 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7668 pw.print(" startingMoved"); pw.println(startingMoved);
7669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007670 }
7671
7672 @Override
7673 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007674 if (stringName == null) {
7675 StringBuilder sb = new StringBuilder();
7676 sb.append("AppWindowToken{");
7677 sb.append(Integer.toHexString(System.identityHashCode(this)));
7678 sb.append(" token="); sb.append(token); sb.append('}');
7679 stringName = sb.toString();
7680 }
7681 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007682 }
7683 }
Romain Guy06882f82009-06-10 13:36:04 -07007684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 // -------------------------------------------------------------
7686 // DummyAnimation
7687 // -------------------------------------------------------------
7688
7689 // This is an animation that does nothing: it just immediately finishes
7690 // itself every time it is called. It is used as a stub animation in cases
7691 // where we want to synchronize multiple things that may be animating.
7692 static final class DummyAnimation extends Animation {
7693 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7694 return false;
7695 }
7696 }
7697 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007699 // -------------------------------------------------------------
7700 // Async Handler
7701 // -------------------------------------------------------------
7702
7703 static final class StartingData {
7704 final String pkg;
7705 final int theme;
7706 final CharSequence nonLocalizedLabel;
7707 final int labelRes;
7708 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007710 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7711 int _labelRes, int _icon) {
7712 pkg = _pkg;
7713 theme = _theme;
7714 nonLocalizedLabel = _nonLocalizedLabel;
7715 labelRes = _labelRes;
7716 icon = _icon;
7717 }
7718 }
7719
7720 private final class H extends Handler {
7721 public static final int REPORT_FOCUS_CHANGE = 2;
7722 public static final int REPORT_LOSING_FOCUS = 3;
7723 public static final int ANIMATE = 4;
7724 public static final int ADD_STARTING = 5;
7725 public static final int REMOVE_STARTING = 6;
7726 public static final int FINISHED_STARTING = 7;
7727 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007728 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7729 public static final int HOLD_SCREEN_CHANGED = 12;
7730 public static final int APP_TRANSITION_TIMEOUT = 13;
7731 public static final int PERSIST_ANIMATION_SCALE = 14;
7732 public static final int FORCE_GC = 15;
7733 public static final int ENABLE_SCREEN = 16;
7734 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007735 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007736 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007738 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007740 public H() {
7741 }
Romain Guy06882f82009-06-10 13:36:04 -07007742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007743 @Override
7744 public void handleMessage(Message msg) {
7745 switch (msg.what) {
7746 case REPORT_FOCUS_CHANGE: {
7747 WindowState lastFocus;
7748 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 synchronized(mWindowMap) {
7751 lastFocus = mLastFocus;
7752 newFocus = mCurrentFocus;
7753 if (lastFocus == newFocus) {
7754 // Focus is not changing, so nothing to do.
7755 return;
7756 }
7757 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007758 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 // + " to " + newFocus);
7760 if (newFocus != null && lastFocus != null
7761 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007762 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007763 mLosingFocus.add(lastFocus);
7764 lastFocus = null;
7765 }
7766 }
7767
7768 if (lastFocus != newFocus) {
7769 //System.out.println("Changing focus from " + lastFocus
7770 // + " to " + newFocus);
7771 if (newFocus != null) {
7772 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007773 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7775 } catch (RemoteException e) {
7776 // Ignore if process has died.
7777 }
7778 }
7779
7780 if (lastFocus != null) {
7781 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007782 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7784 } catch (RemoteException e) {
7785 // Ignore if process has died.
7786 }
7787 }
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007788 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007789 }
7790 } break;
7791
7792 case REPORT_LOSING_FOCUS: {
7793 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007795 synchronized(mWindowMap) {
7796 losers = mLosingFocus;
7797 mLosingFocus = new ArrayList<WindowState>();
7798 }
7799
7800 final int N = losers.size();
7801 for (int i=0; i<N; i++) {
7802 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007803 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007804 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7805 } catch (RemoteException e) {
7806 // Ignore if process has died.
7807 }
7808 }
7809 } break;
7810
7811 case ANIMATE: {
7812 synchronized(mWindowMap) {
7813 mAnimationPending = false;
7814 performLayoutAndPlaceSurfacesLocked();
7815 }
7816 } break;
7817
7818 case ADD_STARTING: {
7819 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7820 final StartingData sd = wtoken.startingData;
7821
7822 if (sd == null) {
7823 // Animation has been canceled... do nothing.
7824 return;
7825 }
Romain Guy06882f82009-06-10 13:36:04 -07007826
Joe Onorato8a9b2202010-02-26 18:56:32 -08007827 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007828 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007830 View view = null;
7831 try {
7832 view = mPolicy.addStartingWindow(
7833 wtoken.token, sd.pkg,
7834 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7835 sd.icon);
7836 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007837 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007838 }
7839
7840 if (view != null) {
7841 boolean abort = false;
7842
7843 synchronized(mWindowMap) {
7844 if (wtoken.removed || wtoken.startingData == null) {
7845 // If the window was successfully added, then
7846 // we need to remove it.
7847 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007848 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007849 "Aborted starting " + wtoken
7850 + ": removed=" + wtoken.removed
7851 + " startingData=" + wtoken.startingData);
7852 wtoken.startingWindow = null;
7853 wtoken.startingData = null;
7854 abort = true;
7855 }
7856 } else {
7857 wtoken.startingView = view;
7858 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007859 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007860 "Added starting " + wtoken
7861 + ": startingWindow="
7862 + wtoken.startingWindow + " startingView="
7863 + wtoken.startingView);
7864 }
7865
7866 if (abort) {
7867 try {
7868 mPolicy.removeStartingWindow(wtoken.token, view);
7869 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007870 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 }
7872 }
7873 }
7874 } break;
7875
7876 case REMOVE_STARTING: {
7877 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7878 IBinder token = null;
7879 View view = null;
7880 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007881 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007882 + wtoken + ": startingWindow="
7883 + wtoken.startingWindow + " startingView="
7884 + wtoken.startingView);
7885 if (wtoken.startingWindow != null) {
7886 view = wtoken.startingView;
7887 token = wtoken.token;
7888 wtoken.startingData = null;
7889 wtoken.startingView = null;
7890 wtoken.startingWindow = null;
7891 }
7892 }
7893 if (view != null) {
7894 try {
7895 mPolicy.removeStartingWindow(token, view);
7896 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007897 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 }
7899 }
7900 } break;
7901
7902 case FINISHED_STARTING: {
7903 IBinder token = null;
7904 View view = null;
7905 while (true) {
7906 synchronized (mWindowMap) {
7907 final int N = mFinishedStarting.size();
7908 if (N <= 0) {
7909 break;
7910 }
7911 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7912
Joe Onorato8a9b2202010-02-26 18:56:32 -08007913 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007914 "Finished starting " + wtoken
7915 + ": startingWindow=" + wtoken.startingWindow
7916 + " startingView=" + wtoken.startingView);
7917
7918 if (wtoken.startingWindow == null) {
7919 continue;
7920 }
7921
7922 view = wtoken.startingView;
7923 token = wtoken.token;
7924 wtoken.startingData = null;
7925 wtoken.startingView = null;
7926 wtoken.startingWindow = null;
7927 }
7928
7929 try {
7930 mPolicy.removeStartingWindow(token, view);
7931 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007932 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007933 }
7934 }
7935 } break;
7936
7937 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7938 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7939
7940 boolean nowVisible = msg.arg1 != 0;
7941 boolean nowGone = msg.arg2 != 0;
7942
7943 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007944 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007945 TAG, "Reporting visible in " + wtoken
7946 + " visible=" + nowVisible
7947 + " gone=" + nowGone);
7948 if (nowVisible) {
7949 wtoken.appToken.windowsVisible();
7950 } else {
7951 wtoken.appToken.windowsGone();
7952 }
7953 } catch (RemoteException ex) {
7954 }
7955 } break;
Romain Guy06882f82009-06-10 13:36:04 -07007956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007957 case WINDOW_FREEZE_TIMEOUT: {
7958 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007959 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007960 int i = mWindows.size();
7961 while (i > 0) {
7962 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007963 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007964 if (w.mOrientationChanging) {
7965 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007966 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007967 }
7968 }
7969 performLayoutAndPlaceSurfacesLocked();
7970 }
7971 break;
7972 }
Romain Guy06882f82009-06-10 13:36:04 -07007973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007974 case HOLD_SCREEN_CHANGED: {
7975 Session oldHold;
7976 Session newHold;
7977 synchronized (mWindowMap) {
7978 oldHold = mLastReportedHold;
7979 newHold = (Session)msg.obj;
7980 mLastReportedHold = newHold;
7981 }
Romain Guy06882f82009-06-10 13:36:04 -07007982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007983 if (oldHold != newHold) {
7984 try {
7985 if (oldHold != null) {
7986 mBatteryStats.noteStopWakelock(oldHold.mUid,
7987 "window",
7988 BatteryStats.WAKE_TYPE_WINDOW);
7989 }
7990 if (newHold != null) {
7991 mBatteryStats.noteStartWakelock(newHold.mUid,
7992 "window",
7993 BatteryStats.WAKE_TYPE_WINDOW);
7994 }
7995 } catch (RemoteException e) {
7996 }
7997 }
7998 break;
7999 }
Romain Guy06882f82009-06-10 13:36:04 -07008000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 case APP_TRANSITION_TIMEOUT: {
8002 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008003 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008004 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008005 "*** APP TRANSITION TIMEOUT");
8006 mAppTransitionReady = true;
8007 mAppTransitionTimeout = true;
8008 performLayoutAndPlaceSurfacesLocked();
8009 }
8010 }
8011 break;
8012 }
Romain Guy06882f82009-06-10 13:36:04 -07008013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008014 case PERSIST_ANIMATION_SCALE: {
8015 Settings.System.putFloat(mContext.getContentResolver(),
8016 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8017 Settings.System.putFloat(mContext.getContentResolver(),
8018 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8019 break;
8020 }
Romain Guy06882f82009-06-10 13:36:04 -07008021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 case FORCE_GC: {
8023 synchronized(mWindowMap) {
8024 if (mAnimationPending) {
8025 // If we are animating, don't do the gc now but
8026 // delay a bit so we don't interrupt the animation.
8027 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8028 2000);
8029 return;
8030 }
8031 // If we are currently rotating the display, it will
8032 // schedule a new message when done.
8033 if (mDisplayFrozen) {
8034 return;
8035 }
8036 mFreezeGcPending = 0;
8037 }
8038 Runtime.getRuntime().gc();
8039 break;
8040 }
Romain Guy06882f82009-06-10 13:36:04 -07008041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008042 case ENABLE_SCREEN: {
8043 performEnableScreen();
8044 break;
8045 }
Romain Guy06882f82009-06-10 13:36:04 -07008046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 case APP_FREEZE_TIMEOUT: {
8048 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008049 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 int i = mAppTokens.size();
8051 while (i > 0) {
8052 i--;
8053 AppWindowToken tok = mAppTokens.get(i);
8054 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008055 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008056 unsetAppFreezingScreenLocked(tok, true, true);
8057 }
8058 }
8059 }
8060 break;
8061 }
Romain Guy06882f82009-06-10 13:36:04 -07008062
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008063 case SEND_NEW_CONFIGURATION: {
8064 removeMessages(SEND_NEW_CONFIGURATION);
8065 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008066 break;
8067 }
Romain Guy06882f82009-06-10 13:36:04 -07008068
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008069 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008070 if (mWindowsChanged) {
8071 synchronized (mWindowMap) {
8072 mWindowsChanged = false;
8073 }
8074 notifyWindowsChanged();
8075 }
8076 break;
8077 }
8078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008079 }
8080 }
8081 }
8082
8083 // -------------------------------------------------------------
8084 // IWindowManager API
8085 // -------------------------------------------------------------
8086
8087 public IWindowSession openSession(IInputMethodClient client,
8088 IInputContext inputContext) {
8089 if (client == null) throw new IllegalArgumentException("null client");
8090 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008091 Session session = new Session(client, inputContext);
8092 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008093 }
8094
8095 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8096 synchronized (mWindowMap) {
8097 // The focus for the client is the window immediately below
8098 // where we would place the input method window.
8099 int idx = findDesiredInputMethodWindowIndexLocked(false);
8100 WindowState imFocus;
8101 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008102 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 if (imFocus != null) {
8104 if (imFocus.mSession.mClient != null &&
8105 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8106 return true;
8107 }
8108 }
8109 }
8110 }
8111 return false;
8112 }
Romain Guy06882f82009-06-10 13:36:04 -07008113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008114 // -------------------------------------------------------------
8115 // Internals
8116 // -------------------------------------------------------------
8117
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008118 final WindowState windowForClientLocked(Session session, IWindow client,
8119 boolean throwOnError) {
8120 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 }
Romain Guy06882f82009-06-10 13:36:04 -07008122
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008123 final WindowState windowForClientLocked(Session session, IBinder client,
8124 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008126 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008127 TAG, "Looking up client " + client + ": " + win);
8128 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008129 RuntimeException ex = new IllegalArgumentException(
8130 "Requested window " + client + " does not exist");
8131 if (throwOnError) {
8132 throw ex;
8133 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008134 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008135 return null;
8136 }
8137 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008138 RuntimeException ex = new IllegalArgumentException(
8139 "Requested window " + client + " is in session " +
8140 win.mSession + ", not " + session);
8141 if (throwOnError) {
8142 throw ex;
8143 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008144 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 return null;
8146 }
8147
8148 return win;
8149 }
8150
Dianne Hackborna8f60182009-09-01 19:01:50 -07008151 final void rebuildAppWindowListLocked() {
8152 int NW = mWindows.size();
8153 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008154 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008155 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008156
Dianne Hackborna8f60182009-09-01 19:01:50 -07008157 // First remove all existing app windows.
8158 i=0;
8159 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008160 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008161 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008162 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008163 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008164 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008165 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008166 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008167 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008168 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008169 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8170 && lastWallpaper == i-1) {
8171 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008172 }
8173 i++;
8174 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008175
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008176 // The wallpaper window(s) typically live at the bottom of the stack,
8177 // so skip them before adding app tokens.
8178 lastWallpaper++;
8179 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008180
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008181 // First add all of the exiting app tokens... these are no longer
8182 // in the main app list, but still have windows shown. We put them
8183 // in the back because now that the animation is over we no longer
8184 // will care about them.
8185 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008186 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008187 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8188 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008189
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008190 // And add in the still active app tokens in Z order.
8191 NT = mAppTokens.size();
8192 for (int j=0; j<NT; j++) {
8193 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008194 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008195
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008196 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008197 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008198 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008199 + " windows but added " + i);
8200 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008201 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008203 private final void assignLayersLocked() {
8204 int N = mWindows.size();
8205 int curBaseLayer = 0;
8206 int curLayer = 0;
8207 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008209 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008210 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008211 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8212 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008213 curLayer += WINDOW_LAYER_MULTIPLIER;
8214 w.mLayer = curLayer;
8215 } else {
8216 curBaseLayer = curLayer = w.mBaseLayer;
8217 w.mLayer = curLayer;
8218 }
8219 if (w.mTargetAppToken != null) {
8220 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8221 } else if (w.mAppToken != null) {
8222 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8223 } else {
8224 w.mAnimLayer = w.mLayer;
8225 }
8226 if (w.mIsImWindow) {
8227 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008228 } else if (w.mIsWallpaper) {
8229 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008230 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008231 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008232 + w.mAnimLayer);
8233 //System.out.println(
8234 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8235 }
8236 }
8237
8238 private boolean mInLayout = false;
8239 private final void performLayoutAndPlaceSurfacesLocked() {
8240 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008241 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008242 throw new RuntimeException("Recursive call!");
8243 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008244 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008245 return;
8246 }
8247
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008248 if (mWaitingForConfig) {
8249 // Our configuration has changed (most likely rotation), but we
8250 // don't yet have the complete configuration to report to
8251 // applications. Don't do any window layout until we have it.
8252 return;
8253 }
8254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008255 boolean recoveringMemory = false;
8256 if (mForceRemoves != null) {
8257 recoveringMemory = true;
8258 // Wait a little it for things to settle down, and off we go.
8259 for (int i=0; i<mForceRemoves.size(); i++) {
8260 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008261 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008262 removeWindowInnerLocked(ws.mSession, ws);
8263 }
8264 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008265 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008266 Object tmp = new Object();
8267 synchronized (tmp) {
8268 try {
8269 tmp.wait(250);
8270 } catch (InterruptedException e) {
8271 }
8272 }
8273 }
Romain Guy06882f82009-06-10 13:36:04 -07008274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008275 mInLayout = true;
8276 try {
8277 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279 int i = mPendingRemove.size()-1;
8280 if (i >= 0) {
8281 while (i >= 0) {
8282 WindowState w = mPendingRemove.get(i);
8283 removeWindowInnerLocked(w.mSession, w);
8284 i--;
8285 }
8286 mPendingRemove.clear();
8287
8288 mInLayout = false;
8289 assignLayersLocked();
8290 mLayoutNeeded = true;
8291 performLayoutAndPlaceSurfacesLocked();
8292
8293 } else {
8294 mInLayout = false;
8295 if (mLayoutNeeded) {
8296 requestAnimationLocked(0);
8297 }
8298 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008299 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008300 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8301 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008302 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008303 } catch (RuntimeException e) {
8304 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008305 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008306 }
8307 }
8308
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008309 private final int performLayoutLockedInner() {
8310 if (!mLayoutNeeded) {
8311 return 0;
8312 }
8313
8314 mLayoutNeeded = false;
8315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316 final int dw = mDisplay.getWidth();
8317 final int dh = mDisplay.getHeight();
8318
8319 final int N = mWindows.size();
8320 int i;
8321
Joe Onorato8a9b2202010-02-26 18:56:32 -08008322 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008323 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8324
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008325 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008326
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008327 int seq = mLayoutSeq+1;
8328 if (seq < 0) seq = 0;
8329 mLayoutSeq = seq;
8330
8331 // First perform layout of any root windows (not attached
8332 // to another window).
8333 int topAttached = -1;
8334 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008335 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008337 // Don't do layout of a window if it is not visible, or
8338 // soon won't be visible, to avoid wasting time and funky
8339 // changes while a window is animating away.
8340 final AppWindowToken atoken = win.mAppToken;
8341 final boolean gone = win.mViewVisibility == View.GONE
8342 || !win.mRelayoutCalled
8343 || win.mRootToken.hidden
8344 || (atoken != null && atoken.hiddenRequested)
8345 || win.mAttachedHidden
8346 || win.mExiting || win.mDestroying;
8347
8348 if (!win.mLayoutAttached) {
8349 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8350 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8351 + " mLayoutAttached=" + win.mLayoutAttached);
8352 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8353 + win.mViewVisibility + " mRelayoutCalled="
8354 + win.mRelayoutCalled + " hidden="
8355 + win.mRootToken.hidden + " hiddenRequested="
8356 + (atoken != null && atoken.hiddenRequested)
8357 + " mAttachedHidden=" + win.mAttachedHidden);
8358 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008359
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008360 // If this view is GONE, then skip it -- keep the current
8361 // frame, and let the caller know so they can ignore it
8362 // if they want. (We do the normal layout for INVISIBLE
8363 // windows, since that means "perform layout as normal,
8364 // just don't display").
8365 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008366 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008367 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8368 win.mLayoutSeq = seq;
8369 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8370 + win.mFrame + " mContainingFrame="
8371 + win.mContainingFrame + " mDisplayFrame="
8372 + win.mDisplayFrame);
8373 } else {
8374 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008375 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008378
8379 // Now perform layout of attached windows, which usually
8380 // depend on the position of the window they are attached to.
8381 // XXX does not deal with windows that are attached to windows
8382 // that are themselves attached.
8383 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008384 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008385
8386 // If this view is GONE, then skip it -- keep the current
8387 // frame, and let the caller know so they can ignore it
8388 // if they want. (We do the normal layout for INVISIBLE
8389 // windows, since that means "perform layout as normal,
8390 // just don't display").
8391 if (win.mLayoutAttached) {
8392 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8393 + " mHaveFrame=" + win.mHaveFrame
8394 + " mViewVisibility=" + win.mViewVisibility
8395 + " mRelayoutCalled=" + win.mRelayoutCalled);
8396 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8397 || !win.mHaveFrame) {
8398 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8399 win.mLayoutSeq = seq;
8400 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8401 + win.mFrame + " mContainingFrame="
8402 + win.mContainingFrame + " mDisplayFrame="
8403 + win.mDisplayFrame);
8404 }
8405 }
8406 }
Jeff Brown349703e2010-06-22 01:27:15 -07008407
8408 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008409 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008410
8411 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008412 }
Romain Guy06882f82009-06-10 13:36:04 -07008413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 private final void performLayoutAndPlaceSurfacesLockedInner(
8415 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008416 if (mDisplay == null) {
8417 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8418 return;
8419 }
8420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008421 final long currentTime = SystemClock.uptimeMillis();
8422 final int dw = mDisplay.getWidth();
8423 final int dh = mDisplay.getHeight();
8424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008425 int i;
8426
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008427 if (mFocusMayChange) {
8428 mFocusMayChange = false;
8429 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8430 }
8431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008432 if (mFxSession == null) {
8433 mFxSession = new SurfaceSession();
8434 }
Romain Guy06882f82009-06-10 13:36:04 -07008435
Joe Onorato8a9b2202010-02-26 18:56:32 -08008436 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437
8438 // Initialize state of exiting tokens.
8439 for (i=mExitingTokens.size()-1; i>=0; i--) {
8440 mExitingTokens.get(i).hasVisible = false;
8441 }
8442
8443 // Initialize state of exiting applications.
8444 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8445 mExitingAppTokens.get(i).hasVisible = false;
8446 }
8447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008448 boolean orientationChangeComplete = true;
8449 Session holdScreen = null;
8450 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008451 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 boolean focusDisplayed = false;
8453 boolean animating = false;
8454
8455 Surface.openTransaction();
8456 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008457 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008458 int repeats = 0;
8459 int changes = 0;
8460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008461 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008462 repeats++;
8463 if (repeats > 6) {
8464 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8465 mLayoutNeeded = false;
8466 break;
8467 }
8468
8469 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8470 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8471 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8472 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8473 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8474 assignLayersLocked();
8475 mLayoutNeeded = true;
8476 }
8477 }
8478 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8479 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8480 if (updateOrientationFromAppTokensLocked()) {
8481 mLayoutNeeded = true;
8482 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8483 }
8484 }
8485 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8486 mLayoutNeeded = true;
8487 }
8488 }
8489
8490 // FIRST LOOP: Perform a layout, if needed.
8491 if (repeats < 4) {
8492 changes = performLayoutLockedInner();
8493 if (changes != 0) {
8494 continue;
8495 }
8496 } else {
8497 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8498 changes = 0;
8499 }
8500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 final int transactionSequence = ++mTransactionSequence;
8502
8503 // Update animations of all applications, including those
8504 // associated with exiting/removed apps
8505 boolean tokensAnimating = false;
8506 final int NAT = mAppTokens.size();
8507 for (i=0; i<NAT; i++) {
8508 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8509 tokensAnimating = true;
8510 }
8511 }
8512 final int NEAT = mExitingAppTokens.size();
8513 for (i=0; i<NEAT; i++) {
8514 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8515 tokensAnimating = true;
8516 }
8517 }
8518
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008519 // SECOND LOOP: Execute animations and update visibility of windows.
8520
Joe Onorato8a9b2202010-02-26 18:56:32 -08008521 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008522 + transactionSequence + " tokensAnimating="
8523 + tokensAnimating);
8524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008525 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526
8527 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008528 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008529 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530
8531 mPolicy.beginAnimationLw(dw, dh);
8532
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008533 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008536 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537
8538 final WindowManager.LayoutParams attrs = w.mAttrs;
8539
8540 if (w.mSurface != null) {
8541 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008542 if (w.commitFinishDrawingLocked(currentTime)) {
8543 if ((w.mAttrs.flags
8544 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008545 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008546 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008547 wallpaperMayChange = true;
8548 }
8549 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008550
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008551 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8553 animating = true;
8554 //w.dump(" ");
8555 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008556 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8557 wallpaperMayChange = true;
8558 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008559
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008560 if (mPolicy.doesForceHide(w, attrs)) {
8561 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008562 if (DEBUG_VISIBILITY) Slog.v(TAG,
8563 "Animation done that could impact force hide: "
8564 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008565 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008566 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008567 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8568 forceHiding = true;
8569 }
8570 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8571 boolean changed;
8572 if (forceHiding) {
8573 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008574 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8575 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008576 } else {
8577 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008578 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8579 "Now policy shown: " + w);
8580 if (changed) {
8581 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008582 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008583 // Assume we will need to animate. If
8584 // we don't (because the wallpaper will
8585 // stay with the lock screen), then we will
8586 // clean up later.
8587 Animation a = mPolicy.createForceHideEnterAnimation();
8588 if (a != null) {
8589 w.setAnimation(a);
8590 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008591 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008592 if (mCurrentFocus == null ||
8593 mCurrentFocus.mLayer < w.mLayer) {
8594 // We are showing on to of the current
8595 // focus, so re-evaluate focus to make
8596 // sure it is correct.
8597 mFocusMayChange = true;
8598 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008599 }
8600 }
8601 if (changed && (attrs.flags
8602 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8603 wallpaperMayChange = true;
8604 }
8605 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607 mPolicy.animatingWindowLw(w, attrs);
8608 }
8609
8610 final AppWindowToken atoken = w.mAppToken;
8611 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8612 if (atoken.lastTransactionSequence != transactionSequence) {
8613 atoken.lastTransactionSequence = transactionSequence;
8614 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8615 atoken.startingDisplayed = false;
8616 }
8617 if ((w.isOnScreen() || w.mAttrs.type
8618 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8619 && !w.mExiting && !w.mDestroying) {
8620 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008621 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008622 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008624 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008625 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 + " pv=" + w.mPolicyVisibility
8627 + " dp=" + w.mDrawPending
8628 + " cdp=" + w.mCommitDrawPending
8629 + " ah=" + w.mAttachedHidden
8630 + " th=" + atoken.hiddenRequested
8631 + " a=" + w.mAnimating);
8632 }
8633 }
8634 if (w != atoken.startingWindow) {
8635 if (!atoken.freezingScreen || !w.mAppFreezing) {
8636 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008637 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008639 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 "tokenMayBeDrawn: " + atoken
8641 + " freezingScreen=" + atoken.freezingScreen
8642 + " mAppFreezing=" + w.mAppFreezing);
8643 tokenMayBeDrawn = true;
8644 }
8645 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008646 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008647 atoken.startingDisplayed = true;
8648 }
8649 }
8650 } else if (w.mReadyToShow) {
8651 w.performShowLocked();
8652 }
8653 }
8654
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008655 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008656
8657 if (tokenMayBeDrawn) {
8658 // See if any windows have been drawn, so they (and others
8659 // associated with them) can now be shown.
8660 final int NT = mTokenList.size();
8661 for (i=0; i<NT; i++) {
8662 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8663 if (wtoken == null) {
8664 continue;
8665 }
8666 if (wtoken.freezingScreen) {
8667 int numInteresting = wtoken.numInterestingWindows;
8668 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008669 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008670 "allDrawn: " + wtoken
8671 + " interesting=" + numInteresting
8672 + " drawn=" + wtoken.numDrawnWindows);
8673 wtoken.showAllWindowsLocked();
8674 unsetAppFreezingScreenLocked(wtoken, false, true);
8675 orientationChangeComplete = true;
8676 }
8677 } else if (!wtoken.allDrawn) {
8678 int numInteresting = wtoken.numInterestingWindows;
8679 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008680 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 "allDrawn: " + wtoken
8682 + " interesting=" + numInteresting
8683 + " drawn=" + wtoken.numDrawnWindows);
8684 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008685 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686
8687 // We can now show all of the drawn windows!
8688 if (!mOpeningApps.contains(wtoken)) {
8689 wtoken.showAllWindowsLocked();
8690 }
8691 }
8692 }
8693 }
8694 }
8695
8696 // If we are ready to perform an app transition, check through
8697 // all of the app tokens to be shown and see if they are ready
8698 // to go.
8699 if (mAppTransitionReady) {
8700 int NN = mOpeningApps.size();
8701 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008702 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008703 "Checking " + NN + " opening apps (frozen="
8704 + mDisplayFrozen + " timeout="
8705 + mAppTransitionTimeout + ")...");
8706 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8707 // If the display isn't frozen, wait to do anything until
8708 // all of the apps are ready. Otherwise just go because
8709 // we'll unfreeze the display when everyone is ready.
8710 for (i=0; i<NN && goodToGo; i++) {
8711 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008712 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008713 "Check opening app" + wtoken + ": allDrawn="
8714 + wtoken.allDrawn + " startingDisplayed="
8715 + wtoken.startingDisplayed);
8716 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8717 && !wtoken.startingMoved) {
8718 goodToGo = false;
8719 }
8720 }
8721 }
8722 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008723 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 int transit = mNextAppTransition;
8725 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008726 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008727 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008728 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008729 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008730 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008731 mAppTransitionTimeout = false;
8732 mStartingIconInTransition = false;
8733 mSkipAppTransitionAnimation = false;
8734
8735 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8736
Dianne Hackborna8f60182009-09-01 19:01:50 -07008737 // If there are applications waiting to come to the
8738 // top of the stack, now is the time to move their windows.
8739 // (Note that we don't do apps going to the bottom
8740 // here -- we want to keep their windows in the old
8741 // Z-order until the animation completes.)
8742 if (mToTopApps.size() > 0) {
8743 NN = mAppTokens.size();
8744 for (i=0; i<NN; i++) {
8745 AppWindowToken wtoken = mAppTokens.get(i);
8746 if (wtoken.sendingToTop) {
8747 wtoken.sendingToTop = false;
8748 moveAppWindowsLocked(wtoken, NN, false);
8749 }
8750 }
8751 mToTopApps.clear();
8752 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008753
Dianne Hackborn25994b42009-09-04 14:21:19 -07008754 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008755
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008756 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008757 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008758
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008759 // The top-most window will supply the layout params,
8760 // and we will determine it below.
8761 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008762 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008763 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008764
Joe Onorato8a9b2202010-02-26 18:56:32 -08008765 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008766 "New wallpaper target=" + mWallpaperTarget
8767 + ", lower target=" + mLowerWallpaperTarget
8768 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008769 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008770 // Do a first pass through the tokens for two
8771 // things:
8772 // (1) Determine if both the closing and opening
8773 // app token sets are wallpaper targets, in which
8774 // case special animations are needed
8775 // (since the wallpaper needs to stay static
8776 // behind them).
8777 // (2) Find the layout params of the top-most
8778 // application window in the tokens, which is
8779 // what will control the animation theme.
8780 final int NC = mClosingApps.size();
8781 NN = NC + mOpeningApps.size();
8782 for (i=0; i<NN; i++) {
8783 AppWindowToken wtoken;
8784 int mode;
8785 if (i < NC) {
8786 wtoken = mClosingApps.get(i);
8787 mode = 1;
8788 } else {
8789 wtoken = mOpeningApps.get(i-NC);
8790 mode = 2;
8791 }
8792 if (mLowerWallpaperTarget != null) {
8793 if (mLowerWallpaperTarget.mAppToken == wtoken
8794 || mUpperWallpaperTarget.mAppToken == wtoken) {
8795 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008796 }
8797 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008798 if (wtoken.appFullscreen) {
8799 WindowState ws = wtoken.findMainWindow();
8800 if (ws != null) {
8801 // If this is a compatibility mode
8802 // window, we will always use its anim.
8803 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8804 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008805 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008806 bestAnimLayer = Integer.MAX_VALUE;
8807 } else if (ws.mLayer > bestAnimLayer) {
8808 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008809 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008810 bestAnimLayer = ws.mLayer;
8811 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008812 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008813 }
8814 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008815
Dianne Hackborn25994b42009-09-04 14:21:19 -07008816 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008817 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008818 "Wallpaper animation!");
8819 switch (transit) {
8820 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8821 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8822 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8823 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8824 break;
8825 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8826 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8827 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8828 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8829 break;
8830 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008831 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008832 "New transit: " + transit);
8833 } else if (oldWallpaper != null) {
8834 // We are transitioning from an activity with
8835 // a wallpaper to one without.
8836 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008837 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008838 "New transit away from wallpaper: " + transit);
8839 } else if (mWallpaperTarget != null) {
8840 // We are transitioning from an activity without
8841 // a wallpaper to now showing the wallpaper
8842 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008843 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008844 "New transit into wallpaper: " + transit);
8845 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008846
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008847 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8848 mLastEnterAnimToken = animToken;
8849 mLastEnterAnimParams = animLp;
8850 } else if (mLastEnterAnimParams != null) {
8851 animLp = mLastEnterAnimParams;
8852 mLastEnterAnimToken = null;
8853 mLastEnterAnimParams = null;
8854 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008855
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008856 // If all closing windows are obscured, then there is
8857 // no need to do an animation. This is the case, for
8858 // example, when this transition is being done behind
8859 // the lock screen.
8860 if (!mPolicy.allowAppAnimationsLw()) {
8861 animLp = null;
8862 }
8863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008864 NN = mOpeningApps.size();
8865 for (i=0; i<NN; i++) {
8866 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008867 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 "Now opening app" + wtoken);
8869 wtoken.reportedVisible = false;
8870 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008871 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008872 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008873 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008874 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 wtoken.showAllWindowsLocked();
8876 }
8877 NN = mClosingApps.size();
8878 for (i=0; i<NN; i++) {
8879 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008880 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008881 "Now closing app" + wtoken);
8882 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008883 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008884 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008886 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008887 // Force the allDrawn flag, because we want to start
8888 // this guy's animations regardless of whether it's
8889 // gotten drawn.
8890 wtoken.allDrawn = true;
8891 }
8892
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008893 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008895 mOpeningApps.clear();
8896 mClosingApps.clear();
8897
8898 // This has changed the visibility of windows, so perform
8899 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008900 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008902 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8903 assignLayersLocked();
8904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008905 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008906 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008907 }
8908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008909
Dianne Hackborn16064f92010-03-25 00:47:24 -07008910 int adjResult = 0;
8911
Dianne Hackborna8f60182009-09-01 19:01:50 -07008912 if (!animating && mAppTransitionRunning) {
8913 // We have finished the animation of an app transition. To do
8914 // this, we have delayed a lot of operations like showing and
8915 // hiding apps, moving apps in Z-order, etc. The app token list
8916 // reflects the correct Z-order, but the window list may now
8917 // be out of sync with it. So here we will just rebuild the
8918 // entire app window list. Fun!
8919 mAppTransitionRunning = false;
8920 // Clear information about apps that were moving.
8921 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008922
Dianne Hackborna8f60182009-09-01 19:01:50 -07008923 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008924 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008925 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008926 moveInputMethodWindowsIfNeededLocked(false);
8927 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008928 // Since the window list has been rebuilt, focus might
8929 // have to be recomputed since the actual order of windows
8930 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008931 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008932 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008933
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008934 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008935 // At this point, there was a window with a wallpaper that
8936 // was force hiding other windows behind it, but now it
8937 // is going away. This may be simple -- just animate
8938 // away the wallpaper and its window -- or it may be
8939 // hard -- the wallpaper now needs to be shown behind
8940 // something that was hidden.
8941 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008942 if (mLowerWallpaperTarget != null
8943 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008944 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008945 "wallpaperForceHiding changed with lower="
8946 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008947 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008948 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
8949 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
8950 if (mLowerWallpaperTarget.mAppToken.hidden) {
8951 // The lower target has become hidden before we
8952 // actually started the animation... let's completely
8953 // re-evaluate everything.
8954 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008955 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008956 }
8957 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07008958 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008959 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008960 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008961 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008962 + " NEW: " + mWallpaperTarget
8963 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008964 if (mLowerWallpaperTarget == null) {
8965 // Whoops, we don't need a special wallpaper animation.
8966 // Clear them out.
8967 forceHiding = false;
8968 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008969 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008970 if (w.mSurface != null) {
8971 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07008972 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008973 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008974 forceHiding = true;
8975 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8976 if (!w.mAnimating) {
8977 // We set the animation above so it
8978 // is not yet running.
8979 w.clearAnimation();
8980 }
8981 }
8982 }
8983 }
8984 }
8985 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008986
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008987 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008988 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008989 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07008990 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008991 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008992
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008993 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008994 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008995 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008996 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008997 assignLayersLocked();
8998 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008999 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009000 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009001 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009002 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009003
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009004 if (mFocusMayChange) {
9005 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009006 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009007 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009008 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009009 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009010 }
9011
9012 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009013 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009014 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009015
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009016 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9017 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009018
Jeff Browne33348b2010-07-15 23:54:05 -07009019 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009020 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009021
9022 // THIRD LOOP: Update the surfaces of all windows.
9023
9024 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9025
9026 boolean obscured = false;
9027 boolean blurring = false;
9028 boolean dimming = false;
9029 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009030 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009031 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009032
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009033 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009036 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009037
9038 boolean displayed = false;
9039 final WindowManager.LayoutParams attrs = w.mAttrs;
9040 final int attrFlags = attrs.flags;
9041
9042 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009043 // XXX NOTE: The logic here could be improved. We have
9044 // the decision about whether to resize a window separated
9045 // from whether to hide the surface. This can cause us to
9046 // resize a surface even if we are going to hide it. You
9047 // can see this by (1) holding device in landscape mode on
9048 // home screen; (2) tapping browser icon (device will rotate
9049 // to landscape; (3) tap home. The wallpaper will be resized
9050 // in step 2 but then immediately hidden, causing us to
9051 // have to resize and then redraw it again in step 3. It
9052 // would be nice to figure out how to avoid this, but it is
9053 // difficult because we do need to resize surfaces in some
9054 // cases while they are hidden such as when first showing a
9055 // window.
9056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009057 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009058 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009059 TAG, "Placing surface #" + i + " " + w.mSurface
9060 + ": new=" + w.mShownFrame + ", old="
9061 + w.mLastShownFrame);
9062
9063 boolean resize;
9064 int width, height;
9065 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9066 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9067 w.mLastRequestedHeight != w.mRequestedHeight;
9068 // for a scaled surface, we just want to use
9069 // the requested size.
9070 width = w.mRequestedWidth;
9071 height = w.mRequestedHeight;
9072 w.mLastRequestedWidth = width;
9073 w.mLastRequestedHeight = height;
9074 w.mLastShownFrame.set(w.mShownFrame);
9075 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009076 if (SHOW_TRANSACTIONS) logSurface(w,
9077 "POS " + w.mShownFrame.left
9078 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009079 w.mSurfaceX = w.mShownFrame.left;
9080 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009081 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9082 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009083 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 if (!recoveringMemory) {
9085 reclaimSomeSurfaceMemoryLocked(w, "position");
9086 }
9087 }
9088 } else {
9089 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9090 width = w.mShownFrame.width();
9091 height = w.mShownFrame.height();
9092 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009093 }
9094
9095 if (resize) {
9096 if (width < 1) width = 1;
9097 if (height < 1) height = 1;
9098 if (w.mSurface != null) {
9099 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009100 if (SHOW_TRANSACTIONS) logSurface(w,
9101 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009102 + w.mShownFrame.top + " SIZE "
9103 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009104 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009105 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009106 w.mSurfaceW = width;
9107 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009108 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009109 w.mSurfaceX = w.mShownFrame.left;
9110 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009111 w.mSurface.setPosition(w.mShownFrame.left,
9112 w.mShownFrame.top);
9113 } catch (RuntimeException e) {
9114 // If something goes wrong with the surface (such
9115 // as running out of memory), don't take down the
9116 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009117 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 + "size=(" + width + "x" + height
9119 + "), pos=(" + w.mShownFrame.left
9120 + "," + w.mShownFrame.top + ")", e);
9121 if (!recoveringMemory) {
9122 reclaimSomeSurfaceMemoryLocked(w, "size");
9123 }
9124 }
9125 }
9126 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009127 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009128 w.mContentInsetsChanged =
9129 !w.mLastContentInsets.equals(w.mContentInsets);
9130 w.mVisibleInsetsChanged =
9131 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009132 boolean configChanged =
9133 w.mConfiguration != mCurConfiguration
9134 && (w.mConfiguration == null
9135 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009136 if (DEBUG_CONFIGURATION && configChanged) {
9137 Slog.v(TAG, "Win " + w + " config changed: "
9138 + mCurConfiguration);
9139 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009140 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009141 + ": configChanged=" + configChanged
9142 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009143 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009144 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009145 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009146 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009147 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009148 w.mLastFrame.set(w.mFrame);
9149 w.mLastContentInsets.set(w.mContentInsets);
9150 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009151 // If the screen is currently frozen, then keep
9152 // it frozen until this window draws at its new
9153 // orientation.
9154 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009155 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009156 "Resizing while display frozen: " + w);
9157 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009158 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009159 mWindowsFreezingScreen = true;
9160 // XXX should probably keep timeout from
9161 // when we first froze the display.
9162 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9163 mH.sendMessageDelayed(mH.obtainMessage(
9164 H.WINDOW_FREEZE_TIMEOUT), 2000);
9165 }
9166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009167 // If the orientation is changing, then we need to
9168 // hold off on unfreezing the display until this
9169 // window has been redrawn; to do that, we need
9170 // to go through the process of getting informed
9171 // by the application when it has finished drawing.
9172 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009173 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 "Orientation start waiting for draw in "
9175 + w + ", surface " + w.mSurface);
9176 w.mDrawPending = true;
9177 w.mCommitDrawPending = false;
9178 w.mReadyToShow = false;
9179 if (w.mAppToken != null) {
9180 w.mAppToken.allDrawn = false;
9181 }
9182 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009183 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 "Resizing window " + w + " to " + w.mFrame);
9185 mResizingWindows.add(w);
9186 } else if (w.mOrientationChanging) {
9187 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009188 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009189 "Orientation not waiting for draw in "
9190 + w + ", surface " + w.mSurface);
9191 w.mOrientationChanging = false;
9192 }
9193 }
9194 }
9195
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009196 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009197 if (!w.mLastHidden) {
9198 //dump();
9199 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009200 if (SHOW_TRANSACTIONS) logSurface(w,
9201 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009202 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009203 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009204 try {
9205 w.mSurface.hide();
9206 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009207 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009208 }
9209 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009210 }
9211 // If we are waiting for this window to handle an
9212 // orientation change, well, it is hidden, so
9213 // doesn't really matter. Note that this does
9214 // introduce a potential glitch if the window
9215 // becomes unhidden before it has drawn for the
9216 // new orientation.
9217 if (w.mOrientationChanging) {
9218 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009219 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009220 "Orientation change skips hidden " + w);
9221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 } else if (w.mLastLayer != w.mAnimLayer
9223 || w.mLastAlpha != w.mShownAlpha
9224 || w.mLastDsDx != w.mDsDx
9225 || w.mLastDtDx != w.mDtDx
9226 || w.mLastDsDy != w.mDsDy
9227 || w.mLastDtDy != w.mDtDy
9228 || w.mLastHScale != w.mHScale
9229 || w.mLastVScale != w.mVScale
9230 || w.mLastHidden) {
9231 displayed = true;
9232 w.mLastAlpha = w.mShownAlpha;
9233 w.mLastLayer = w.mAnimLayer;
9234 w.mLastDsDx = w.mDsDx;
9235 w.mLastDtDx = w.mDtDx;
9236 w.mLastDsDy = w.mDsDy;
9237 w.mLastDtDy = w.mDtDy;
9238 w.mLastHScale = w.mHScale;
9239 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009240 if (SHOW_TRANSACTIONS) logSurface(w,
9241 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009242 + " matrix=[" + (w.mDsDx*w.mHScale)
9243 + "," + (w.mDtDx*w.mVScale)
9244 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009245 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009246 if (w.mSurface != null) {
9247 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009248 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009250 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009251 w.mSurface.setLayer(w.mAnimLayer);
9252 w.mSurface.setMatrix(
9253 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9254 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9255 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009256 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 if (!recoveringMemory) {
9258 reclaimSomeSurfaceMemoryLocked(w, "update");
9259 }
9260 }
9261 }
9262
9263 if (w.mLastHidden && !w.mDrawPending
9264 && !w.mCommitDrawPending
9265 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009266 if (SHOW_TRANSACTIONS) logSurface(w,
9267 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009268 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009269 + " during relayout");
9270 if (showSurfaceRobustlyLocked(w)) {
9271 w.mHasDrawn = true;
9272 w.mLastHidden = false;
9273 } else {
9274 w.mOrientationChanging = false;
9275 }
9276 }
9277 if (w.mSurface != null) {
9278 w.mToken.hasVisible = true;
9279 }
9280 } else {
9281 displayed = true;
9282 }
9283
9284 if (displayed) {
9285 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009286 if (attrs.width == LayoutParams.MATCH_PARENT
9287 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009288 covered = true;
9289 }
9290 }
9291 if (w.mOrientationChanging) {
9292 if (w.mDrawPending || w.mCommitDrawPending) {
9293 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009294 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 "Orientation continue waiting for draw in " + w);
9296 } else {
9297 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009298 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009299 "Orientation change complete in " + w);
9300 }
9301 }
9302 w.mToken.hasVisible = true;
9303 }
9304 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009305 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009306 "Orientation change skips hidden " + w);
9307 w.mOrientationChanging = false;
9308 }
9309
9310 final boolean canBeSeen = w.isDisplayedLw();
9311
9312 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9313 focusDisplayed = true;
9314 }
9315
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009316 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009318 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009319 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009320 if (w.mSurface != null) {
9321 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9322 holdScreen = w.mSession;
9323 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009324 if (!syswin && w.mAttrs.screenBrightness >= 0
9325 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009326 screenBrightness = w.mAttrs.screenBrightness;
9327 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009328 if (!syswin && w.mAttrs.buttonBrightness >= 0
9329 && buttonBrightness < 0) {
9330 buttonBrightness = w.mAttrs.buttonBrightness;
9331 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009332 if (canBeSeen
9333 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9334 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9335 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009336 syswin = true;
9337 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009338 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009339
Dianne Hackborn25994b42009-09-04 14:21:19 -07009340 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9341 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 // This window completely covers everything behind it,
9343 // so we want to leave all of them as unblurred (for
9344 // performance reasons).
9345 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009346 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009347 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009348 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009349 obscured = true;
9350 if (mBackgroundFillerSurface == null) {
9351 try {
9352 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009353 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009354 0, dw, dh,
9355 PixelFormat.OPAQUE,
9356 Surface.FX_SURFACE_NORMAL);
9357 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009358 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009359 }
9360 }
9361 try {
9362 mBackgroundFillerSurface.setPosition(0, 0);
9363 mBackgroundFillerSurface.setSize(dw, dh);
9364 // Using the same layer as Dim because they will never be shown at the
9365 // same time.
9366 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9367 mBackgroundFillerSurface.show();
9368 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009369 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009370 }
9371 backgroundFillerShown = true;
9372 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009373 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009374 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009375 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009376 + ": blurring=" + blurring
9377 + " obscured=" + obscured
9378 + " displayed=" + displayed);
9379 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9380 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009381 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009382 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009383 if (mDimAnimator == null) {
9384 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009385 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009386 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009387 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009389 }
9390 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9391 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009392 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009394 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009395 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009396 + mBlurSurface + ": CREATE");
9397 try {
Romain Guy06882f82009-06-10 13:36:04 -07009398 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009399 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009400 -1, 16, 16,
9401 PixelFormat.OPAQUE,
9402 Surface.FX_SURFACE_BLUR);
9403 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009404 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009405 }
9406 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009408 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9409 + mBlurSurface + ": pos=(0,0) (" +
9410 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 mBlurSurface.setPosition(0, 0);
9412 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009413 mBlurSurface.setLayer(w.mAnimLayer-2);
9414 if (!mBlurShown) {
9415 try {
9416 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9417 + mBlurSurface + ": SHOW");
9418 mBlurSurface.show();
9419 } catch (RuntimeException e) {
9420 Slog.w(TAG, "Failure showing blur surface", e);
9421 }
9422 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009423 }
9424 }
9425 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 }
9427 }
9428 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009429
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009430 if (obscuredChanged && mWallpaperTarget == w) {
9431 // This is the wallpaper target and its obscured state
9432 // changed... make sure the current wallaper's visibility
9433 // has been updated accordingly.
9434 updateWallpaperVisibilityLocked();
9435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009436 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009437
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009438 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9439 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009440 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009441 try {
9442 mBackgroundFillerSurface.hide();
9443 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009444 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009445 }
9446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009448 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009449 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9450 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009451 }
Romain Guy06882f82009-06-10 13:36:04 -07009452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009453 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009454 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009455 + ": HIDE");
9456 try {
9457 mBlurSurface.hide();
9458 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009459 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009460 }
9461 mBlurShown = false;
9462 }
9463
Joe Onorato8a9b2202010-02-26 18:56:32 -08009464 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009465 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009466 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009467 }
9468
Jeff Browne33348b2010-07-15 23:54:05 -07009469 mInputMonitor.updateInputWindowsLw();
9470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009471 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009472
Joe Onorato8a9b2202010-02-26 18:56:32 -08009473 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 "With display frozen, orientationChangeComplete="
9475 + orientationChangeComplete);
9476 if (orientationChangeComplete) {
9477 if (mWindowsFreezingScreen) {
9478 mWindowsFreezingScreen = false;
9479 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9480 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009481 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009482 }
Romain Guy06882f82009-06-10 13:36:04 -07009483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009484 i = mResizingWindows.size();
9485 if (i > 0) {
9486 do {
9487 i--;
9488 WindowState win = mResizingWindows.get(i);
9489 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009490 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9491 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009492 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009493 boolean configChanged =
9494 win.mConfiguration != mCurConfiguration
9495 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009496 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9497 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9498 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009499 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009500 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009501 + " / " + mCurConfiguration + " / 0x"
9502 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009503 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009504 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 win.mClient.resized(win.mFrame.width(),
9506 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009507 win.mLastVisibleInsets, win.mDrawPending,
9508 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 win.mContentInsetsChanged = false;
9510 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009511 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009512 } catch (RemoteException e) {
9513 win.mOrientationChanging = false;
9514 }
9515 } while (i > 0);
9516 mResizingWindows.clear();
9517 }
Romain Guy06882f82009-06-10 13:36:04 -07009518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009520 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009521 i = mDestroySurface.size();
9522 if (i > 0) {
9523 do {
9524 i--;
9525 WindowState win = mDestroySurface.get(i);
9526 win.mDestroying = false;
9527 if (mInputMethodWindow == win) {
9528 mInputMethodWindow = null;
9529 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009530 if (win == mWallpaperTarget) {
9531 wallpaperDestroyed = true;
9532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009533 win.destroySurfaceLocked();
9534 } while (i > 0);
9535 mDestroySurface.clear();
9536 }
9537
9538 // Time to remove any exiting tokens?
9539 for (i=mExitingTokens.size()-1; i>=0; i--) {
9540 WindowToken token = mExitingTokens.get(i);
9541 if (!token.hasVisible) {
9542 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009543 if (token.windowType == TYPE_WALLPAPER) {
9544 mWallpaperTokens.remove(token);
9545 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009546 }
9547 }
9548
9549 // Time to remove any exiting applications?
9550 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9551 AppWindowToken token = mExitingAppTokens.get(i);
9552 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009553 // Make sure there is no animation running on this token,
9554 // so any windows associated with it will be removed as
9555 // soon as their animations are complete
9556 token.animation = null;
9557 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 mAppTokens.remove(token);
9559 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009560 if (mLastEnterAnimToken == token) {
9561 mLastEnterAnimToken = null;
9562 mLastEnterAnimParams = null;
9563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009564 }
9565 }
9566
Dianne Hackborna8f60182009-09-01 19:01:50 -07009567 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009568
Dianne Hackborna8f60182009-09-01 19:01:50 -07009569 if (!animating && mAppTransitionRunning) {
9570 // We have finished the animation of an app transition. To do
9571 // this, we have delayed a lot of operations like showing and
9572 // hiding apps, moving apps in Z-order, etc. The app token list
9573 // reflects the correct Z-order, but the window list may now
9574 // be out of sync with it. So here we will just rebuild the
9575 // entire app window list. Fun!
9576 mAppTransitionRunning = false;
9577 needRelayout = true;
9578 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009579 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009580 // Clear information about apps that were moving.
9581 mToBottomApps.clear();
9582 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009584 if (focusDisplayed) {
9585 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9586 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009587 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009588 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009589 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009590 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009591 requestAnimationLocked(0);
9592 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9594 }
Jeff Browneb857f12010-07-16 10:06:33 -07009595
Jeff Browne33348b2010-07-15 23:54:05 -07009596 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -07009597
Jeff Brown8e03b752010-06-13 19:16:55 -07009598 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009599 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9600 mPowerManager.setScreenBrightnessOverride(-1);
9601 } else {
9602 mPowerManager.setScreenBrightnessOverride((int)
9603 (screenBrightness * Power.BRIGHTNESS_ON));
9604 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009605 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9606 mPowerManager.setButtonBrightnessOverride(-1);
9607 } else {
9608 mPowerManager.setButtonBrightnessOverride((int)
9609 (buttonBrightness * Power.BRIGHTNESS_ON));
9610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009611 if (holdScreen != mHoldingScreenOn) {
9612 mHoldingScreenOn = holdScreen;
9613 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9614 mH.sendMessage(m);
9615 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009616
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009617 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009618 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009619 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9620 LocalPowerManager.BUTTON_EVENT, true);
9621 mTurnOnScreen = false;
9622 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009623
9624 // Check to see if we are now in a state where the screen should
9625 // be enabled, because the window obscured flags have changed.
9626 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009627 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07009628
9629 /**
9630 * Must be called with the main window manager lock held.
9631 */
9632 void setHoldScreenLocked(boolean holding) {
9633 boolean state = mHoldingScreenWakeLock.isHeld();
9634 if (holding != state) {
9635 if (holding) {
9636 mHoldingScreenWakeLock.acquire();
9637 } else {
9638 mPolicy.screenOnStoppedLw();
9639 mHoldingScreenWakeLock.release();
9640 }
9641 }
9642 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009643
9644 void requestAnimationLocked(long delay) {
9645 if (!mAnimationPending) {
9646 mAnimationPending = true;
9647 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9648 }
9649 }
Romain Guy06882f82009-06-10 13:36:04 -07009650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651 /**
9652 * Have the surface flinger show a surface, robustly dealing with
9653 * error conditions. In particular, if there is not enough memory
9654 * to show the surface, then we will try to get rid of other surfaces
9655 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009656 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009657 * @return Returns true if the surface was successfully shown.
9658 */
9659 boolean showSurfaceRobustlyLocked(WindowState win) {
9660 try {
9661 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009662 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009663 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009664 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009665 if (DEBUG_VISIBILITY) Slog.v(TAG,
9666 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009667 win.mTurnOnScreen = false;
9668 mTurnOnScreen = true;
9669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009670 }
9671 return true;
9672 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009673 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009674 }
Romain Guy06882f82009-06-10 13:36:04 -07009675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009676 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009678 return false;
9679 }
Romain Guy06882f82009-06-10 13:36:04 -07009680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009681 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9682 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009683
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009684 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009687 if (mForceRemoves == null) {
9688 mForceRemoves = new ArrayList<WindowState>();
9689 }
Romain Guy06882f82009-06-10 13:36:04 -07009690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009691 long callingIdentity = Binder.clearCallingIdentity();
9692 try {
9693 // There was some problem... first, do a sanity check of the
9694 // window list to make sure we haven't left any dangling surfaces
9695 // around.
9696 int N = mWindows.size();
9697 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009698 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009699 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009700 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009701 if (ws.mSurface != null) {
9702 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009703 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009704 + ws + " surface=" + ws.mSurface
9705 + " token=" + win.mToken
9706 + " pid=" + ws.mSession.mPid
9707 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009708 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009709 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 ws.mSurface = null;
9711 mForceRemoves.add(ws);
9712 i--;
9713 N--;
9714 leakedSurface = true;
9715 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009716 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009717 + ws + " surface=" + ws.mSurface
9718 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009719 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009720 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009721 ws.mSurface = null;
9722 leakedSurface = true;
9723 }
9724 }
9725 }
Romain Guy06882f82009-06-10 13:36:04 -07009726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009727 boolean killedApps = false;
9728 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009729 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009730 SparseIntArray pidCandidates = new SparseIntArray();
9731 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009732 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009733 if (ws.mSurface != null) {
9734 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9735 }
9736 }
9737 if (pidCandidates.size() > 0) {
9738 int[] pids = new int[pidCandidates.size()];
9739 for (int i=0; i<pids.length; i++) {
9740 pids[i] = pidCandidates.keyAt(i);
9741 }
9742 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009743 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009744 killedApps = true;
9745 }
9746 } catch (RemoteException e) {
9747 }
9748 }
9749 }
Romain Guy06882f82009-06-10 13:36:04 -07009750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009751 if (leakedSurface || killedApps) {
9752 // We managed to reclaim some memory, so get rid of the trouble
9753 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009754 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009756 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009757 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 win.mSurface = null;
9759 }
Romain Guy06882f82009-06-10 13:36:04 -07009760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009761 try {
9762 win.mClient.dispatchGetNewSurface();
9763 } catch (RemoteException e) {
9764 }
9765 }
9766 } finally {
9767 Binder.restoreCallingIdentity(callingIdentity);
9768 }
9769 }
Romain Guy06882f82009-06-10 13:36:04 -07009770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009771 private boolean updateFocusedWindowLocked(int mode) {
9772 WindowState newFocus = computeFocusedWindowLocked();
9773 if (mCurrentFocus != newFocus) {
9774 // This check makes sure that we don't already have the focus
9775 // change message pending.
9776 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9777 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009778 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009779 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9780 final WindowState oldFocus = mCurrentFocus;
9781 mCurrentFocus = newFocus;
9782 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009784 final WindowState imWindow = mInputMethodWindow;
9785 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009786 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009788 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9789 mLayoutNeeded = true;
9790 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9792 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009793 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9794 // Client will do the layout, but we need to assign layers
9795 // for handleNewWindowLocked() below.
9796 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009797 }
9798 }
Jeff Brown349703e2010-06-22 01:27:15 -07009799
9800 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9801 // If we defer assigning layers, then the caller is responsible for
9802 // doing this part.
9803 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009804 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 return true;
9806 }
9807 return false;
9808 }
Jeff Brown349703e2010-06-22 01:27:15 -07009809
9810 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009811 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009812 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813
9814 private WindowState computeFocusedWindowLocked() {
9815 WindowState result = null;
9816 WindowState win;
9817
9818 int i = mWindows.size() - 1;
9819 int nextAppIndex = mAppTokens.size()-1;
9820 WindowToken nextApp = nextAppIndex >= 0
9821 ? mAppTokens.get(nextAppIndex) : null;
9822
9823 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009824 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009825
Joe Onorato8a9b2202010-02-26 18:56:32 -08009826 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 TAG, "Looking for focus: " + i
9828 + " = " + win
9829 + ", flags=" + win.mAttrs.flags
9830 + ", canReceive=" + win.canReceiveKeys());
9831
9832 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009834 // If this window's application has been removed, just skip it.
9835 if (thisApp != null && thisApp.removed) {
9836 i--;
9837 continue;
9838 }
Romain Guy06882f82009-06-10 13:36:04 -07009839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009840 // If there is a focused app, don't allow focus to go to any
9841 // windows below it. If this is an application window, step
9842 // through the app tokens until we find its app.
9843 if (thisApp != null && nextApp != null && thisApp != nextApp
9844 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9845 int origAppIndex = nextAppIndex;
9846 while (nextAppIndex > 0) {
9847 if (nextApp == mFocusedApp) {
9848 // Whoops, we are below the focused app... no focus
9849 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009850 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 TAG, "Reached focused app: " + mFocusedApp);
9852 return null;
9853 }
9854 nextAppIndex--;
9855 nextApp = mAppTokens.get(nextAppIndex);
9856 if (nextApp == thisApp) {
9857 break;
9858 }
9859 }
9860 if (thisApp != nextApp) {
9861 // Uh oh, the app token doesn't exist! This shouldn't
9862 // happen, but if it does we can get totally hosed...
9863 // so restart at the original app.
9864 nextAppIndex = origAppIndex;
9865 nextApp = mAppTokens.get(nextAppIndex);
9866 }
9867 }
9868
9869 // Dispatch to this window if it is wants key events.
9870 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009871 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 TAG, "Found focus @ " + i + " = " + win);
9873 result = win;
9874 break;
9875 }
9876
9877 i--;
9878 }
9879
9880 return result;
9881 }
9882
9883 private void startFreezingDisplayLocked() {
9884 if (mDisplayFrozen) {
9885 return;
9886 }
Romain Guy06882f82009-06-10 13:36:04 -07009887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009888 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009890 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009891 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 if (mFreezeGcPending != 0) {
9893 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009894 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009895 mH.removeMessages(H.FORCE_GC);
9896 Runtime.getRuntime().gc();
9897 mFreezeGcPending = now;
9898 }
9899 } else {
9900 mFreezeGcPending = now;
9901 }
Romain Guy06882f82009-06-10 13:36:04 -07009902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009903 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009904
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009905 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009906
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009907 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9908 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009909 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009910 mAppTransitionReady = true;
9911 }
Romain Guy06882f82009-06-10 13:36:04 -07009912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009913 if (PROFILE_ORIENTATION) {
9914 File file = new File("/data/system/frozen");
9915 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9916 }
9917 Surface.freezeDisplay(0);
9918 }
Romain Guy06882f82009-06-10 13:36:04 -07009919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009920 private void stopFreezingDisplayLocked() {
9921 if (!mDisplayFrozen) {
9922 return;
9923 }
Romain Guy06882f82009-06-10 13:36:04 -07009924
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009925 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9926 return;
9927 }
9928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 mDisplayFrozen = false;
9930 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9931 if (PROFILE_ORIENTATION) {
9932 Debug.stopMethodTracing();
9933 }
9934 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009935
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009936 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937
Christopher Tateb696aee2010-04-02 19:08:30 -07009938 // While the display is frozen we don't re-compute the orientation
9939 // to avoid inconsistent states. However, something interesting
9940 // could have actually changed during that time so re-evaluate it
9941 // now to catch that.
9942 if (updateOrientationFromAppTokensLocked()) {
9943 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9944 }
9945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009946 // A little kludge: a lot could have happened while the
9947 // display was frozen, so now that we are coming back we
9948 // do a gc so that any remote references the system
9949 // processes holds on others can be released if they are
9950 // no longer needed.
9951 mH.removeMessages(H.FORCE_GC);
9952 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9953 2000);
Romain Guy06882f82009-06-10 13:36:04 -07009954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009955 mScreenFrozenLock.release();
9956 }
Romain Guy06882f82009-06-10 13:36:04 -07009957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009958 @Override
9959 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
9960 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
9961 != PackageManager.PERMISSION_GRANTED) {
9962 pw.println("Permission Denial: can't dump WindowManager from from pid="
9963 + Binder.getCallingPid()
9964 + ", uid=" + Binder.getCallingUid());
9965 return;
9966 }
Romain Guy06882f82009-06-10 13:36:04 -07009967
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009968 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -08009969 pw.println(" ");
9970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009971 synchronized(mWindowMap) {
9972 pw.println("Current Window Manager state:");
9973 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009974 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009975 pw.print(" Window #"); pw.print(i); pw.print(' ');
9976 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009977 w.dump(pw, " ");
9978 }
9979 if (mInputMethodDialogs.size() > 0) {
9980 pw.println(" ");
9981 pw.println(" Input method dialogs:");
9982 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
9983 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009984 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009985 }
9986 }
9987 if (mPendingRemove.size() > 0) {
9988 pw.println(" ");
9989 pw.println(" Remove pending for:");
9990 for (int i=mPendingRemove.size()-1; i>=0; i--) {
9991 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009992 pw.print(" Remove #"); pw.print(i); pw.print(' ');
9993 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009994 w.dump(pw, " ");
9995 }
9996 }
9997 if (mForceRemoves != null && mForceRemoves.size() > 0) {
9998 pw.println(" ");
9999 pw.println(" Windows force removing:");
10000 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10001 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010002 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10003 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 w.dump(pw, " ");
10005 }
10006 }
10007 if (mDestroySurface.size() > 0) {
10008 pw.println(" ");
10009 pw.println(" Windows waiting to destroy their surface:");
10010 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10011 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010012 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10013 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010014 w.dump(pw, " ");
10015 }
10016 }
10017 if (mLosingFocus.size() > 0) {
10018 pw.println(" ");
10019 pw.println(" Windows losing focus:");
10020 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10021 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010022 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10023 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010024 w.dump(pw, " ");
10025 }
10026 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010027 if (mResizingWindows.size() > 0) {
10028 pw.println(" ");
10029 pw.println(" Windows waiting to resize:");
10030 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10031 WindowState w = mResizingWindows.get(i);
10032 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10033 pw.print(w); pw.println(":");
10034 w.dump(pw, " ");
10035 }
10036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010037 if (mSessions.size() > 0) {
10038 pw.println(" ");
10039 pw.println(" All active sessions:");
10040 Iterator<Session> it = mSessions.iterator();
10041 while (it.hasNext()) {
10042 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010043 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010044 s.dump(pw, " ");
10045 }
10046 }
10047 if (mTokenMap.size() > 0) {
10048 pw.println(" ");
10049 pw.println(" All tokens:");
10050 Iterator<WindowToken> it = mTokenMap.values().iterator();
10051 while (it.hasNext()) {
10052 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010053 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 token.dump(pw, " ");
10055 }
10056 }
10057 if (mTokenList.size() > 0) {
10058 pw.println(" ");
10059 pw.println(" Window token list:");
10060 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010061 pw.print(" #"); pw.print(i); pw.print(": ");
10062 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 }
10064 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010065 if (mWallpaperTokens.size() > 0) {
10066 pw.println(" ");
10067 pw.println(" Wallpaper tokens:");
10068 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10069 WindowToken token = mWallpaperTokens.get(i);
10070 pw.print(" Wallpaper #"); pw.print(i);
10071 pw.print(' '); pw.print(token); pw.println(':');
10072 token.dump(pw, " ");
10073 }
10074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075 if (mAppTokens.size() > 0) {
10076 pw.println(" ");
10077 pw.println(" Application tokens in Z order:");
10078 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010079 pw.print(" App #"); pw.print(i); pw.print(": ");
10080 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 }
10082 }
10083 if (mFinishedStarting.size() > 0) {
10084 pw.println(" ");
10085 pw.println(" Finishing start of application tokens:");
10086 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10087 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010088 pw.print(" Finished Starting #"); pw.print(i);
10089 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010090 token.dump(pw, " ");
10091 }
10092 }
10093 if (mExitingTokens.size() > 0) {
10094 pw.println(" ");
10095 pw.println(" Exiting tokens:");
10096 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10097 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010098 pw.print(" Exiting #"); pw.print(i);
10099 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010100 token.dump(pw, " ");
10101 }
10102 }
10103 if (mExitingAppTokens.size() > 0) {
10104 pw.println(" ");
10105 pw.println(" Exiting application tokens:");
10106 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10107 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010108 pw.print(" Exiting App #"); pw.print(i);
10109 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010110 token.dump(pw, " ");
10111 }
10112 }
10113 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010114 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10115 pw.print(" mLastFocus="); pw.println(mLastFocus);
10116 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10117 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10118 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010119 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010120 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10121 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10122 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10123 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010124 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10125 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10126 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010127 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10128 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10129 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10130 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010131 if (mDimAnimator != null) {
10132 mDimAnimator.printTo(pw);
10133 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010134 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010135 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010136 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010137 pw.print(mInputMethodAnimLayerAdjustment);
10138 pw.print(" mWallpaperAnimLayerAdjustment=");
10139 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010140 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10141 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010142 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10143 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010144 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10145 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010146 pw.print(" mRotation="); pw.print(mRotation);
10147 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10148 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10149 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10150 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10151 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10152 pw.print(" mNextAppTransition=0x");
10153 pw.print(Integer.toHexString(mNextAppTransition));
10154 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010155 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010156 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010157 if (mNextAppTransitionPackage != null) {
10158 pw.print(" mNextAppTransitionPackage=");
10159 pw.print(mNextAppTransitionPackage);
10160 pw.print(", mNextAppTransitionEnter=0x");
10161 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10162 pw.print(", mNextAppTransitionExit=0x");
10163 pw.print(Integer.toHexString(mNextAppTransitionExit));
10164 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010165 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10166 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010167 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10168 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10169 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10170 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010171 if (mOpeningApps.size() > 0) {
10172 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10173 }
10174 if (mClosingApps.size() > 0) {
10175 pw.print(" mClosingApps="); pw.println(mClosingApps);
10176 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010177 if (mToTopApps.size() > 0) {
10178 pw.print(" mToTopApps="); pw.println(mToTopApps);
10179 }
10180 if (mToBottomApps.size() > 0) {
10181 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10182 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010183 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10184 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010185 }
10186 }
10187
Jeff Brown349703e2010-06-22 01:27:15 -070010188 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010189 public void monitor() {
10190 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010191 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010192 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010193
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010194 /**
10195 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010196 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010197 */
10198 private static class DimAnimator {
10199 Surface mDimSurface;
10200 boolean mDimShown = false;
10201 float mDimCurrentAlpha;
10202 float mDimTargetAlpha;
10203 float mDimDeltaPerMs;
10204 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010205
10206 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010207
10208 DimAnimator (SurfaceSession session) {
10209 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010210 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010211 + mDimSurface + ": CREATE");
10212 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010213 mDimSurface = new Surface(session, 0,
10214 "DimSurface",
10215 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010216 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010217 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010218 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010219 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010220 }
10221 }
10222 }
10223
10224 /**
10225 * Show the dim surface.
10226 */
10227 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010228 if (!mDimShown) {
10229 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10230 dw + "x" + dh + ")");
10231 mDimShown = true;
10232 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010233 mLastDimWidth = dw;
10234 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010235 mDimSurface.setPosition(0, 0);
10236 mDimSurface.setSize(dw, dh);
10237 mDimSurface.show();
10238 } catch (RuntimeException e) {
10239 Slog.w(TAG, "Failure showing dim surface", e);
10240 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010241 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10242 mLastDimWidth = dw;
10243 mLastDimHeight = dh;
10244 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010245 }
10246 }
10247
10248 /**
10249 * Set's the dim surface's layer and update dim parameters that will be used in
10250 * {@link updateSurface} after all windows are examined.
10251 */
10252 void updateParameters(WindowState w, long currentTime) {
10253 mDimSurface.setLayer(w.mAnimLayer-1);
10254
10255 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010256 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010257 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010258 if (mDimTargetAlpha != target) {
10259 // If the desired dim level has changed, then
10260 // start an animation to it.
10261 mLastDimAnimTime = currentTime;
10262 long duration = (w.mAnimating && w.mAnimation != null)
10263 ? w.mAnimation.computeDurationHint()
10264 : DEFAULT_DIM_DURATION;
10265 if (target > mDimTargetAlpha) {
10266 // This is happening behind the activity UI,
10267 // so we can make it run a little longer to
10268 // give a stronger impression without disrupting
10269 // the user.
10270 duration *= DIM_DURATION_MULTIPLIER;
10271 }
10272 if (duration < 1) {
10273 // Don't divide by zero
10274 duration = 1;
10275 }
10276 mDimTargetAlpha = target;
10277 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10278 }
10279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010280
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010281 /**
10282 * Updating the surface's alpha. Returns true if the animation continues, or returns
10283 * false when the animation is finished and the dim surface is hidden.
10284 */
10285 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10286 if (!dimming) {
10287 if (mDimTargetAlpha != 0) {
10288 mLastDimAnimTime = currentTime;
10289 mDimTargetAlpha = 0;
10290 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10291 }
10292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010293
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010294 boolean animating = false;
10295 if (mLastDimAnimTime != 0) {
10296 mDimCurrentAlpha += mDimDeltaPerMs
10297 * (currentTime-mLastDimAnimTime);
10298 boolean more = true;
10299 if (displayFrozen) {
10300 // If the display is frozen, there is no reason to animate.
10301 more = false;
10302 } else if (mDimDeltaPerMs > 0) {
10303 if (mDimCurrentAlpha > mDimTargetAlpha) {
10304 more = false;
10305 }
10306 } else if (mDimDeltaPerMs < 0) {
10307 if (mDimCurrentAlpha < mDimTargetAlpha) {
10308 more = false;
10309 }
10310 } else {
10311 more = false;
10312 }
10313
10314 // Do we need to continue animating?
10315 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010316 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010317 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10318 mLastDimAnimTime = currentTime;
10319 mDimSurface.setAlpha(mDimCurrentAlpha);
10320 animating = true;
10321 } else {
10322 mDimCurrentAlpha = mDimTargetAlpha;
10323 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010324 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010325 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10326 mDimSurface.setAlpha(mDimCurrentAlpha);
10327 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010328 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010329 + ": HIDE");
10330 try {
10331 mDimSurface.hide();
10332 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010333 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010334 }
10335 mDimShown = false;
10336 }
10337 }
10338 }
10339 return animating;
10340 }
10341
10342 public void printTo(PrintWriter pw) {
10343 pw.print(" mDimShown="); pw.print(mDimShown);
10344 pw.print(" current="); pw.print(mDimCurrentAlpha);
10345 pw.print(" target="); pw.print(mDimTargetAlpha);
10346 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10347 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10348 }
10349 }
10350
10351 /**
10352 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10353 * This is used for opening/closing transition for apps in compatible mode.
10354 */
10355 private static class FadeInOutAnimation extends Animation {
10356 int mWidth;
10357 boolean mFadeIn;
10358
10359 public FadeInOutAnimation(boolean fadeIn) {
10360 setInterpolator(new AccelerateInterpolator());
10361 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10362 mFadeIn = fadeIn;
10363 }
10364
10365 @Override
10366 protected void applyTransformation(float interpolatedTime, Transformation t) {
10367 float x = interpolatedTime;
10368 if (!mFadeIn) {
10369 x = 1.0f - x; // reverse the interpolation for fade out
10370 }
10371 if (x < 0.5) {
10372 // move the window out of the screen.
10373 t.getMatrix().setTranslate(mWidth, 0);
10374 } else {
10375 t.getMatrix().setTranslate(0, 0);// show
10376 t.setAlpha((x - 0.5f) * 2);
10377 }
10378 }
10379
10380 @Override
10381 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10382 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10383 mWidth = width;
10384 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010385
10386 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010387 public int getZAdjustment() {
10388 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010389 }
10390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010391}