blob: 0e5ff429932ce9c74c145e2833e8bdf89e799ca7 [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 Brown46b9ac0a2010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brown46b9ac0a2010-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 */
334 final ArrayList mWindows = new ArrayList();
335
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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Brown00fa7bd2010-07-02 15:37:36 -0700632 mInputManager = new InputManager(context, this, pmc, mPowerManager);
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
667 private void placeWindowAfter(Object pos, WindowState window) {
668 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
676 private void placeWindowBefore(Object pos, WindowState window) {
677 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
689 ArrayList localmWindows = mWindows;
690 int jmax = localmWindows.size();
691 if(jmax == 0) {
692 return -1;
693 }
694 for(int j = (jmax-1); j >= 0; j--) {
695 WindowState wentry = (WindowState)localmWindows.get(j);
696 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;
706 final ArrayList 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();
751 Object pos = null;
752 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.
Romain Guy06882f82009-06-10 13:36:04 -0700771 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 mTokenMap.get(((WindowState)pos).mClient.asBinder());
773 if (atoken != null) {
774 final int NC = atoken.windows.size();
775 if (NC > 0) {
776 WindowState bottom = atoken.windows.get(0);
777 if (bottom.mSubLayer < 0) {
778 pos = bottom;
779 }
780 }
781 }
782 placeWindowBefore(pos, win);
783 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700784 // Continue looking down until we find the first
785 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 while (i >= 0) {
787 AppWindowToken t = mAppTokens.get(i);
788 final int NW = t.windows.size();
789 if (NW > 0) {
790 pos = t.windows.get(NW-1);
791 break;
792 }
793 i--;
794 }
795 if (pos != null) {
796 // Move in front of any windows attached to this
797 // one.
798 WindowToken atoken =
799 mTokenMap.get(((WindowState)pos).mClient.asBinder());
800 if (atoken != null) {
801 final int NC = atoken.windows.size();
802 if (NC > 0) {
803 WindowState top = atoken.windows.get(NC-1);
804 if (top.mSubLayer >= 0) {
805 pos = top;
806 }
807 }
808 }
809 placeWindowAfter(pos, win);
810 } else {
811 // Just search for the start of this layer.
812 final int myLayer = win.mBaseLayer;
813 for (i=0; i<N; i++) {
814 WindowState w = (WindowState)localmWindows.get(i);
815 if (w.mBaseLayer > myLayer) {
816 break;
817 }
818 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800819 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700820 TAG, "Adding window " + win + " at "
821 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700823 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 }
825 }
826 }
827 } else {
828 // Figure out where window should go, based on layer.
829 final int myLayer = win.mBaseLayer;
830 for (i=N-1; i>=0; i--) {
831 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
832 i++;
833 break;
834 }
835 }
836 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800837 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700838 TAG, "Adding window " + win + " at "
839 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700841 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 }
843 if (addToToken) {
844 token.windows.add(tokenWindowsPos, win);
845 }
846
847 } else {
848 // Figure out this window's ordering relative to the window
849 // it is attached to.
850 final int NA = token.windows.size();
851 final int sublayer = win.mSubLayer;
852 int largestSublayer = Integer.MIN_VALUE;
853 WindowState windowWithLargestSublayer = null;
854 for (i=0; i<NA; i++) {
855 WindowState w = token.windows.get(i);
856 final int wSublayer = w.mSubLayer;
857 if (wSublayer >= largestSublayer) {
858 largestSublayer = wSublayer;
859 windowWithLargestSublayer = w;
860 }
861 if (sublayer < 0) {
862 // For negative sublayers, we go below all windows
863 // in the same sublayer.
864 if (wSublayer >= sublayer) {
865 if (addToToken) {
866 token.windows.add(i, win);
867 }
868 placeWindowBefore(
869 wSublayer >= 0 ? attached : w, win);
870 break;
871 }
872 } else {
873 // For positive sublayers, we go above all windows
874 // in the same sublayer.
875 if (wSublayer > sublayer) {
876 if (addToToken) {
877 token.windows.add(i, win);
878 }
879 placeWindowBefore(w, win);
880 break;
881 }
882 }
883 }
884 if (i >= NA) {
885 if (addToToken) {
886 token.windows.add(win);
887 }
888 if (sublayer < 0) {
889 placeWindowBefore(attached, win);
890 } else {
891 placeWindowAfter(largestSublayer >= 0
892 ? windowWithLargestSublayer
893 : attached,
894 win);
895 }
896 }
897 }
Romain Guy06882f82009-06-10 13:36:04 -0700898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 if (win.mAppToken != null && addToToken) {
900 win.mAppToken.allAppWindows.add(win);
901 }
902 }
Romain Guy06882f82009-06-10 13:36:04 -0700903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 static boolean canBeImeTarget(WindowState w) {
905 final int fl = w.mAttrs.flags
906 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
907 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
908 return w.isVisibleOrAdding();
909 }
910 return false;
911 }
Romain Guy06882f82009-06-10 13:36:04 -0700912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
914 final ArrayList localmWindows = mWindows;
915 final int N = localmWindows.size();
916 WindowState w = null;
917 int i = N;
918 while (i > 0) {
919 i--;
920 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700921
Joe Onorato8a9b2202010-02-26 18:56:32 -0800922 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 // + Integer.toHexString(w.mAttrs.flags));
924 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800925 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 // Yet more tricksyness! If this window is a "starting"
928 // window, we do actually want to be on top of it, but
929 // it is not -really- where input will go. So if the caller
930 // is not actually looking to move the IME, look down below
931 // for a real window to target...
932 if (!willMove
933 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
934 && i > 0) {
935 WindowState wb = (WindowState)localmWindows.get(i-1);
936 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
937 i--;
938 w = wb;
939 }
940 }
941 break;
942 }
943 }
Romain Guy06882f82009-06-10 13:36:04 -0700944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700946
Joe Onorato8a9b2202010-02-26 18:56:32 -0800947 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 if (willMove && w != null) {
951 final WindowState curTarget = mInputMethodTarget;
952 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 // Now some fun for dealing with window animations that
955 // modify the Z order. We need to look at all windows below
956 // the current target that are in this app, finding the highest
957 // visible one in layering.
958 AppWindowToken token = curTarget.mAppToken;
959 WindowState highestTarget = null;
960 int highestPos = 0;
961 if (token.animating || token.animation != null) {
962 int pos = 0;
963 pos = localmWindows.indexOf(curTarget);
964 while (pos >= 0) {
965 WindowState win = (WindowState)localmWindows.get(pos);
966 if (win.mAppToken != token) {
967 break;
968 }
969 if (!win.mRemoved) {
970 if (highestTarget == null || win.mAnimLayer >
971 highestTarget.mAnimLayer) {
972 highestTarget = win;
973 highestPos = pos;
974 }
975 }
976 pos--;
977 }
978 }
Romain Guy06882f82009-06-10 13:36:04 -0700979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800981 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 + mNextAppTransition + " " + highestTarget
983 + " animating=" + highestTarget.isAnimating()
984 + " layer=" + highestTarget.mAnimLayer
985 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700986
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700987 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 // If we are currently setting up for an animation,
989 // hold everything until we can find out what will happen.
990 mInputMethodTargetWaitingAnim = true;
991 mInputMethodTarget = highestTarget;
992 return highestPos + 1;
993 } else if (highestTarget.isAnimating() &&
994 highestTarget.mAnimLayer > w.mAnimLayer) {
995 // If the window we are currently targeting is involved
996 // with an animation, and it is on top of the next target
997 // we will be over, then hold off on moving until
998 // that is done.
999 mInputMethodTarget = highestTarget;
1000 return highestPos + 1;
1001 }
1002 }
1003 }
1004 }
Romain Guy06882f82009-06-10 13:36:04 -07001005
Joe Onorato8a9b2202010-02-26 18:56:32 -08001006 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 if (w != null) {
1008 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001009 if (DEBUG_INPUT_METHOD) {
1010 RuntimeException e = null;
1011 if (!HIDE_STACK_CRAWLS) {
1012 e = new RuntimeException();
1013 e.fillInStackTrace();
1014 }
1015 Slog.w(TAG, "Moving IM target from "
1016 + mInputMethodTarget + " to " + w, e);
1017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 mInputMethodTarget = w;
1019 if (w.mAppToken != null) {
1020 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1021 } else {
1022 setInputMethodAnimLayerAdjustment(0);
1023 }
1024 }
1025 return i+1;
1026 }
1027 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001028 if (DEBUG_INPUT_METHOD) {
1029 RuntimeException e = null;
1030 if (!HIDE_STACK_CRAWLS) {
1031 e = new RuntimeException();
1032 e.fillInStackTrace();
1033 }
1034 Slog.w(TAG, "Moving IM target from "
1035 + mInputMethodTarget + " to null", e);
1036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 mInputMethodTarget = null;
1038 setInputMethodAnimLayerAdjustment(0);
1039 }
1040 return -1;
1041 }
Romain Guy06882f82009-06-10 13:36:04 -07001042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 void addInputMethodWindowToListLocked(WindowState win) {
1044 int pos = findDesiredInputMethodWindowIndexLocked(true);
1045 if (pos >= 0) {
1046 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001047 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001048 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001050 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 moveInputMethodDialogsLocked(pos+1);
1052 return;
1053 }
1054 win.mTargetAppToken = null;
1055 addWindowToListInOrderLocked(win, true);
1056 moveInputMethodDialogsLocked(pos);
1057 }
Romain Guy06882f82009-06-10 13:36:04 -07001058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001060 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 mInputMethodAnimLayerAdjustment = adj;
1062 WindowState imw = mInputMethodWindow;
1063 if (imw != null) {
1064 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001065 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 + " anim layer: " + imw.mAnimLayer);
1067 int wi = imw.mChildWindows.size();
1068 while (wi > 0) {
1069 wi--;
1070 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1071 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001072 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 + " anim layer: " + cw.mAnimLayer);
1074 }
1075 }
1076 int di = mInputMethodDialogs.size();
1077 while (di > 0) {
1078 di --;
1079 imw = mInputMethodDialogs.get(di);
1080 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001081 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 + " anim layer: " + imw.mAnimLayer);
1083 }
1084 }
Romain Guy06882f82009-06-10 13:36:04 -07001085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1087 int wpos = mWindows.indexOf(win);
1088 if (wpos >= 0) {
1089 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001090 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001092 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 int NC = win.mChildWindows.size();
1094 while (NC > 0) {
1095 NC--;
1096 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1097 int cpos = mWindows.indexOf(cw);
1098 if (cpos >= 0) {
1099 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001100 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001101 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 mWindows.remove(cpos);
1103 }
1104 }
1105 }
1106 return interestingPos;
1107 }
Romain Guy06882f82009-06-10 13:36:04 -07001108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 private void reAddWindowToListInOrderLocked(WindowState win) {
1110 addWindowToListInOrderLocked(win, false);
1111 // This is a hack to get all of the child windows added as well
1112 // at the right position. Child windows should be rare and
1113 // this case should be rare, so it shouldn't be that big a deal.
1114 int wpos = mWindows.indexOf(win);
1115 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001116 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001117 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001119 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 reAddWindowLocked(wpos, win);
1121 }
1122 }
Romain Guy06882f82009-06-10 13:36:04 -07001123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 void logWindowList(String prefix) {
1125 int N = mWindows.size();
1126 while (N > 0) {
1127 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001128 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 }
1130 }
Romain Guy06882f82009-06-10 13:36:04 -07001131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 void moveInputMethodDialogsLocked(int pos) {
1133 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001136 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 for (int i=0; i<N; i++) {
1138 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1139 }
1140 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001141 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 logWindowList(" ");
1143 }
Romain Guy06882f82009-06-10 13:36:04 -07001144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 if (pos >= 0) {
1146 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1147 if (pos < mWindows.size()) {
1148 WindowState wp = (WindowState)mWindows.get(pos);
1149 if (wp == mInputMethodWindow) {
1150 pos++;
1151 }
1152 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001153 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 for (int i=0; i<N; i++) {
1155 WindowState win = dialogs.get(i);
1156 win.mTargetAppToken = targetAppToken;
1157 pos = reAddWindowLocked(pos, win);
1158 }
1159 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001160 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 logWindowList(" ");
1162 }
1163 return;
1164 }
1165 for (int i=0; i<N; i++) {
1166 WindowState win = dialogs.get(i);
1167 win.mTargetAppToken = null;
1168 reAddWindowToListInOrderLocked(win);
1169 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001170 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 logWindowList(" ");
1172 }
1173 }
1174 }
Romain Guy06882f82009-06-10 13:36:04 -07001175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1177 final WindowState imWin = mInputMethodWindow;
1178 final int DN = mInputMethodDialogs.size();
1179 if (imWin == null && DN == 0) {
1180 return false;
1181 }
Romain Guy06882f82009-06-10 13:36:04 -07001182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1184 if (imPos >= 0) {
1185 // In this case, the input method windows are to be placed
1186 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 // First check to see if the input method windows are already
1189 // located here, and contiguous.
1190 final int N = mWindows.size();
1191 WindowState firstImWin = imPos < N
1192 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 // Figure out the actual input method window that should be
1195 // at the bottom of their stack.
1196 WindowState baseImWin = imWin != null
1197 ? imWin : mInputMethodDialogs.get(0);
1198 if (baseImWin.mChildWindows.size() > 0) {
1199 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1200 if (cw.mSubLayer < 0) baseImWin = cw;
1201 }
Romain Guy06882f82009-06-10 13:36:04 -07001202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 if (firstImWin == baseImWin) {
1204 // The windows haven't moved... but are they still contiguous?
1205 // First find the top IM window.
1206 int pos = imPos+1;
1207 while (pos < N) {
1208 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1209 break;
1210 }
1211 pos++;
1212 }
1213 pos++;
1214 // Now there should be no more input method windows above.
1215 while (pos < N) {
1216 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1217 break;
1218 }
1219 pos++;
1220 }
1221 if (pos >= N) {
1222 // All is good!
1223 return false;
1224 }
1225 }
Romain Guy06882f82009-06-10 13:36:04 -07001226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 if (imWin != null) {
1228 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001229 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 logWindowList(" ");
1231 }
1232 imPos = tmpRemoveWindowLocked(imPos, imWin);
1233 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001234 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 logWindowList(" ");
1236 }
1237 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1238 reAddWindowLocked(imPos, imWin);
1239 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001240 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 logWindowList(" ");
1242 }
1243 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1244 } else {
1245 moveInputMethodDialogsLocked(imPos);
1246 }
Romain Guy06882f82009-06-10 13:36:04 -07001247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 } else {
1249 // In this case, the input method windows go in a fixed layer,
1250 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001253 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 tmpRemoveWindowLocked(0, imWin);
1255 imWin.mTargetAppToken = null;
1256 reAddWindowToListInOrderLocked(imWin);
1257 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001258 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 logWindowList(" ");
1260 }
1261 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1262 } else {
1263 moveInputMethodDialogsLocked(-1);;
1264 }
Romain Guy06882f82009-06-10 13:36:04 -07001265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 }
Romain Guy06882f82009-06-10 13:36:04 -07001267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 if (needAssignLayers) {
1269 assignLayersLocked();
1270 }
Romain Guy06882f82009-06-10 13:36:04 -07001271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 return true;
1273 }
Romain Guy06882f82009-06-10 13:36:04 -07001274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 void adjustInputMethodDialogsLocked() {
1276 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1277 }
Romain Guy06882f82009-06-10 13:36:04 -07001278
Dianne Hackborn25994b42009-09-04 14:21:19 -07001279 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001280 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001281 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1282 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1283 ? wallpaperTarget.mAppToken.animation : null)
1284 + " upper=" + mUpperWallpaperTarget
1285 + " lower=" + mLowerWallpaperTarget);
1286 return (wallpaperTarget != null
1287 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1288 && wallpaperTarget.mAppToken.animation != null)))
1289 || mUpperWallpaperTarget != null
1290 || mLowerWallpaperTarget != null;
1291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001292
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001293 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1294 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001295
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001296 int adjustWallpaperWindowsLocked() {
1297 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001298
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001299 final int dw = mDisplay.getWidth();
1300 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001301
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001302 // First find top-most window that has asked to be on top of the
1303 // wallpaper; all wallpapers go behind it.
1304 final ArrayList localmWindows = mWindows;
1305 int N = localmWindows.size();
1306 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001307 WindowState foundW = null;
1308 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001309 WindowState topCurW = null;
1310 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001311 int i = N;
1312 while (i > 0) {
1313 i--;
1314 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001315 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1316 if (topCurW == null) {
1317 topCurW = w;
1318 topCurI = i;
1319 }
1320 continue;
1321 }
1322 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001323 if (w.mAppToken != null) {
1324 // If this window's app token is hidden and not animating,
1325 // it is of no interest to us.
1326 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001327 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001328 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001329 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001330 continue;
1331 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001332 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001334 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1335 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001336 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001337 && (mWallpaperTarget == w
1338 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001339 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001340 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001341 foundW = w;
1342 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001343 if (w == mWallpaperTarget && ((w.mAppToken != null
1344 && w.mAppToken.animation != null)
1345 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001346 // The current wallpaper target is animating, so we'll
1347 // look behind it for another possible target and figure
1348 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001349 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001350 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001351 continue;
1352 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001353 break;
1354 }
1355 }
1356
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001357 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001358 // If we are currently waiting for an app transition, and either
1359 // the current target or the next target are involved with it,
1360 // then hold off on doing anything with the wallpaper.
1361 // Note that we are checking here for just whether the target
1362 // is part of an app token... which is potentially overly aggressive
1363 // (the app token may not be involved in the transition), but good
1364 // enough (we'll just wait until whatever transition is pending
1365 // executes).
1366 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001367 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001368 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001369 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001370 }
1371 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001372 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001373 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001374 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001375 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001376 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001377
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001378 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001379 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001380 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 + " oldTarget: " + mWallpaperTarget);
1382 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001383
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001384 mLowerWallpaperTarget = null;
1385 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001386
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001387 WindowState oldW = mWallpaperTarget;
1388 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001389
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001390 // Now what is happening... if the current and new targets are
1391 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001392 if (foundW != null && oldW != null) {
1393 boolean oldAnim = oldW.mAnimation != null
1394 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1395 boolean foundAnim = foundW.mAnimation != null
1396 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001398 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001399 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001400 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001401 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001402 int oldI = localmWindows.indexOf(oldW);
1403 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001404 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001405 }
1406 if (oldI >= 0) {
1407 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001408 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001409 + "=" + oldW + "; new#" + foundI
1410 + "=" + foundW);
1411 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001412
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001413 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001414 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001415 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001416 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001417 }
1418 mWallpaperTarget = oldW;
1419 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001420
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001421 // Now set the upper and lower wallpaper targets
1422 // correctly, and make sure that we are positioning
1423 // the wallpaper below the lower.
1424 if (foundI > oldI) {
1425 // The new target is on top of the old one.
1426 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001427 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001428 }
1429 mUpperWallpaperTarget = foundW;
1430 mLowerWallpaperTarget = oldW;
1431 foundW = oldW;
1432 foundI = oldI;
1433 } else {
1434 // The new target is below the old one.
1435 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001436 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001437 }
1438 mUpperWallpaperTarget = oldW;
1439 mLowerWallpaperTarget = foundW;
1440 }
1441 }
1442 }
1443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001444
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001445 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001446 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001447 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1448 || (mLowerWallpaperTarget.mAppToken != null
1449 && mLowerWallpaperTarget.mAppToken.animation != null);
1450 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1451 || (mUpperWallpaperTarget.mAppToken != null
1452 && mUpperWallpaperTarget.mAppToken.animation != null);
1453 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001454 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001455 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001456 }
1457 mLowerWallpaperTarget = null;
1458 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001459 }
1460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001461
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001462 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001463 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001464 // The window is visible to the compositor... but is it visible
1465 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001466 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001468
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001469 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001470 // its layer adjustment. Only do this if we are not transfering
1471 // between two wallpaper targets.
1472 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001473 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001474 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001475
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001476 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1477 * TYPE_LAYER_MULTIPLIER
1478 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001479
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001480 // Now w is the window we are supposed to be behind... but we
1481 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001482 // AND any starting window associated with it, AND below the
1483 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001484 while (foundI > 0) {
1485 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001486 if (wb.mBaseLayer < maxLayer &&
1487 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001488 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001489 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001490 // This window is not related to the previous one in any
1491 // interesting way, so stop here.
1492 break;
1493 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001494 foundW = wb;
1495 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001496 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001497 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001498 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001499 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001500
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001501 if (foundW == null && topCurW != null) {
1502 // There is no wallpaper target, so it goes at the bottom.
1503 // We will assume it is the same place as last time, if known.
1504 foundW = topCurW;
1505 foundI = topCurI+1;
1506 } else {
1507 // Okay i is the position immediately above the wallpaper. Look at
1508 // what is below it for later.
1509 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1510 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001511
Dianne Hackborn284ac932009-08-28 10:34:25 -07001512 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001513 if (mWallpaperTarget.mWallpaperX >= 0) {
1514 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001515 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001516 }
1517 if (mWallpaperTarget.mWallpaperY >= 0) {
1518 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001519 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001520 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001521 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001522
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001523 // Start stepping backwards from here, ensuring that our wallpaper windows
1524 // are correctly placed.
1525 int curTokenIndex = mWallpaperTokens.size();
1526 while (curTokenIndex > 0) {
1527 curTokenIndex--;
1528 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001529 if (token.hidden == visible) {
1530 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1531 token.hidden = !visible;
1532 // Need to do a layout to ensure the wallpaper now has the
1533 // correct size.
1534 mLayoutNeeded = true;
1535 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001536
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001537 int curWallpaperIndex = token.windows.size();
1538 while (curWallpaperIndex > 0) {
1539 curWallpaperIndex--;
1540 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001541
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001542 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001543 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001544 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001545
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001546 // First, make sure the client has the current visibility
1547 // state.
1548 if (wallpaper.mWallpaperVisible != visible) {
1549 wallpaper.mWallpaperVisible = visible;
1550 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001551 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001552 "Setting visibility of wallpaper " + wallpaper
1553 + ": " + visible);
1554 wallpaper.mClient.dispatchAppVisibility(visible);
1555 } catch (RemoteException e) {
1556 }
1557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001558
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001559 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001561 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001562
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001563 // First, if this window is at the current index, then all
1564 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001565 if (wallpaper == foundW) {
1566 foundI--;
1567 foundW = foundI > 0
1568 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 continue;
1570 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001571
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001572 // The window didn't match... the current wallpaper window,
1573 // wherever it is, is in the wrong place, so make sure it is
1574 // not in the list.
1575 int oldIndex = localmWindows.indexOf(wallpaper);
1576 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001577 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001578 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001579 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001580 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001581 if (oldIndex < foundI) {
1582 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001583 }
1584 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001585
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001586 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001587 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001588 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001589 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001590
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001591 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001592 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001593 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001594 }
1595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001596
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001597 return changed;
1598 }
1599
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001600 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001601 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001602 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001603 mWallpaperAnimLayerAdjustment = adj;
1604 int curTokenIndex = mWallpaperTokens.size();
1605 while (curTokenIndex > 0) {
1606 curTokenIndex--;
1607 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1608 int curWallpaperIndex = token.windows.size();
1609 while (curWallpaperIndex > 0) {
1610 curWallpaperIndex--;
1611 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1612 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001613 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001614 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001615 }
1616 }
1617 }
1618
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001619 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1620 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001621 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001622 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001624 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001625 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1626 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1627 changed = wallpaperWin.mXOffset != offset;
1628 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001629 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001630 + wallpaperWin + " x: " + offset);
1631 wallpaperWin.mXOffset = offset;
1632 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001635 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001636 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001637 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001638
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001639 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001640 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001641 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1642 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1643 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001644 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001645 + wallpaperWin + " y: " + offset);
1646 changed = true;
1647 wallpaperWin.mYOffset = offset;
1648 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001649 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001651 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001652 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001654
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001655 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001656 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001657 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001658 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1659 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001661 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001662 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001663 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001664 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1665 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001666 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001667 if (mWaitingOnWallpaper != null) {
1668 long start = SystemClock.uptimeMillis();
1669 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1670 < start) {
1671 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001672 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001673 "Waiting for offset complete...");
1674 mWindowMap.wait(WALLPAPER_TIMEOUT);
1675 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001676 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 if ((start+WALLPAPER_TIMEOUT)
1679 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001680 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001681 + wallpaperWin);
1682 mLastWallpaperTimeoutTime = start;
1683 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001684 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001685 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001686 }
1687 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001688 } catch (RemoteException e) {
1689 }
1690 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001691
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001692 return changed;
1693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001694
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001695 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001696 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001697 if (mWaitingOnWallpaper != null &&
1698 mWaitingOnWallpaper.mClient.asBinder() == window) {
1699 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001700 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001701 }
1702 }
1703 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001704
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001705 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001706 final int dw = mDisplay.getWidth();
1707 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001709 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001710
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001711 WindowState target = mWallpaperTarget;
1712 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001713 if (target.mWallpaperX >= 0) {
1714 mLastWallpaperX = target.mWallpaperX;
1715 } else if (changingTarget.mWallpaperX >= 0) {
1716 mLastWallpaperX = changingTarget.mWallpaperX;
1717 }
1718 if (target.mWallpaperY >= 0) {
1719 mLastWallpaperY = target.mWallpaperY;
1720 } else if (changingTarget.mWallpaperY >= 0) {
1721 mLastWallpaperY = changingTarget.mWallpaperY;
1722 }
1723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001724
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001725 int curTokenIndex = mWallpaperTokens.size();
1726 while (curTokenIndex > 0) {
1727 curTokenIndex--;
1728 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1729 int curWallpaperIndex = token.windows.size();
1730 while (curWallpaperIndex > 0) {
1731 curWallpaperIndex--;
1732 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1733 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1734 wallpaper.computeShownFrameLocked();
1735 changed = true;
1736 // We only want to be synchronous with one wallpaper.
1737 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001738 }
1739 }
1740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001742 return changed;
1743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001744
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001745 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001746 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001747 final int dw = mDisplay.getWidth();
1748 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001749
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001750 int curTokenIndex = mWallpaperTokens.size();
1751 while (curTokenIndex > 0) {
1752 curTokenIndex--;
1753 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001754 if (token.hidden == visible) {
1755 token.hidden = !visible;
1756 // Need to do a layout to ensure the wallpaper now has the
1757 // correct size.
1758 mLayoutNeeded = true;
1759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001760
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001761 int curWallpaperIndex = token.windows.size();
1762 while (curWallpaperIndex > 0) {
1763 curWallpaperIndex--;
1764 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1765 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001766 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001768
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001769 if (wallpaper.mWallpaperVisible != visible) {
1770 wallpaper.mWallpaperVisible = visible;
1771 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001772 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001773 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001774 + ": " + visible);
1775 wallpaper.mClient.dispatchAppVisibility(visible);
1776 } catch (RemoteException e) {
1777 }
1778 }
1779 }
1780 }
1781 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 public int addWindow(Session session, IWindow client,
1784 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001785 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 int res = mPolicy.checkAddPermission(attrs);
1787 if (res != WindowManagerImpl.ADD_OKAY) {
1788 return res;
1789 }
Romain Guy06882f82009-06-10 13:36:04 -07001790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 boolean reportNewConfig = false;
1792 WindowState attachedWindow = null;
1793 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 synchronized(mWindowMap) {
1796 // Instantiating a Display requires talking with the simulator,
1797 // so don't do it until we know the system is mostly up and
1798 // running.
1799 if (mDisplay == null) {
1800 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1801 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001802 mInitialDisplayWidth = mDisplay.getWidth();
1803 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001804 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 reportNewConfig = true;
1806 }
Romain Guy06882f82009-06-10 13:36:04 -07001807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1811 }
1812
1813 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001814 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001816 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 + attrs.token + ". Aborting.");
1818 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1819 }
1820 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1821 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001822 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 + attrs.token + ". Aborting.");
1824 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1825 }
1826 }
1827
1828 boolean addToken = false;
1829 WindowToken token = mTokenMap.get(attrs.token);
1830 if (token == null) {
1831 if (attrs.type >= FIRST_APPLICATION_WINDOW
1832 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 + attrs.token + ". Aborting.");
1835 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1836 }
1837 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001838 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 + attrs.token + ". Aborting.");
1840 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1841 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001842 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001843 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001844 + attrs.token + ". Aborting.");
1845 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 token = new WindowToken(attrs.token, -1, false);
1848 addToken = true;
1849 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1850 && attrs.type <= LAST_APPLICATION_WINDOW) {
1851 AppWindowToken atoken = token.appWindowToken;
1852 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001853 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 + token + ". Aborting.");
1855 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1856 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001857 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 + token + ". Aborting.");
1859 return WindowManagerImpl.ADD_APP_EXITING;
1860 }
1861 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1862 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1865 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1866 }
1867 } else if (attrs.type == TYPE_INPUT_METHOD) {
1868 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 + attrs.token + ". Aborting.");
1871 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1872 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001873 } else if (attrs.type == TYPE_WALLPAPER) {
1874 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001875 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001876 + attrs.token + ". Aborting.");
1877 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 }
1880
1881 win = new WindowState(session, client, token,
1882 attachedWindow, attrs, viewVisibility);
1883 if (win.mDeathRecipient == null) {
1884 // Client has apparently died, so there is no reason to
1885 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001886 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 + " that is dead, aborting.");
1888 return WindowManagerImpl.ADD_APP_EXITING;
1889 }
1890
1891 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 res = mPolicy.prepareAddWindowLw(win, attrs);
1894 if (res != WindowManagerImpl.ADD_OKAY) {
1895 return res;
1896 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001897
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001898 if (outInputChannel != null) {
1899 String name = win.makeInputChannelName();
1900 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1901 win.mInputChannel = inputChannels[0];
1902 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1903
1904 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001906
1907 // From now on, no exceptions or errors allowed!
1908
1909 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 if (addToken) {
1914 mTokenMap.put(attrs.token, token);
1915 mTokenList.add(token);
1916 }
1917 win.attach();
1918 mWindowMap.put(client.asBinder(), win);
1919
1920 if (attrs.type == TYPE_APPLICATION_STARTING &&
1921 token.appWindowToken != null) {
1922 token.appWindowToken.startingWindow = win;
1923 }
1924
1925 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 if (attrs.type == TYPE_INPUT_METHOD) {
1928 mInputMethodWindow = win;
1929 addInputMethodWindowToListLocked(win);
1930 imMayMove = false;
1931 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1932 mInputMethodDialogs.add(win);
1933 addWindowToListInOrderLocked(win, true);
1934 adjustInputMethodDialogsLocked();
1935 imMayMove = false;
1936 } else {
1937 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001938 if (attrs.type == TYPE_WALLPAPER) {
1939 mLastWallpaperTimeoutTime = 0;
1940 adjustWallpaperWindowsLocked();
1941 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001942 adjustWallpaperWindowsLocked();
1943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 }
Romain Guy06882f82009-06-10 13:36:04 -07001945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 if (mInTouchMode) {
1951 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1952 }
1953 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1954 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1955 }
Romain Guy06882f82009-06-10 13:36:04 -07001956
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001957 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001959 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1960 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 imMayMove = false;
1962 }
1963 }
Romain Guy06882f82009-06-10 13:36:04 -07001964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001966 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 }
Romain Guy06882f82009-06-10 13:36:04 -07001968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 assignLayersLocked();
1970 // Don't do layout here, the window must call
1971 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 //dump();
1974
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001975 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001976 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001977 }
Jeff Brown349703e2010-06-22 01:27:15 -07001978
Joe Onorato8a9b2202010-02-26 18:56:32 -08001979 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 TAG, "New client " + client.asBinder()
1981 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001982
1983 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1984 reportNewConfig = true;
1985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 }
1987
1988 // sendNewConfiguration() checks caller permissions so we must call it with
1989 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1990 // identity anyway, so it's safe to just clear & restore around this whole
1991 // block.
1992 final long origId = Binder.clearCallingIdentity();
1993 if (reportNewConfig) {
1994 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 }
1996 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 return res;
1999 }
Romain Guy06882f82009-06-10 13:36:04 -07002000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 public void removeWindow(Session session, IWindow client) {
2002 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002003 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 if (win == null) {
2005 return;
2006 }
2007 removeWindowLocked(session, win);
2008 }
2009 }
Romain Guy06882f82009-06-10 13:36:04 -07002010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 public void removeWindowLocked(Session session, WindowState win) {
2012
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 TAG, "Remove " + win + " client="
2015 + Integer.toHexString(System.identityHashCode(
2016 win.mClient.asBinder()))
2017 + ", surface=" + win.mSurface);
2018
2019 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002020
2021 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002022
Joe Onorato8a9b2202010-02-26 18:56:32 -08002023 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2025 + " mExiting=" + win.mExiting
2026 + " isAnimating=" + win.isAnimating()
2027 + " app-animation="
2028 + (win.mAppToken != null ? win.mAppToken.animation : null)
2029 + " inPendingTransaction="
2030 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2031 + " mDisplayFrozen=" + mDisplayFrozen);
2032 // Visibility of the removed window. Will be used later to update orientation later on.
2033 boolean wasVisible = false;
2034 // First, see if we need to run an animation. If we do, we have
2035 // to hold off on removing the window until the animation is done.
2036 // If the display is frozen, just remove immediately, since the
2037 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002038 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 // If we are not currently running the exit animation, we
2040 // need to see about starting one.
2041 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2044 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2045 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2046 }
2047 // Try starting an animation.
2048 if (applyAnimationLocked(win, transit, false)) {
2049 win.mExiting = true;
2050 }
2051 }
2052 if (win.mExiting || win.isAnimating()) {
2053 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002054 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002055 win.mExiting = true;
2056 win.mRemoveOnExit = true;
2057 mLayoutNeeded = true;
2058 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2059 performLayoutAndPlaceSurfacesLocked();
2060 if (win.mAppToken != null) {
2061 win.mAppToken.updateReportedVisibilityLocked();
2062 }
2063 //dump();
2064 Binder.restoreCallingIdentity(origId);
2065 return;
2066 }
2067 }
2068
2069 removeWindowInnerLocked(session, win);
2070 // Removing a visible window will effect the computed orientation
2071 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002072 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002073 != mForcedAppOrientation
2074 && updateOrientationFromAppTokensLocked()) {
2075 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 }
2077 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2078 Binder.restoreCallingIdentity(origId);
2079 }
Romain Guy06882f82009-06-10 13:36:04 -07002080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 if (mInputMethodTarget == win) {
2085 moveInputMethodWindowsIfNeededLocked(false);
2086 }
Romain Guy06882f82009-06-10 13:36:04 -07002087
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002088 if (false) {
2089 RuntimeException e = new RuntimeException("here");
2090 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002091 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 mPolicy.removeWindowLw(win);
2095 win.removeLocked();
2096
2097 mWindowMap.remove(win.mClient.asBinder());
2098 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002099 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002100 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101
2102 if (mInputMethodWindow == win) {
2103 mInputMethodWindow = null;
2104 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2105 mInputMethodDialogs.remove(win);
2106 }
Romain Guy06882f82009-06-10 13:36:04 -07002107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002108 final WindowToken token = win.mToken;
2109 final AppWindowToken atoken = win.mAppToken;
2110 token.windows.remove(win);
2111 if (atoken != null) {
2112 atoken.allAppWindows.remove(win);
2113 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002114 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 TAG, "**** Removing window " + win + ": count="
2116 + token.windows.size());
2117 if (token.windows.size() == 0) {
2118 if (!token.explicit) {
2119 mTokenMap.remove(token.token);
2120 mTokenList.remove(token);
2121 } else if (atoken != null) {
2122 atoken.firstWindowDrawn = false;
2123 }
2124 }
2125
2126 if (atoken != null) {
2127 if (atoken.startingWindow == win) {
2128 atoken.startingWindow = null;
2129 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2130 // If this is the last window and we had requested a starting
2131 // transition window, well there is no point now.
2132 atoken.startingData = null;
2133 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2134 // If this is the last window except for a starting transition
2135 // window, we need to get rid of the starting transition.
2136 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002137 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 + ": no more real windows");
2139 }
2140 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2141 mH.sendMessage(m);
2142 }
2143 }
Romain Guy06882f82009-06-10 13:36:04 -07002144
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002145 if (win.mAttrs.type == TYPE_WALLPAPER) {
2146 mLastWallpaperTimeoutTime = 0;
2147 adjustWallpaperWindowsLocked();
2148 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002149 adjustWallpaperWindowsLocked();
2150 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 if (!mInLayout) {
2153 assignLayersLocked();
2154 mLayoutNeeded = true;
2155 performLayoutAndPlaceSurfacesLocked();
2156 if (win.mAppToken != null) {
2157 win.mAppToken.updateReportedVisibilityLocked();
2158 }
2159 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002160
2161 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 }
2163
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002164 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2165 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2166 + ": " + msg + " / " + w.mAttrs.getTitle();
2167 if (where != null) {
2168 Slog.i(TAG, str, where);
2169 } else {
2170 Slog.i(TAG, str);
2171 }
2172 }
2173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2175 long origId = Binder.clearCallingIdentity();
2176 try {
2177 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002178 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002180 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 Surface.openTransaction();
2182 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002183 if (SHOW_TRANSACTIONS) logSurface(w,
2184 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 w.mSurface.setTransparentRegionHint(region);
2186 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002187 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 Surface.closeTransaction();
2189 }
2190 }
2191 }
2192 } finally {
2193 Binder.restoreCallingIdentity(origId);
2194 }
2195 }
2196
2197 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002198 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 Rect visibleInsets) {
2200 long origId = Binder.clearCallingIdentity();
2201 try {
2202 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002203 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 if (w != null) {
2205 w.mGivenInsetsPending = false;
2206 w.mGivenContentInsets.set(contentInsets);
2207 w.mGivenVisibleInsets.set(visibleInsets);
2208 w.mTouchableInsets = touchableInsets;
2209 mLayoutNeeded = true;
2210 performLayoutAndPlaceSurfacesLocked();
2211 }
2212 }
2213 } finally {
2214 Binder.restoreCallingIdentity(origId);
2215 }
2216 }
Romain Guy06882f82009-06-10 13:36:04 -07002217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 public void getWindowDisplayFrame(Session session, IWindow client,
2219 Rect outDisplayFrame) {
2220 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002221 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 if (win == null) {
2223 outDisplayFrame.setEmpty();
2224 return;
2225 }
2226 outDisplayFrame.set(win.mDisplayFrame);
2227 }
2228 }
2229
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002230 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2231 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002232 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2233 window.mWallpaperX = x;
2234 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002235 window.mWallpaperXStep = xStep;
2236 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002237 if (updateWallpaperOffsetLocked(window, true)) {
2238 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002239 }
2240 }
2241 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002242
Dianne Hackborn75804932009-10-20 20:15:20 -07002243 void wallpaperCommandComplete(IBinder window, Bundle result) {
2244 synchronized (mWindowMap) {
2245 if (mWaitingOnWallpaper != null &&
2246 mWaitingOnWallpaper.mClient.asBinder() == window) {
2247 mWaitingOnWallpaper = null;
2248 mWindowMap.notifyAll();
2249 }
2250 }
2251 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002252
Dianne Hackborn75804932009-10-20 20:15:20 -07002253 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2254 String action, int x, int y, int z, Bundle extras, boolean sync) {
2255 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2256 || window == mUpperWallpaperTarget) {
2257 boolean doWait = sync;
2258 int curTokenIndex = mWallpaperTokens.size();
2259 while (curTokenIndex > 0) {
2260 curTokenIndex--;
2261 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2262 int curWallpaperIndex = token.windows.size();
2263 while (curWallpaperIndex > 0) {
2264 curWallpaperIndex--;
2265 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2266 try {
2267 wallpaper.mClient.dispatchWallpaperCommand(action,
2268 x, y, z, extras, sync);
2269 // We only want to be synchronous with one wallpaper.
2270 sync = false;
2271 } catch (RemoteException e) {
2272 }
2273 }
2274 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002275
Dianne Hackborn75804932009-10-20 20:15:20 -07002276 if (doWait) {
2277 // XXX Need to wait for result.
2278 }
2279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002280
Dianne Hackborn75804932009-10-20 20:15:20 -07002281 return null;
2282 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 public int relayoutWindow(Session session, IWindow client,
2285 WindowManager.LayoutParams attrs, int requestedWidth,
2286 int requestedHeight, int viewVisibility, boolean insetsPending,
2287 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002288 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 boolean displayed = false;
2290 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002291 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002295 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 if (win == null) {
2297 return 0;
2298 }
2299 win.mRequestedWidth = requestedWidth;
2300 win.mRequestedHeight = requestedHeight;
2301
2302 if (attrs != null) {
2303 mPolicy.adjustWindowParamsLw(attrs);
2304 }
Romain Guy06882f82009-06-10 13:36:04 -07002305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 int attrChanges = 0;
2307 int flagChanges = 0;
2308 if (attrs != null) {
2309 flagChanges = win.mAttrs.flags ^= attrs.flags;
2310 attrChanges = win.mAttrs.copyFrom(attrs);
2311 }
2312
Joe Onorato8a9b2202010-02-26 18:56:32 -08002313 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314
2315 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2316 win.mAlpha = attrs.alpha;
2317 }
2318
2319 final boolean scaledWindow =
2320 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2321
2322 if (scaledWindow) {
2323 // requested{Width|Height} Surface's physical size
2324 // attrs.{width|height} Size on screen
2325 win.mHScale = (attrs.width != requestedWidth) ?
2326 (attrs.width / (float)requestedWidth) : 1.0f;
2327 win.mVScale = (attrs.height != requestedHeight) ?
2328 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002329 } else {
2330 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 }
2332
2333 boolean imMayMove = (flagChanges&(
2334 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2335 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 boolean focusMayChange = win.mViewVisibility != viewVisibility
2338 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2339 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002340
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002341 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2342 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 win.mRelayoutCalled = true;
2345 final int oldVisibility = win.mViewVisibility;
2346 win.mViewVisibility = viewVisibility;
2347 if (viewVisibility == View.VISIBLE &&
2348 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2349 displayed = !win.isVisibleLw();
2350 if (win.mExiting) {
2351 win.mExiting = false;
2352 win.mAnimation = null;
2353 }
2354 if (win.mDestroying) {
2355 win.mDestroying = false;
2356 mDestroySurface.remove(win);
2357 }
2358 if (oldVisibility == View.GONE) {
2359 win.mEnterAnimationPending = true;
2360 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002361 if (displayed) {
2362 if (win.mSurface != null && !win.mDrawPending
2363 && !win.mCommitDrawPending && !mDisplayFrozen
2364 && mPolicy.isScreenOn()) {
2365 applyEnterAnimationLocked(win);
2366 }
2367 if ((win.mAttrs.flags
2368 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2369 if (DEBUG_VISIBILITY) Slog.v(TAG,
2370 "Relayout window turning screen on: " + win);
2371 win.mTurnOnScreen = true;
2372 }
2373 int diff = 0;
2374 if (win.mConfiguration != mCurConfiguration
2375 && (win.mConfiguration == null
2376 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2377 win.mConfiguration = mCurConfiguration;
2378 if (DEBUG_CONFIGURATION) {
2379 Slog.i(TAG, "Window " + win + " visible with new config: "
2380 + win.mConfiguration + " / 0x"
2381 + Integer.toHexString(diff));
2382 }
2383 outConfig.setTo(mCurConfiguration);
2384 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2387 // To change the format, we need to re-build the surface.
2388 win.destroySurfaceLocked();
2389 displayed = true;
2390 }
2391 try {
2392 Surface surface = win.createSurfaceLocked();
2393 if (surface != null) {
2394 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002395 win.mReportDestroySurface = false;
2396 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002397 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002398 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002400 // For some reason there isn't a surface. Clear the
2401 // caller's object so they see the same state.
2402 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 }
2404 } catch (Exception e) {
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;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002451 mInputMonitor.windowIsBecomingInvisibleLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 } else if (win.isAnimating()) {
2453 // Currently in a hide animation... turn this into
2454 // an exit.
2455 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002456 } else if (win == mWallpaperTarget) {
2457 // If the wallpaper is currently behind this
2458 // window, we need to change both of them inside
2459 // of a transaction to avoid artifacts.
2460 win.mExiting = true;
2461 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 } else {
2463 if (mInputMethodWindow == win) {
2464 mInputMethodWindow = null;
2465 }
2466 win.destroySurfaceLocked();
2467 }
2468 }
2469 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002470
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002471 if (win.mSurface == null || (win.getAttrs().flags
2472 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2473 || win.mSurfacePendingDestroy) {
2474 // We are being called from a local process, which
2475 // means outSurface holds its current surface. Ensure the
2476 // surface object is cleared, but we don't want it actually
2477 // destroyed at this point.
2478 win.mSurfacePendingDestroy = false;
2479 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002480 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002481 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002482 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002483 "Keeping surface, will report destroy: " + win);
2484 win.mReportDestroySurface = true;
2485 outSurface.copyFrom(win.mSurface);
2486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 }
2488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 if (focusMayChange) {
2490 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2491 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 imMayMove = false;
2493 }
2494 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2495 }
Romain Guy06882f82009-06-10 13:36:04 -07002496
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002497 // updateFocusedWindowLocked() already assigned layers so we only need to
2498 // reassign them at this point if the IM window state gets shuffled
2499 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002502 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2503 // Little hack here -- we -should- be able to rely on the
2504 // function to return true if the IME has moved and needs
2505 // its layer recomputed. However, if the IME was hidden
2506 // and isn't actually moved in the list, its layer may be
2507 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 assignLayers = true;
2509 }
2510 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002511 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002512 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002513 assignLayers = true;
2514 }
2515 }
Romain Guy06882f82009-06-10 13:36:04 -07002516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 mLayoutNeeded = true;
2518 win.mGivenInsetsPending = insetsPending;
2519 if (assignLayers) {
2520 assignLayersLocked();
2521 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002522 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002524 if (displayed && win.mIsWallpaper) {
2525 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002526 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 if (win.mAppToken != null) {
2529 win.mAppToken.updateReportedVisibilityLocked();
2530 }
2531 outFrame.set(win.mFrame);
2532 outContentInsets.set(win.mContentInsets);
2533 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002534 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002536 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 + ", requestedHeight=" + requestedHeight
2538 + ", viewVisibility=" + viewVisibility
2539 + "\nRelayout returning frame=" + outFrame
2540 + ", surface=" + outSurface);
2541
Joe Onorato8a9b2202010-02-26 18:56:32 -08002542 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2544
2545 inTouchMode = mInTouchMode;
2546 }
2547
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002548 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 sendNewConfiguration();
2550 }
Romain Guy06882f82009-06-10 13:36:04 -07002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2555 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2556 }
2557
2558 public void finishDrawingWindow(Session session, IWindow client) {
2559 final long origId = Binder.clearCallingIdentity();
2560 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002561 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002563 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2564 adjustWallpaperWindowsLocked();
2565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 mLayoutNeeded = true;
2567 performLayoutAndPlaceSurfacesLocked();
2568 }
2569 }
2570 Binder.restoreCallingIdentity(origId);
2571 }
2572
2573 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002574 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 + (lp != null ? lp.packageName : null)
2576 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2577 if (lp != null && lp.windowAnimations != 0) {
2578 // If this is a system resource, don't try to load it from the
2579 // application resources. It is nice to avoid loading application
2580 // resources if we can.
2581 String packageName = lp.packageName != null ? lp.packageName : "android";
2582 int resId = lp.windowAnimations;
2583 if ((resId&0xFF000000) == 0x01000000) {
2584 packageName = "android";
2585 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002586 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 + packageName);
2588 return AttributeCache.instance().get(packageName, resId,
2589 com.android.internal.R.styleable.WindowAnimation);
2590 }
2591 return null;
2592 }
Romain Guy06882f82009-06-10 13:36:04 -07002593
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002594 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002595 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002596 + packageName + " resId=0x" + Integer.toHexString(resId));
2597 if (packageName != null) {
2598 if ((resId&0xFF000000) == 0x01000000) {
2599 packageName = "android";
2600 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002601 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002602 + packageName);
2603 return AttributeCache.instance().get(packageName, resId,
2604 com.android.internal.R.styleable.WindowAnimation);
2605 }
2606 return null;
2607 }
2608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 private void applyEnterAnimationLocked(WindowState win) {
2610 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2611 if (win.mEnterAnimationPending) {
2612 win.mEnterAnimationPending = false;
2613 transit = WindowManagerPolicy.TRANSIT_ENTER;
2614 }
2615
2616 applyAnimationLocked(win, transit, true);
2617 }
2618
2619 private boolean applyAnimationLocked(WindowState win,
2620 int transit, boolean isEntrance) {
2621 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2622 // If we are trying to apply an animation, but already running
2623 // an animation of the same type, then just leave that one alone.
2624 return true;
2625 }
Romain Guy06882f82009-06-10 13:36:04 -07002626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 // Only apply an animation if the display isn't frozen. If it is
2628 // frozen, there is no reason to animate and it can cause strange
2629 // artifacts when we unfreeze the display if some different animation
2630 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002631 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 int anim = mPolicy.selectAnimationLw(win, transit);
2633 int attr = -1;
2634 Animation a = null;
2635 if (anim != 0) {
2636 a = AnimationUtils.loadAnimation(mContext, anim);
2637 } else {
2638 switch (transit) {
2639 case WindowManagerPolicy.TRANSIT_ENTER:
2640 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2641 break;
2642 case WindowManagerPolicy.TRANSIT_EXIT:
2643 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2644 break;
2645 case WindowManagerPolicy.TRANSIT_SHOW:
2646 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2647 break;
2648 case WindowManagerPolicy.TRANSIT_HIDE:
2649 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2650 break;
2651 }
2652 if (attr >= 0) {
2653 a = loadAnimation(win.mAttrs, attr);
2654 }
2655 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002656 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2658 + " mAnimation=" + win.mAnimation
2659 + " isEntrance=" + isEntrance);
2660 if (a != null) {
2661 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002662 RuntimeException e = null;
2663 if (!HIDE_STACK_CRAWLS) {
2664 e = new RuntimeException();
2665 e.fillInStackTrace();
2666 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002667 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 }
2669 win.setAnimation(a);
2670 win.mAnimationIsEntrance = isEntrance;
2671 }
2672 } else {
2673 win.clearAnimation();
2674 }
2675
2676 return win.mAnimation != null;
2677 }
2678
2679 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2680 int anim = 0;
2681 Context context = mContext;
2682 if (animAttr >= 0) {
2683 AttributeCache.Entry ent = getCachedAnimations(lp);
2684 if (ent != null) {
2685 context = ent.context;
2686 anim = ent.array.getResourceId(animAttr, 0);
2687 }
2688 }
2689 if (anim != 0) {
2690 return AnimationUtils.loadAnimation(context, anim);
2691 }
2692 return null;
2693 }
Romain Guy06882f82009-06-10 13:36:04 -07002694
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002695 private Animation loadAnimation(String packageName, int resId) {
2696 int anim = 0;
2697 Context context = mContext;
2698 if (resId >= 0) {
2699 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2700 if (ent != null) {
2701 context = ent.context;
2702 anim = resId;
2703 }
2704 }
2705 if (anim != 0) {
2706 return AnimationUtils.loadAnimation(context, anim);
2707 }
2708 return null;
2709 }
2710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 private boolean applyAnimationLocked(AppWindowToken wtoken,
2712 WindowManager.LayoutParams lp, int transit, boolean enter) {
2713 // Only apply an animation if the display isn't frozen. If it is
2714 // frozen, there is no reason to animate and it can cause strange
2715 // artifacts when we unfreeze the display if some different animation
2716 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002717 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002718 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002719 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002720 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002721 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002722 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002723 } else if (mNextAppTransitionPackage != null) {
2724 a = loadAnimation(mNextAppTransitionPackage, enter ?
2725 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002726 } else {
2727 int animAttr = 0;
2728 switch (transit) {
2729 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2730 animAttr = enter
2731 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2732 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2733 break;
2734 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2735 animAttr = enter
2736 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2737 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2738 break;
2739 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2740 animAttr = enter
2741 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2742 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2743 break;
2744 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2745 animAttr = enter
2746 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2747 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2748 break;
2749 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2750 animAttr = enter
2751 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2752 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2753 break;
2754 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2755 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002756 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002757 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2758 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002759 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002760 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002761 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2762 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002763 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002764 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002765 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002766 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2767 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2768 break;
2769 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2770 animAttr = enter
2771 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2772 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2773 break;
2774 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2775 animAttr = enter
2776 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2777 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002778 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002779 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002780 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002781 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002782 + " anim=" + a
2783 + " animAttr=0x" + Integer.toHexString(animAttr)
2784 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 if (a != null) {
2787 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002788 RuntimeException e = null;
2789 if (!HIDE_STACK_CRAWLS) {
2790 e = new RuntimeException();
2791 e.fillInStackTrace();
2792 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002793 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 }
2795 wtoken.setAnimation(a);
2796 }
2797 } else {
2798 wtoken.clearAnimation();
2799 }
2800
2801 return wtoken.animation != null;
2802 }
2803
2804 // -------------------------------------------------------------
2805 // Application Window Tokens
2806 // -------------------------------------------------------------
2807
2808 public void validateAppTokens(List tokens) {
2809 int v = tokens.size()-1;
2810 int m = mAppTokens.size()-1;
2811 while (v >= 0 && m >= 0) {
2812 AppWindowToken wtoken = mAppTokens.get(m);
2813 if (wtoken.removed) {
2814 m--;
2815 continue;
2816 }
2817 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002818 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2820 }
2821 v--;
2822 m--;
2823 }
2824 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002825 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 v--;
2827 }
2828 while (m >= 0) {
2829 AppWindowToken wtoken = mAppTokens.get(m);
2830 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002831 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 }
2833 m--;
2834 }
2835 }
2836
2837 boolean checkCallingPermission(String permission, String func) {
2838 // Quick check: if the calling permission is me, it's all okay.
2839 if (Binder.getCallingPid() == Process.myPid()) {
2840 return true;
2841 }
Romain Guy06882f82009-06-10 13:36:04 -07002842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 if (mContext.checkCallingPermission(permission)
2844 == PackageManager.PERMISSION_GRANTED) {
2845 return true;
2846 }
2847 String msg = "Permission Denial: " + func + " from pid="
2848 + Binder.getCallingPid()
2849 + ", uid=" + Binder.getCallingUid()
2850 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002851 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 return false;
2853 }
Romain Guy06882f82009-06-10 13:36:04 -07002854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 AppWindowToken findAppWindowToken(IBinder token) {
2856 WindowToken wtoken = mTokenMap.get(token);
2857 if (wtoken == null) {
2858 return null;
2859 }
2860 return wtoken.appWindowToken;
2861 }
Romain Guy06882f82009-06-10 13:36:04 -07002862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 public void addWindowToken(IBinder token, int type) {
2864 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2865 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002866 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 }
Romain Guy06882f82009-06-10 13:36:04 -07002868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 synchronized(mWindowMap) {
2870 WindowToken wtoken = mTokenMap.get(token);
2871 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002872 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 return;
2874 }
2875 wtoken = new WindowToken(token, type, true);
2876 mTokenMap.put(token, wtoken);
2877 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002878 if (type == TYPE_WALLPAPER) {
2879 mWallpaperTokens.add(wtoken);
2880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 }
2882 }
Romain Guy06882f82009-06-10 13:36:04 -07002883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 public void removeWindowToken(IBinder token) {
2885 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2886 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002887 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 }
2889
2890 final long origId = Binder.clearCallingIdentity();
2891 synchronized(mWindowMap) {
2892 WindowToken wtoken = mTokenMap.remove(token);
2893 mTokenList.remove(wtoken);
2894 if (wtoken != null) {
2895 boolean delayed = false;
2896 if (!wtoken.hidden) {
2897 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 final int N = wtoken.windows.size();
2900 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 for (int i=0; i<N; i++) {
2903 WindowState win = wtoken.windows.get(i);
2904
2905 if (win.isAnimating()) {
2906 delayed = true;
2907 }
Romain Guy06882f82009-06-10 13:36:04 -07002908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 if (win.isVisibleNow()) {
2910 applyAnimationLocked(win,
2911 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 changed = true;
2913 }
2914 }
2915
2916 if (changed) {
2917 mLayoutNeeded = true;
2918 performLayoutAndPlaceSurfacesLocked();
2919 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2920 }
Romain Guy06882f82009-06-10 13:36:04 -07002921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 if (delayed) {
2923 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002924 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2925 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 }
2927 }
Romain Guy06882f82009-06-10 13:36:04 -07002928
Jeff Brownc5ed5912010-07-14 18:48:53 -07002929 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002931 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
2933 }
2934 Binder.restoreCallingIdentity(origId);
2935 }
2936
2937 public void addAppToken(int addPos, IApplicationToken token,
2938 int groupId, int requestedOrientation, boolean fullscreen) {
2939 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2940 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002941 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 }
Jeff Brown349703e2010-06-22 01:27:15 -07002943
2944 // Get the dispatching timeout here while we are not holding any locks so that it
2945 // can be cached by the AppWindowToken. The timeout value is used later by the
2946 // input dispatcher in code that does hold locks. If we did not cache the value
2947 // here we would run the chance of introducing a deadlock between the window manager
2948 // (which holds locks while updating the input dispatcher state) and the activity manager
2949 // (which holds locks while querying the application token).
2950 long inputDispatchingTimeoutNanos;
2951 try {
2952 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2953 } catch (RemoteException ex) {
2954 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2955 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2956 }
Romain Guy06882f82009-06-10 13:36:04 -07002957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 synchronized(mWindowMap) {
2959 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2960 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002961 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 return;
2963 }
2964 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002965 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 wtoken.groupId = groupId;
2967 wtoken.appFullscreen = fullscreen;
2968 wtoken.requestedOrientation = requestedOrientation;
2969 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002970 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 mTokenMap.put(token.asBinder(), wtoken);
2972 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 // Application tokens start out hidden.
2975 wtoken.hidden = true;
2976 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 //dump();
2979 }
2980 }
Romain Guy06882f82009-06-10 13:36:04 -07002981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 public void setAppGroupId(IBinder token, int groupId) {
2983 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2984 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002985 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 }
2987
2988 synchronized(mWindowMap) {
2989 AppWindowToken wtoken = findAppWindowToken(token);
2990 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002991 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 return;
2993 }
2994 wtoken.groupId = groupId;
2995 }
2996 }
Romain Guy06882f82009-06-10 13:36:04 -07002997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 public int getOrientationFromWindowsLocked() {
2999 int pos = mWindows.size() - 1;
3000 while (pos >= 0) {
3001 WindowState wtoken = (WindowState) mWindows.get(pos);
3002 pos--;
3003 if (wtoken.mAppToken != null) {
3004 // We hit an application window. so the orientation will be determined by the
3005 // app window. No point in continuing further.
3006 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3007 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003008 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 continue;
3010 }
3011 int req = wtoken.mAttrs.screenOrientation;
3012 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3013 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3014 continue;
3015 } else {
3016 return req;
3017 }
3018 }
3019 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3020 }
Romain Guy06882f82009-06-10 13:36:04 -07003021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003023 int pos = mAppTokens.size() - 1;
3024 int curGroup = 0;
3025 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3026 boolean findingBehind = false;
3027 boolean haveGroup = false;
3028 boolean lastFullscreen = false;
3029 while (pos >= 0) {
3030 AppWindowToken wtoken = mAppTokens.get(pos);
3031 pos--;
3032 // if we're about to tear down this window and not seek for
3033 // the behind activity, don't use it for orientation
3034 if (!findingBehind
3035 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3036 continue;
3037 }
3038
3039 if (!haveGroup) {
3040 // We ignore any hidden applications on the top.
3041 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003042 continue;
3043 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003044 haveGroup = true;
3045 curGroup = wtoken.groupId;
3046 lastOrientation = wtoken.requestedOrientation;
3047 } else if (curGroup != wtoken.groupId) {
3048 // If we have hit a new application group, and the bottom
3049 // of the previous group didn't explicitly say to use
3050 // the orientation behind it, and the last app was
3051 // full screen, then we'll stick with the
3052 // user's orientation.
3053 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3054 && lastFullscreen) {
3055 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003058 int or = wtoken.requestedOrientation;
3059 // If this application is fullscreen, and didn't explicitly say
3060 // to use the orientation behind it, then just take whatever
3061 // orientation it has and ignores whatever is under it.
3062 lastFullscreen = wtoken.appFullscreen;
3063 if (lastFullscreen
3064 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3065 return or;
3066 }
3067 // If this application has requested an explicit orientation,
3068 // then use it.
3069 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3070 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3071 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3072 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3074 return or;
3075 }
3076 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3077 }
3078 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 }
Romain Guy06882f82009-06-10 13:36:04 -07003080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003082 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003083 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3084 "updateOrientationFromAppTokens()")) {
3085 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3086 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003087
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003088 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003090
3091 synchronized(mWindowMap) {
3092 if (updateOrientationFromAppTokensLocked()) {
3093 if (freezeThisOneIfNeeded != null) {
3094 AppWindowToken wtoken = findAppWindowToken(
3095 freezeThisOneIfNeeded);
3096 if (wtoken != null) {
3097 startAppFreezingScreenLocked(wtoken,
3098 ActivityInfo.CONFIG_ORIENTATION);
3099 }
3100 }
3101 config = computeNewConfigurationLocked();
3102
3103 } else if (currentConfig != null) {
3104 // No obvious action we need to take, but if our current
3105 // state mismatches the activity maanager's, update it
3106 mTempConfiguration.setToDefaults();
3107 if (computeNewConfigurationLocked(mTempConfiguration)) {
3108 if (currentConfig.diff(mTempConfiguration) != 0) {
3109 mWaitingForConfig = true;
3110 mLayoutNeeded = true;
3111 startFreezingDisplayLocked();
3112 config = new Configuration(mTempConfiguration);
3113 }
3114 }
3115 }
3116 }
3117
Dianne Hackborncfaef692009-06-15 14:24:44 -07003118 Binder.restoreCallingIdentity(ident);
3119 return config;
3120 }
3121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003123 * Determine the new desired orientation of the display, returning
3124 * a non-null new Configuration if it has changed from the current
3125 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3126 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3127 * SCREEN. This will typically be done for you if you call
3128 * sendNewConfiguration().
3129 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 * The orientation is computed from non-application windows first. If none of
3131 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003132 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3134 * android.os.IBinder)
3135 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003136 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003137 if (mDisplayFrozen) {
3138 // If the display is frozen, some activities may be in the middle
3139 // of restarting, and thus have removed their old window. If the
3140 // window has the flag to hide the lock screen, then the lock screen
3141 // can re-appear and inflict its own orientation on us. Keep the
3142 // orientation stable until this all settles down.
3143 return false;
3144 }
3145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 long ident = Binder.clearCallingIdentity();
3148 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003149 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 mForcedAppOrientation = req;
3153 //send a message to Policy indicating orientation change to take
3154 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003155 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003156 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3157 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3158 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 }
3160 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003161
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003162 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 } finally {
3164 Binder.restoreCallingIdentity(ident);
3165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 }
Romain Guy06882f82009-06-10 13:36:04 -07003167
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003168 int computeForcedAppOrientationLocked() {
3169 int req = getOrientationFromWindowsLocked();
3170 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3171 req = getOrientationFromAppTokensLocked();
3172 }
3173 return req;
3174 }
Romain Guy06882f82009-06-10 13:36:04 -07003175
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003176 public void setNewConfiguration(Configuration config) {
3177 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3178 "setNewConfiguration()")) {
3179 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3180 }
3181
3182 synchronized(mWindowMap) {
3183 mCurConfiguration = new Configuration(config);
3184 mWaitingForConfig = false;
3185 performLayoutAndPlaceSurfacesLocked();
3186 }
3187 }
3188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3190 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3191 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003192 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 }
Romain Guy06882f82009-06-10 13:36:04 -07003194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 synchronized(mWindowMap) {
3196 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3197 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003198 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 return;
3200 }
Romain Guy06882f82009-06-10 13:36:04 -07003201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 wtoken.requestedOrientation = requestedOrientation;
3203 }
3204 }
Romain Guy06882f82009-06-10 13:36:04 -07003205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 public int getAppOrientation(IApplicationToken token) {
3207 synchronized(mWindowMap) {
3208 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3209 if (wtoken == null) {
3210 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3211 }
Romain Guy06882f82009-06-10 13:36:04 -07003212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 return wtoken.requestedOrientation;
3214 }
3215 }
Romain Guy06882f82009-06-10 13:36:04 -07003216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3218 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3219 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003220 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 }
3222
3223 synchronized(mWindowMap) {
3224 boolean changed = false;
3225 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003226 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 changed = mFocusedApp != null;
3228 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003229 if (changed) {
3230 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 } else {
3233 AppWindowToken newFocus = findAppWindowToken(token);
3234 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003235 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 return;
3237 }
3238 changed = mFocusedApp != newFocus;
3239 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003240 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003241 if (changed) {
3242 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003244 }
3245
3246 if (moveFocusNow && changed) {
3247 final long origId = Binder.clearCallingIdentity();
3248 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3249 Binder.restoreCallingIdentity(origId);
3250 }
3251 }
3252 }
3253
3254 public void prepareAppTransition(int transit) {
3255 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3256 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003257 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 }
Romain Guy06882f82009-06-10 13:36:04 -07003259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003261 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 TAG, "Prepare app transition: transit=" + transit
3263 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003264 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003265 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3266 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003268 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3269 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3270 // Opening a new task always supersedes a close for the anim.
3271 mNextAppTransition = transit;
3272 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3273 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3274 // Opening a new activity always supersedes a close for the anim.
3275 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 }
3277 mAppTransitionReady = false;
3278 mAppTransitionTimeout = false;
3279 mStartingIconInTransition = false;
3280 mSkipAppTransitionAnimation = false;
3281 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3282 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3283 5000);
3284 }
3285 }
3286 }
3287
3288 public int getPendingAppTransition() {
3289 return mNextAppTransition;
3290 }
Romain Guy06882f82009-06-10 13:36:04 -07003291
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003292 public void overridePendingAppTransition(String packageName,
3293 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003294 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003295 mNextAppTransitionPackage = packageName;
3296 mNextAppTransitionEnter = enterAnim;
3297 mNextAppTransitionExit = exitAnim;
3298 }
3299 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 public void executeAppTransition() {
3302 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3303 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003304 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 }
Romain Guy06882f82009-06-10 13:36:04 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003308 if (DEBUG_APP_TRANSITIONS) {
3309 RuntimeException e = new RuntimeException("here");
3310 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003311 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003312 + mNextAppTransition, e);
3313 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003314 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 mAppTransitionReady = true;
3316 final long origId = Binder.clearCallingIdentity();
3317 performLayoutAndPlaceSurfacesLocked();
3318 Binder.restoreCallingIdentity(origId);
3319 }
3320 }
3321 }
3322
3323 public void setAppStartingWindow(IBinder token, String pkg,
3324 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3325 IBinder transferFrom, boolean createIfNeeded) {
3326 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3327 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003328 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 }
3330
3331 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003332 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3334 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 AppWindowToken wtoken = findAppWindowToken(token);
3337 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003338 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 return;
3340 }
3341
3342 // If the display is frozen, we won't do anything until the
3343 // actual window is displayed so there is no reason to put in
3344 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003345 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 return;
3347 }
Romain Guy06882f82009-06-10 13:36:04 -07003348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 if (wtoken.startingData != null) {
3350 return;
3351 }
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 if (transferFrom != null) {
3354 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3355 if (ttoken != null) {
3356 WindowState startingWindow = ttoken.startingWindow;
3357 if (startingWindow != null) {
3358 if (mStartingIconInTransition) {
3359 // In this case, the starting icon has already
3360 // been displayed, so start letting windows get
3361 // shown immediately without any more transitions.
3362 mSkipAppTransitionAnimation = true;
3363 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003364 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 "Moving existing starting from " + ttoken
3366 + " to " + wtoken);
3367 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 // Transfer the starting window over to the new
3370 // token.
3371 wtoken.startingData = ttoken.startingData;
3372 wtoken.startingView = ttoken.startingView;
3373 wtoken.startingWindow = startingWindow;
3374 ttoken.startingData = null;
3375 ttoken.startingView = null;
3376 ttoken.startingWindow = null;
3377 ttoken.startingMoved = true;
3378 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003379 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003381 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003382 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003384 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 ttoken.windows.remove(startingWindow);
3386 ttoken.allAppWindows.remove(startingWindow);
3387 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 // Propagate other interesting state between the
3390 // tokens. If the old token is displayed, we should
3391 // immediately force the new one to be displayed. If
3392 // it is animating, we need to move that animation to
3393 // the new one.
3394 if (ttoken.allDrawn) {
3395 wtoken.allDrawn = true;
3396 }
3397 if (ttoken.firstWindowDrawn) {
3398 wtoken.firstWindowDrawn = true;
3399 }
3400 if (!ttoken.hidden) {
3401 wtoken.hidden = false;
3402 wtoken.hiddenRequested = false;
3403 wtoken.willBeHidden = false;
3404 }
3405 if (wtoken.clientHidden != ttoken.clientHidden) {
3406 wtoken.clientHidden = ttoken.clientHidden;
3407 wtoken.sendAppVisibilityToClients();
3408 }
3409 if (ttoken.animation != null) {
3410 wtoken.animation = ttoken.animation;
3411 wtoken.animating = ttoken.animating;
3412 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3413 ttoken.animation = null;
3414 ttoken.animLayerAdjustment = 0;
3415 wtoken.updateLayers();
3416 ttoken.updateLayers();
3417 }
Romain Guy06882f82009-06-10 13:36:04 -07003418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 mLayoutNeeded = true;
3421 performLayoutAndPlaceSurfacesLocked();
3422 Binder.restoreCallingIdentity(origId);
3423 return;
3424 } else if (ttoken.startingData != null) {
3425 // The previous app was getting ready to show a
3426 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003427 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 "Moving pending starting from " + ttoken
3429 + " to " + wtoken);
3430 wtoken.startingData = ttoken.startingData;
3431 ttoken.startingData = null;
3432 ttoken.startingMoved = true;
3433 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3434 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3435 // want to process the message ASAP, before any other queued
3436 // messages.
3437 mH.sendMessageAtFrontOfQueue(m);
3438 return;
3439 }
3440 }
3441 }
3442
3443 // There is no existing starting window, and the caller doesn't
3444 // want us to create one, so that's it!
3445 if (!createIfNeeded) {
3446 return;
3447 }
Romain Guy06882f82009-06-10 13:36:04 -07003448
Dianne Hackborn284ac932009-08-28 10:34:25 -07003449 // If this is a translucent or wallpaper window, then don't
3450 // show a starting window -- the current effect (a full-screen
3451 // opaque starting window that fades away to the real contents
3452 // when it is ready) does not work for this.
3453 if (theme != 0) {
3454 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3455 com.android.internal.R.styleable.Window);
3456 if (ent.array.getBoolean(
3457 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3458 return;
3459 }
3460 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003461 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3462 return;
3463 }
3464 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003465 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3466 return;
3467 }
3468 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 mStartingIconInTransition = true;
3471 wtoken.startingData = new StartingData(
3472 pkg, theme, nonLocalizedLabel,
3473 labelRes, icon);
3474 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3475 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3476 // want to process the message ASAP, before any other queued
3477 // messages.
3478 mH.sendMessageAtFrontOfQueue(m);
3479 }
3480 }
3481
3482 public void setAppWillBeHidden(IBinder token) {
3483 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3484 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003485 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 }
3487
3488 AppWindowToken wtoken;
3489
3490 synchronized(mWindowMap) {
3491 wtoken = findAppWindowToken(token);
3492 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003493 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 -08003494 return;
3495 }
3496 wtoken.willBeHidden = true;
3497 }
3498 }
Romain Guy06882f82009-06-10 13:36:04 -07003499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3501 boolean visible, int transit, boolean performLayout) {
3502 boolean delayed = false;
3503
3504 if (wtoken.clientHidden == visible) {
3505 wtoken.clientHidden = !visible;
3506 wtoken.sendAppVisibilityToClients();
3507 }
Romain Guy06882f82009-06-10 13:36:04 -07003508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509 wtoken.willBeHidden = false;
3510 if (wtoken.hidden == visible) {
3511 final int N = wtoken.allAppWindows.size();
3512 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003513 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3515 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003518
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003519 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 if (wtoken.animation == sDummyAnimation) {
3521 wtoken.animation = null;
3522 }
3523 applyAnimationLocked(wtoken, lp, transit, visible);
3524 changed = true;
3525 if (wtoken.animation != null) {
3526 delayed = runningAppAnimation = true;
3527 }
3528 }
Romain Guy06882f82009-06-10 13:36:04 -07003529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 for (int i=0; i<N; i++) {
3531 WindowState win = wtoken.allAppWindows.get(i);
3532 if (win == wtoken.startingWindow) {
3533 continue;
3534 }
3535
3536 if (win.isAnimating()) {
3537 delayed = true;
3538 }
Romain Guy06882f82009-06-10 13:36:04 -07003539
Joe Onorato8a9b2202010-02-26 18:56:32 -08003540 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 //win.dump(" ");
3542 if (visible) {
3543 if (!win.isVisibleNow()) {
3544 if (!runningAppAnimation) {
3545 applyAnimationLocked(win,
3546 WindowManagerPolicy.TRANSIT_ENTER, true);
3547 }
3548 changed = true;
3549 }
3550 } else if (win.isVisibleNow()) {
3551 if (!runningAppAnimation) {
3552 applyAnimationLocked(win,
3553 WindowManagerPolicy.TRANSIT_EXIT, false);
3554 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003555 mInputMonitor.windowIsBecomingInvisibleLw(win);
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();
3583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 }
3585 }
3586
3587 if (wtoken.animation != null) {
3588 delayed = true;
3589 }
Romain Guy06882f82009-06-10 13:36:04 -07003590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 return delayed;
3592 }
3593
3594 public void setAppVisibility(IBinder token, boolean visible) {
3595 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3596 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003597 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 }
3599
3600 AppWindowToken wtoken;
3601
3602 synchronized(mWindowMap) {
3603 wtoken = findAppWindowToken(token);
3604 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003605 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 return;
3607 }
3608
3609 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003610 RuntimeException e = null;
3611 if (!HIDE_STACK_CRAWLS) {
3612 e = new RuntimeException();
3613 e.fillInStackTrace();
3614 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003615 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 + "): mNextAppTransition=" + mNextAppTransition
3617 + " hidden=" + wtoken.hidden
3618 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3619 }
Romain Guy06882f82009-06-10 13:36:04 -07003620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 // If we are preparing an app transition, then delay changing
3622 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003623 if (!mDisplayFrozen && mPolicy.isScreenOn()
3624 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 // Already in requested state, don't do anything more.
3626 if (wtoken.hiddenRequested != visible) {
3627 return;
3628 }
3629 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003630
Joe Onorato8a9b2202010-02-26 18:56:32 -08003631 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 TAG, "Setting dummy animation on: " + wtoken);
3633 wtoken.setDummyAnimation();
3634 mOpeningApps.remove(wtoken);
3635 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003636 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 wtoken.inPendingTransaction = true;
3638 if (visible) {
3639 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 wtoken.startingDisplayed = false;
3641 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003642
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003643 // If the token is currently hidden (should be the
3644 // common case), then we need to set up to wait for
3645 // its windows to be ready.
3646 if (wtoken.hidden) {
3647 wtoken.allDrawn = false;
3648 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003649
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003650 if (wtoken.clientHidden) {
3651 // In the case where we are making an app visible
3652 // but holding off for a transition, we still need
3653 // to tell the client to make its windows visible so
3654 // they get drawn. Otherwise, we will wait on
3655 // performing the transition until all windows have
3656 // been drawn, they never will be, and we are sad.
3657 wtoken.clientHidden = false;
3658 wtoken.sendAppVisibilityToClients();
3659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 }
3661 } else {
3662 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003663
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003664 // If the token is currently visible (should be the
3665 // common case), then set up to wait for it to be hidden.
3666 if (!wtoken.hidden) {
3667 wtoken.waitingToHide = true;
3668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 }
3670 return;
3671 }
Romain Guy06882f82009-06-10 13:36:04 -07003672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003674 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 wtoken.updateReportedVisibilityLocked();
3676 Binder.restoreCallingIdentity(origId);
3677 }
3678 }
3679
3680 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3681 boolean unfreezeSurfaceNow, boolean force) {
3682 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003683 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 + " force=" + force);
3685 final int N = wtoken.allAppWindows.size();
3686 boolean unfrozeWindows = false;
3687 for (int i=0; i<N; i++) {
3688 WindowState w = wtoken.allAppWindows.get(i);
3689 if (w.mAppFreezing) {
3690 w.mAppFreezing = false;
3691 if (w.mSurface != null && !w.mOrientationChanging) {
3692 w.mOrientationChanging = true;
3693 }
3694 unfrozeWindows = true;
3695 }
3696 }
3697 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003698 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 wtoken.freezingScreen = false;
3700 mAppsFreezingScreen--;
3701 }
3702 if (unfreezeSurfaceNow) {
3703 if (unfrozeWindows) {
3704 mLayoutNeeded = true;
3705 performLayoutAndPlaceSurfacesLocked();
3706 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003707 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 }
3709 }
3710 }
Romain Guy06882f82009-06-10 13:36:04 -07003711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3713 int configChanges) {
3714 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003715 RuntimeException e = null;
3716 if (!HIDE_STACK_CRAWLS) {
3717 e = new RuntimeException();
3718 e.fillInStackTrace();
3719 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003720 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 + ": hidden=" + wtoken.hidden + " freezing="
3722 + wtoken.freezingScreen, e);
3723 }
3724 if (!wtoken.hiddenRequested) {
3725 if (!wtoken.freezingScreen) {
3726 wtoken.freezingScreen = true;
3727 mAppsFreezingScreen++;
3728 if (mAppsFreezingScreen == 1) {
3729 startFreezingDisplayLocked();
3730 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3731 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3732 5000);
3733 }
3734 }
3735 final int N = wtoken.allAppWindows.size();
3736 for (int i=0; i<N; i++) {
3737 WindowState w = wtoken.allAppWindows.get(i);
3738 w.mAppFreezing = true;
3739 }
3740 }
3741 }
Romain Guy06882f82009-06-10 13:36:04 -07003742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 public void startAppFreezingScreen(IBinder token, int configChanges) {
3744 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3745 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003746 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 }
3748
3749 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003750 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003751 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 return;
3753 }
Romain Guy06882f82009-06-10 13:36:04 -07003754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755 AppWindowToken wtoken = findAppWindowToken(token);
3756 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003757 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 return;
3759 }
3760 final long origId = Binder.clearCallingIdentity();
3761 startAppFreezingScreenLocked(wtoken, configChanges);
3762 Binder.restoreCallingIdentity(origId);
3763 }
3764 }
Romain Guy06882f82009-06-10 13:36:04 -07003765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 public void stopAppFreezingScreen(IBinder token, boolean force) {
3767 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3768 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003769 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 }
3771
3772 synchronized(mWindowMap) {
3773 AppWindowToken wtoken = findAppWindowToken(token);
3774 if (wtoken == null || wtoken.appToken == null) {
3775 return;
3776 }
3777 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003778 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3780 unsetAppFreezingScreenLocked(wtoken, true, force);
3781 Binder.restoreCallingIdentity(origId);
3782 }
3783 }
Romain Guy06882f82009-06-10 13:36:04 -07003784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003785 public void removeAppToken(IBinder token) {
3786 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3787 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003788 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003789 }
3790
3791 AppWindowToken wtoken = null;
3792 AppWindowToken startingToken = null;
3793 boolean delayed = false;
3794
3795 final long origId = Binder.clearCallingIdentity();
3796 synchronized(mWindowMap) {
3797 WindowToken basewtoken = mTokenMap.remove(token);
3798 mTokenList.remove(basewtoken);
3799 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003800 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003801 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 wtoken.inPendingTransaction = false;
3803 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003804 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 if (mClosingApps.contains(wtoken)) {
3806 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003807 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003808 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003809 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 delayed = true;
3811 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003812 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 TAG, "Removing app " + wtoken + " delayed=" + delayed
3814 + " animation=" + wtoken.animation
3815 + " animating=" + wtoken.animating);
3816 if (delayed) {
3817 // set the token aside because it has an active animation to be finished
3818 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003819 } else {
3820 // Make sure there is no animation running on this token,
3821 // so any windows associated with it will be removed as
3822 // soon as their animations are complete
3823 wtoken.animation = null;
3824 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 }
3826 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003827 if (mLastEnterAnimToken == wtoken) {
3828 mLastEnterAnimToken = null;
3829 mLastEnterAnimParams = null;
3830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003831 wtoken.removed = true;
3832 if (wtoken.startingData != null) {
3833 startingToken = wtoken;
3834 }
3835 unsetAppFreezingScreenLocked(wtoken, true, true);
3836 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003837 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 mFocusedApp = null;
3839 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003840 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 }
3842 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003843 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 }
Romain Guy06882f82009-06-10 13:36:04 -07003845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 if (!delayed && wtoken != null) {
3847 wtoken.updateReportedVisibilityLocked();
3848 }
3849 }
3850 Binder.restoreCallingIdentity(origId);
3851
3852 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003853 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003854 + startingToken + ": app token removed");
3855 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3856 mH.sendMessage(m);
3857 }
3858 }
3859
3860 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3861 final int NW = token.windows.size();
3862 for (int i=0; i<NW; i++) {
3863 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003864 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003866 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 int j = win.mChildWindows.size();
3868 while (j > 0) {
3869 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003870 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003871 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003872 "Tmp removing child window " + cwin);
3873 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 }
3875 }
3876 return NW > 0;
3877 }
3878
3879 void dumpAppTokensLocked() {
3880 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003881 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 }
3883 }
Romain Guy06882f82009-06-10 13:36:04 -07003884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 void dumpWindowsLocked() {
3886 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003887 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 }
3889 }
Romain Guy06882f82009-06-10 13:36:04 -07003890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003891 private int findWindowOffsetLocked(int tokenPos) {
3892 final int NW = mWindows.size();
3893
3894 if (tokenPos >= mAppTokens.size()) {
3895 int i = NW;
3896 while (i > 0) {
3897 i--;
3898 WindowState win = (WindowState)mWindows.get(i);
3899 if (win.getAppToken() != null) {
3900 return i+1;
3901 }
3902 }
3903 }
3904
3905 while (tokenPos > 0) {
3906 // Find the first app token below the new position that has
3907 // a window displayed.
3908 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003909 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003911 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003912 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003913 "Skipping token -- currently sending to bottom");
3914 tokenPos--;
3915 continue;
3916 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 int i = wtoken.windows.size();
3918 while (i > 0) {
3919 i--;
3920 WindowState win = wtoken.windows.get(i);
3921 int j = win.mChildWindows.size();
3922 while (j > 0) {
3923 j--;
3924 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003925 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003926 for (int pos=NW-1; pos>=0; pos--) {
3927 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003928 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 "Found child win @" + (pos+1));
3930 return pos+1;
3931 }
3932 }
3933 }
3934 }
3935 for (int pos=NW-1; pos>=0; pos--) {
3936 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003937 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938 return pos+1;
3939 }
3940 }
3941 }
3942 tokenPos--;
3943 }
3944
3945 return 0;
3946 }
3947
3948 private final int reAddWindowLocked(int index, WindowState win) {
3949 final int NCW = win.mChildWindows.size();
3950 boolean added = false;
3951 for (int j=0; j<NCW; j++) {
3952 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3953 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003954 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003955 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956 mWindows.add(index, win);
3957 index++;
3958 added = true;
3959 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003960 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003961 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 mWindows.add(index, cwin);
3963 index++;
3964 }
3965 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003966 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003967 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003968 mWindows.add(index, win);
3969 index++;
3970 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003971 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 return index;
3973 }
Romain Guy06882f82009-06-10 13:36:04 -07003974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3976 final int NW = token.windows.size();
3977 for (int i=0; i<NW; i++) {
3978 index = reAddWindowLocked(index, token.windows.get(i));
3979 }
3980 return index;
3981 }
3982
3983 public void moveAppToken(int index, IBinder token) {
3984 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3985 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003986 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 }
3988
3989 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003990 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003991 if (DEBUG_REORDER) dumpAppTokensLocked();
3992 final AppWindowToken wtoken = findAppWindowToken(token);
3993 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003994 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 + token + " (" + wtoken + ")");
3996 return;
3997 }
3998 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003999 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004003 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 if (DEBUG_REORDER) dumpWindowsLocked();
4005 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004006 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 if (DEBUG_REORDER) dumpWindowsLocked();
4008 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004009 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 if (DEBUG_REORDER) dumpWindowsLocked();
4011 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 mLayoutNeeded = true;
4013 performLayoutAndPlaceSurfacesLocked();
4014 }
4015 Binder.restoreCallingIdentity(origId);
4016 }
4017 }
4018
4019 private void removeAppTokensLocked(List<IBinder> tokens) {
4020 // XXX This should be done more efficiently!
4021 // (take advantage of the fact that both lists should be
4022 // ordered in the same way.)
4023 int N = tokens.size();
4024 for (int i=0; i<N; i++) {
4025 IBinder token = tokens.get(i);
4026 final AppWindowToken wtoken = findAppWindowToken(token);
4027 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004028 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 + token + " (" + wtoken + ")");
4030 i--;
4031 N--;
4032 }
4033 }
4034 }
4035
Dianne Hackborna8f60182009-09-01 19:01:50 -07004036 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4037 boolean updateFocusAndLayout) {
4038 // First remove all of the windows from the list.
4039 tmpRemoveAppWindowsLocked(wtoken);
4040
4041 // Where to start adding?
4042 int pos = findWindowOffsetLocked(tokenPos);
4043
4044 // And now add them back at the correct place.
4045 pos = reAddAppWindowsLocked(pos, wtoken);
4046
4047 if (updateFocusAndLayout) {
4048 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4049 assignLayersLocked();
4050 }
4051 mLayoutNeeded = true;
4052 performLayoutAndPlaceSurfacesLocked();
4053 }
4054 }
4055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004056 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4057 // First remove all of the windows from the list.
4058 final int N = tokens.size();
4059 int i;
4060 for (i=0; i<N; i++) {
4061 WindowToken token = mTokenMap.get(tokens.get(i));
4062 if (token != null) {
4063 tmpRemoveAppWindowsLocked(token);
4064 }
4065 }
4066
4067 // Where to start adding?
4068 int pos = findWindowOffsetLocked(tokenPos);
4069
4070 // And now add them back at the correct place.
4071 for (i=0; i<N; i++) {
4072 WindowToken token = mTokenMap.get(tokens.get(i));
4073 if (token != null) {
4074 pos = reAddAppWindowsLocked(pos, token);
4075 }
4076 }
4077
Dianne Hackborna8f60182009-09-01 19:01:50 -07004078 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4079 assignLayersLocked();
4080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 mLayoutNeeded = true;
4082 performLayoutAndPlaceSurfacesLocked();
4083
4084 //dump();
4085 }
4086
4087 public void moveAppTokensToTop(List<IBinder> tokens) {
4088 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4089 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004090 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004091 }
4092
4093 final long origId = Binder.clearCallingIdentity();
4094 synchronized(mWindowMap) {
4095 removeAppTokensLocked(tokens);
4096 final int N = tokens.size();
4097 for (int i=0; i<N; i++) {
4098 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4099 if (wt != null) {
4100 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004101 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004102 mToTopApps.remove(wt);
4103 mToBottomApps.remove(wt);
4104 mToTopApps.add(wt);
4105 wt.sendingToBottom = false;
4106 wt.sendingToTop = true;
4107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 }
4109 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004110
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004111 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004112 moveAppWindowsLocked(tokens, mAppTokens.size());
4113 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 }
4115 Binder.restoreCallingIdentity(origId);
4116 }
4117
4118 public void moveAppTokensToBottom(List<IBinder> tokens) {
4119 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4120 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004121 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004122 }
4123
4124 final long origId = Binder.clearCallingIdentity();
4125 synchronized(mWindowMap) {
4126 removeAppTokensLocked(tokens);
4127 final int N = tokens.size();
4128 int pos = 0;
4129 for (int i=0; i<N; i++) {
4130 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4131 if (wt != null) {
4132 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004133 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004134 mToTopApps.remove(wt);
4135 mToBottomApps.remove(wt);
4136 mToBottomApps.add(i, wt);
4137 wt.sendingToTop = false;
4138 wt.sendingToBottom = true;
4139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 pos++;
4141 }
4142 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004143
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004144 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004145 moveAppWindowsLocked(tokens, 0);
4146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147 }
4148 Binder.restoreCallingIdentity(origId);
4149 }
4150
4151 // -------------------------------------------------------------
4152 // Misc IWindowSession methods
4153 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004154
Jim Miller284b62e2010-06-08 14:27:42 -07004155 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004156 {
Jim Miller284b62e2010-06-08 14:27:42 -07004157 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4158 // called before DevicePolicyManagerService has started.
4159 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4160 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4161 Context.DEVICE_POLICY_SERVICE);
4162 if (dpm != null) {
4163 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4164 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4165 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4166 }
Jim Millerd6b57052010-06-07 17:52:42 -07004167 }
Jim Miller284b62e2010-06-08 14:27:42 -07004168 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004169 }
4170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004172 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 != PackageManager.PERMISSION_GRANTED) {
4174 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4175 }
Jim Millerd6b57052010-06-07 17:52:42 -07004176
Jim Miller284b62e2010-06-08 14:27:42 -07004177 synchronized (mKeyguardTokenWatcher) {
4178 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004179 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 }
4181
4182 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004183 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 != PackageManager.PERMISSION_GRANTED) {
4185 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187
Jim Miller284b62e2010-06-08 14:27:42 -07004188 synchronized (mKeyguardTokenWatcher) {
4189 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004190
Jim Miller284b62e2010-06-08 14:27:42 -07004191 if (!mKeyguardTokenWatcher.isAcquired()) {
4192 // If we are the last one to reenable the keyguard wait until
4193 // we have actually finished reenabling until returning.
4194 // It is possible that reenableKeyguard() can be called before
4195 // the previous disableKeyguard() is handled, in which case
4196 // neither mKeyguardTokenWatcher.acquired() or released() would
4197 // be called. In that case mKeyguardDisabled will be false here
4198 // and we have nothing to wait for.
4199 while (mKeyguardDisabled) {
4200 try {
4201 mKeyguardTokenWatcher.wait();
4202 } catch (InterruptedException e) {
4203 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 }
4205 }
4206 }
4207 }
4208 }
4209
4210 /**
4211 * @see android.app.KeyguardManager#exitKeyguardSecurely
4212 */
4213 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004214 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 != PackageManager.PERMISSION_GRANTED) {
4216 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4217 }
4218 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4219 public void onKeyguardExitResult(boolean success) {
4220 try {
4221 callback.onKeyguardExitResult(success);
4222 } catch (RemoteException e) {
4223 // Client has died, we don't care.
4224 }
4225 }
4226 });
4227 }
4228
4229 public boolean inKeyguardRestrictedInputMode() {
4230 return mPolicy.inKeyguardRestrictedKeyInputMode();
4231 }
Romain Guy06882f82009-06-10 13:36:04 -07004232
Dianne Hackbornffa42482009-09-23 22:20:11 -07004233 public void closeSystemDialogs(String reason) {
4234 synchronized(mWindowMap) {
4235 for (int i=mWindows.size()-1; i>=0; i--) {
4236 WindowState w = (WindowState)mWindows.get(i);
4237 if (w.mSurface != null) {
4238 try {
4239 w.mClient.closeSystemDialogs(reason);
4240 } catch (RemoteException e) {
4241 }
4242 }
4243 }
4244 }
4245 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 static float fixScale(float scale) {
4248 if (scale < 0) scale = 0;
4249 else if (scale > 20) scale = 20;
4250 return Math.abs(scale);
4251 }
Romain Guy06882f82009-06-10 13:36:04 -07004252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004253 public void setAnimationScale(int which, float scale) {
4254 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4255 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004256 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 }
4258
4259 if (scale < 0) scale = 0;
4260 else if (scale > 20) scale = 20;
4261 scale = Math.abs(scale);
4262 switch (which) {
4263 case 0: mWindowAnimationScale = fixScale(scale); break;
4264 case 1: mTransitionAnimationScale = fixScale(scale); break;
4265 }
Romain Guy06882f82009-06-10 13:36:04 -07004266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 // Persist setting
4268 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4269 }
Romain Guy06882f82009-06-10 13:36:04 -07004270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 public void setAnimationScales(float[] scales) {
4272 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4273 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004274 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 }
4276
4277 if (scales != null) {
4278 if (scales.length >= 1) {
4279 mWindowAnimationScale = fixScale(scales[0]);
4280 }
4281 if (scales.length >= 2) {
4282 mTransitionAnimationScale = fixScale(scales[1]);
4283 }
4284 }
Romain Guy06882f82009-06-10 13:36:04 -07004285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 // Persist setting
4287 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4288 }
Romain Guy06882f82009-06-10 13:36:04 -07004289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 public float getAnimationScale(int which) {
4291 switch (which) {
4292 case 0: return mWindowAnimationScale;
4293 case 1: return mTransitionAnimationScale;
4294 }
4295 return 0;
4296 }
Romain Guy06882f82009-06-10 13:36:04 -07004297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004298 public float[] getAnimationScales() {
4299 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 public int getSwitchState(int sw) {
4303 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4304 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004305 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004307 return mInputManager.getSwitchState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 }
Romain Guy06882f82009-06-10 13:36:04 -07004309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 public int getSwitchStateForDevice(int devid, int sw) {
4311 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4312 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004313 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004314 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004315 return mInputManager.getSwitchState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 }
Romain Guy06882f82009-06-10 13:36:04 -07004317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 public int getScancodeState(int sw) {
4319 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4320 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004321 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004323 return mInputManager.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 }
Romain Guy06882f82009-06-10 13:36:04 -07004325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 public int getScancodeStateForDevice(int devid, int sw) {
4327 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4328 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004329 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004331 return mInputManager.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
Romain Guy06882f82009-06-10 13:36:04 -07004333
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004334 public int getTrackballScancodeState(int sw) {
4335 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4336 "getTrackballScancodeState()")) {
4337 throw new SecurityException("Requires READ_INPUT_STATE permission");
4338 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004339 return mInputManager.getTrackballScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004340 }
4341
4342 public int getDPadScancodeState(int sw) {
4343 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4344 "getDPadScancodeState()")) {
4345 throw new SecurityException("Requires READ_INPUT_STATE permission");
4346 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004347 return mInputManager.getDPadScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004348 }
4349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 public int getKeycodeState(int sw) {
4351 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4352 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004353 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004355 return mInputManager.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 }
Romain Guy06882f82009-06-10 13:36:04 -07004357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 public int getKeycodeStateForDevice(int devid, int sw) {
4359 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4360 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004361 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004363 return mInputManager.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 }
Romain Guy06882f82009-06-10 13:36:04 -07004365
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004366 public int getTrackballKeycodeState(int sw) {
4367 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4368 "getTrackballKeycodeState()")) {
4369 throw new SecurityException("Requires READ_INPUT_STATE permission");
4370 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004371 return mInputManager.getTrackballKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004372 }
4373
4374 public int getDPadKeycodeState(int sw) {
4375 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4376 "getDPadKeycodeState()")) {
4377 throw new SecurityException("Requires READ_INPUT_STATE permission");
4378 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004379 return mInputManager.getDPadKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004380 }
4381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004383 return mInputManager.hasKeys(keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 }
Romain Guy06882f82009-06-10 13:36:04 -07004385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 public void enableScreenAfterBoot() {
4387 synchronized(mWindowMap) {
4388 if (mSystemBooted) {
4389 return;
4390 }
4391 mSystemBooted = true;
4392 }
Romain Guy06882f82009-06-10 13:36:04 -07004393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 performEnableScreen();
4395 }
Romain Guy06882f82009-06-10 13:36:04 -07004396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004397 public void enableScreenIfNeededLocked() {
4398 if (mDisplayEnabled) {
4399 return;
4400 }
4401 if (!mSystemBooted) {
4402 return;
4403 }
4404 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4405 }
Romain Guy06882f82009-06-10 13:36:04 -07004406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004407 public void performEnableScreen() {
4408 synchronized(mWindowMap) {
4409 if (mDisplayEnabled) {
4410 return;
4411 }
4412 if (!mSystemBooted) {
4413 return;
4414 }
Romain Guy06882f82009-06-10 13:36:04 -07004415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 // Don't enable the screen until all existing windows
4417 // have been drawn.
4418 final int N = mWindows.size();
4419 for (int i=0; i<N; i++) {
4420 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004421 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004422 return;
4423 }
4424 }
Romain Guy06882f82009-06-10 13:36:04 -07004425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 mDisplayEnabled = true;
4427 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004428 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004429 StringWriter sw = new StringWriter();
4430 PrintWriter pw = new PrintWriter(sw);
4431 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004432 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 }
4434 try {
4435 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4436 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004437 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 Parcel data = Parcel.obtain();
4439 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4440 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4441 data, null, 0);
4442 data.recycle();
4443 }
4444 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004445 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 }
4447 }
Romain Guy06882f82009-06-10 13:36:04 -07004448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004452 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4453 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 }
Romain Guy06882f82009-06-10 13:36:04 -07004455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 public void setInTouchMode(boolean mode) {
4457 synchronized(mWindowMap) {
4458 mInTouchMode = mode;
4459 }
4460 }
4461
Romain Guy06882f82009-06-10 13:36:04 -07004462 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004463 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004465 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004466 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 }
4468
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004469 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 }
Romain Guy06882f82009-06-10 13:36:04 -07004471
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004472 public void setRotationUnchecked(int rotation,
4473 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004474 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 long origId = Binder.clearCallingIdentity();
4478 boolean changed;
4479 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004480 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 }
Romain Guy06882f82009-06-10 13:36:04 -07004482
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004483 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 sendNewConfiguration();
4485 }
Romain Guy06882f82009-06-10 13:36:04 -07004486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 Binder.restoreCallingIdentity(origId);
4488 }
Romain Guy06882f82009-06-10 13:36:04 -07004489
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004490 /**
4491 * Apply a new rotation to the screen, respecting the requests of
4492 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4493 * re-evaluate the desired rotation.
4494 *
4495 * Returns null if the rotation has been changed. In this case YOU
4496 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4497 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004498 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 boolean changed;
4500 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4501 rotation = mRequestedRotation;
4502 } else {
4503 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004504 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004506 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004507 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004509 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004513 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 "Rotation changed to " + rotation
4515 + " from " + mRotation
4516 + " (forceApp=" + mForcedAppOrientation
4517 + ", req=" + mRequestedRotation + ")");
4518 mRotation = rotation;
4519 mWindowsFreezingScreen = true;
4520 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4521 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4522 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004523 mWaitingForConfig = true;
4524 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004526 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004527 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004529 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 }
4531 for (int i=mWindows.size()-1; i>=0; i--) {
4532 WindowState w = (WindowState)mWindows.get(i);
4533 if (w.mSurface != null) {
4534 w.mOrientationChanging = true;
4535 }
4536 }
4537 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4538 try {
4539 mRotationWatchers.get(i).onRotationChanged(rotation);
4540 } catch (RemoteException e) {
4541 }
4542 }
4543 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004545 return changed;
4546 }
Romain Guy06882f82009-06-10 13:36:04 -07004547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 public int getRotation() {
4549 return mRotation;
4550 }
4551
4552 public int watchRotation(IRotationWatcher watcher) {
4553 final IBinder watcherBinder = watcher.asBinder();
4554 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4555 public void binderDied() {
4556 synchronized (mWindowMap) {
4557 for (int i=0; i<mRotationWatchers.size(); i++) {
4558 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004559 IRotationWatcher removed = mRotationWatchers.remove(i);
4560 if (removed != null) {
4561 removed.asBinder().unlinkToDeath(this, 0);
4562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004563 i--;
4564 }
4565 }
4566 }
4567 }
4568 };
Romain Guy06882f82009-06-10 13:36:04 -07004569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004570 synchronized (mWindowMap) {
4571 try {
4572 watcher.asBinder().linkToDeath(dr, 0);
4573 mRotationWatchers.add(watcher);
4574 } catch (RemoteException e) {
4575 // Client died, no cleanup needed.
4576 }
Romain Guy06882f82009-06-10 13:36:04 -07004577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578 return mRotation;
4579 }
4580 }
4581
4582 /**
4583 * Starts the view server on the specified port.
4584 *
4585 * @param port The port to listener to.
4586 *
4587 * @return True if the server was successfully started, false otherwise.
4588 *
4589 * @see com.android.server.ViewServer
4590 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4591 */
4592 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004593 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004594 return false;
4595 }
4596
4597 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4598 return false;
4599 }
4600
4601 if (port < 1024) {
4602 return false;
4603 }
4604
4605 if (mViewServer != null) {
4606 if (!mViewServer.isRunning()) {
4607 try {
4608 return mViewServer.start();
4609 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004610 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004611 }
4612 }
4613 return false;
4614 }
4615
4616 try {
4617 mViewServer = new ViewServer(this, port);
4618 return mViewServer.start();
4619 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004620 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 }
4622 return false;
4623 }
4624
Romain Guy06882f82009-06-10 13:36:04 -07004625 private boolean isSystemSecure() {
4626 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4627 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4628 }
4629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 /**
4631 * Stops the view server if it exists.
4632 *
4633 * @return True if the server stopped, false if it wasn't started or
4634 * couldn't be stopped.
4635 *
4636 * @see com.android.server.ViewServer
4637 */
4638 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004639 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 return false;
4641 }
4642
4643 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4644 return false;
4645 }
4646
4647 if (mViewServer != null) {
4648 return mViewServer.stop();
4649 }
4650 return false;
4651 }
4652
4653 /**
4654 * Indicates whether the view server is running.
4655 *
4656 * @return True if the server is running, false otherwise.
4657 *
4658 * @see com.android.server.ViewServer
4659 */
4660 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004661 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662 return false;
4663 }
4664
4665 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4666 return false;
4667 }
4668
4669 return mViewServer != null && mViewServer.isRunning();
4670 }
4671
4672 /**
4673 * Lists all availble windows in the system. The listing is written in the
4674 * specified Socket's output stream with the following syntax:
4675 * windowHashCodeInHexadecimal windowName
4676 * Each line of the ouput represents a different window.
4677 *
4678 * @param client The remote client to send the listing to.
4679 * @return False if an error occured, true otherwise.
4680 */
4681 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004682 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 return false;
4684 }
4685
4686 boolean result = true;
4687
4688 Object[] windows;
4689 synchronized (mWindowMap) {
4690 windows = new Object[mWindows.size()];
4691 //noinspection unchecked
4692 windows = mWindows.toArray(windows);
4693 }
4694
4695 BufferedWriter out = null;
4696
4697 // Any uncaught exception will crash the system process
4698 try {
4699 OutputStream clientStream = client.getOutputStream();
4700 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4701
4702 final int count = windows.length;
4703 for (int i = 0; i < count; i++) {
4704 final WindowState w = (WindowState) windows[i];
4705 out.write(Integer.toHexString(System.identityHashCode(w)));
4706 out.write(' ');
4707 out.append(w.mAttrs.getTitle());
4708 out.write('\n');
4709 }
4710
4711 out.write("DONE.\n");
4712 out.flush();
4713 } catch (Exception e) {
4714 result = false;
4715 } finally {
4716 if (out != null) {
4717 try {
4718 out.close();
4719 } catch (IOException e) {
4720 result = false;
4721 }
4722 }
4723 }
4724
4725 return result;
4726 }
4727
4728 /**
4729 * Sends a command to a target window. The result of the command, if any, will be
4730 * written in the output stream of the specified socket.
4731 *
4732 * The parameters must follow this syntax:
4733 * windowHashcode extra
4734 *
4735 * Where XX is the length in characeters of the windowTitle.
4736 *
4737 * The first parameter is the target window. The window with the specified hashcode
4738 * will be the target. If no target can be found, nothing happens. The extra parameters
4739 * will be delivered to the target window and as parameters to the command itself.
4740 *
4741 * @param client The remote client to sent the result, if any, to.
4742 * @param command The command to execute.
4743 * @param parameters The command parameters.
4744 *
4745 * @return True if the command was successfully delivered, false otherwise. This does
4746 * not indicate whether the command itself was successful.
4747 */
4748 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004749 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004750 return false;
4751 }
4752
4753 boolean success = true;
4754 Parcel data = null;
4755 Parcel reply = null;
4756
4757 // Any uncaught exception will crash the system process
4758 try {
4759 // Find the hashcode of the window
4760 int index = parameters.indexOf(' ');
4761 if (index == -1) {
4762 index = parameters.length();
4763 }
4764 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004765 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766
4767 // Extract the command's parameter after the window description
4768 if (index < parameters.length()) {
4769 parameters = parameters.substring(index + 1);
4770 } else {
4771 parameters = "";
4772 }
4773
4774 final WindowManagerService.WindowState window = findWindow(hashCode);
4775 if (window == null) {
4776 return false;
4777 }
4778
4779 data = Parcel.obtain();
4780 data.writeInterfaceToken("android.view.IWindow");
4781 data.writeString(command);
4782 data.writeString(parameters);
4783 data.writeInt(1);
4784 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4785
4786 reply = Parcel.obtain();
4787
4788 final IBinder binder = window.mClient.asBinder();
4789 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4790 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4791
4792 reply.readException();
4793
4794 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004795 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 success = false;
4797 } finally {
4798 if (data != null) {
4799 data.recycle();
4800 }
4801 if (reply != null) {
4802 reply.recycle();
4803 }
4804 }
4805
4806 return success;
4807 }
4808
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004809 public void addWindowChangeListener(WindowChangeListener listener) {
4810 synchronized(mWindowMap) {
4811 mWindowChangeListeners.add(listener);
4812 }
4813 }
4814
4815 public void removeWindowChangeListener(WindowChangeListener listener) {
4816 synchronized(mWindowMap) {
4817 mWindowChangeListeners.remove(listener);
4818 }
4819 }
4820
4821 private void notifyWindowsChanged() {
4822 WindowChangeListener[] windowChangeListeners;
4823 synchronized(mWindowMap) {
4824 if(mWindowChangeListeners.isEmpty()) {
4825 return;
4826 }
4827 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4828 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4829 }
4830 int N = windowChangeListeners.length;
4831 for(int i = 0; i < N; i++) {
4832 windowChangeListeners[i].windowsChanged();
4833 }
4834 }
4835
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004836 private void notifyFocusChanged() {
4837 WindowChangeListener[] windowChangeListeners;
4838 synchronized(mWindowMap) {
4839 if(mWindowChangeListeners.isEmpty()) {
4840 return;
4841 }
4842 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4843 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4844 }
4845 int N = windowChangeListeners.length;
4846 for(int i = 0; i < N; i++) {
4847 windowChangeListeners[i].focusChanged();
4848 }
4849 }
4850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004851 private WindowState findWindow(int hashCode) {
4852 if (hashCode == -1) {
4853 return getFocusedWindow();
4854 }
4855
4856 synchronized (mWindowMap) {
4857 final ArrayList windows = mWindows;
4858 final int count = windows.size();
4859
4860 for (int i = 0; i < count; i++) {
4861 WindowState w = (WindowState) windows.get(i);
4862 if (System.identityHashCode(w) == hashCode) {
4863 return w;
4864 }
4865 }
4866 }
4867
4868 return null;
4869 }
4870
4871 /*
4872 * Instruct the Activity Manager to fetch the current configuration and broadcast
4873 * that to config-changed listeners if appropriate.
4874 */
4875 void sendNewConfiguration() {
4876 try {
4877 mActivityManager.updateConfiguration(null);
4878 } catch (RemoteException e) {
4879 }
4880 }
Romain Guy06882f82009-06-10 13:36:04 -07004881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004882 public Configuration computeNewConfiguration() {
4883 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004884 return computeNewConfigurationLocked();
4885 }
4886 }
Romain Guy06882f82009-06-10 13:36:04 -07004887
Dianne Hackbornc485a602009-03-24 22:39:49 -07004888 Configuration computeNewConfigurationLocked() {
4889 Configuration config = new Configuration();
4890 if (!computeNewConfigurationLocked(config)) {
4891 return null;
4892 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004893 return config;
4894 }
Romain Guy06882f82009-06-10 13:36:04 -07004895
Dianne Hackbornc485a602009-03-24 22:39:49 -07004896 boolean computeNewConfigurationLocked(Configuration config) {
4897 if (mDisplay == null) {
4898 return false;
4899 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004900
4901 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004902
4903 // Use the effective "visual" dimensions based on current rotation
4904 final boolean rotated = (mRotation == Surface.ROTATION_90
4905 || mRotation == Surface.ROTATION_270);
4906 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4907 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4908
Dianne Hackbornc485a602009-03-24 22:39:49 -07004909 int orientation = Configuration.ORIENTATION_SQUARE;
4910 if (dw < dh) {
4911 orientation = Configuration.ORIENTATION_PORTRAIT;
4912 } else if (dw > dh) {
4913 orientation = Configuration.ORIENTATION_LANDSCAPE;
4914 }
4915 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004916
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004917 DisplayMetrics dm = new DisplayMetrics();
4918 mDisplay.getMetrics(dm);
4919 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4920
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004921 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004922 // Note we only do this once because at this point we don't
4923 // expect the screen to change in this way at runtime, and want
4924 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004925 int longSize = dw;
4926 int shortSize = dh;
4927 if (longSize < shortSize) {
4928 int tmp = longSize;
4929 longSize = shortSize;
4930 shortSize = tmp;
4931 }
4932 longSize = (int)(longSize/dm.density);
4933 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004934
Dianne Hackborn723738c2009-06-25 19:48:04 -07004935 // These semi-magic numbers define our compatibility modes for
4936 // applications with different screens. Don't change unless you
4937 // make sure to test lots and lots of apps!
4938 if (longSize < 470) {
4939 // This is shorter than an HVGA normal density screen (which
4940 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004941 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4942 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004943 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004944 // What size is this screen screen?
4945 if (longSize >= 800 && shortSize >= 600) {
4946 // SVGA or larger screens at medium density are the point
4947 // at which we consider it to be an extra large screen.
4948 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4949 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004950 // VGA or larger screens at medium density are the point
4951 // at which we consider it to be a large screen.
4952 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4953 } else {
4954 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004955
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004956 // If this screen is wider than normal HVGA, or taller
4957 // than FWVGA, then for old apps we want to run in size
4958 // compatibility mode.
4959 if (shortSize > 321 || longSize > 570) {
4960 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4961 }
4962 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004963
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004964 // Is this a long screen?
4965 if (((longSize*3)/5) >= (shortSize-1)) {
4966 // Anything wider than WVGA (5:3) is considering to be long.
4967 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4968 } else {
4969 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4970 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004971 }
4972 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004973 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004974
Dianne Hackbornc485a602009-03-24 22:39:49 -07004975 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4976 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4977 mPolicy.adjustConfigurationLw(config);
4978 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004979 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981 // -------------------------------------------------------------
4982 // Input Events and Focus Management
4983 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07004984
Jeff Brown349703e2010-06-22 01:27:15 -07004985 InputMonitor mInputMonitor = new InputMonitor();
4986
4987 /* Tracks the progress of input dispatch and ensures that input dispatch state
4988 * is kept in sync with changes in window focus, visibility, registration, and
4989 * other relevant Window Manager state transitions. */
4990 final class InputMonitor {
4991 // Current window with input focus for keys and other non-touch events. May be null.
4992 private WindowState mInputFocus;
4993
4994 // When true, prevents input dispatch from proceeding until set to false again.
4995 private boolean mInputDispatchFrozen;
4996
4997 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
4998 private boolean mInputDispatchEnabled = true;
4999
5000 // Temporary list of windows information to provide to the input dispatcher.
5001 private InputWindowList mTempInputWindows = new InputWindowList();
5002
5003 // Temporary input application object to provide to the input dispatcher.
5004 private InputApplication mTempInputApplication = new InputApplication();
5005
5006 /* Notifies the window manager about a broken input channel.
5007 *
5008 * Called by the InputManager.
5009 */
5010 public void notifyInputChannelBroken(InputChannel inputChannel) {
5011 synchronized (mWindowMap) {
5012 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5013 if (windowState == null) {
5014 return; // irrelevant
5015 }
5016
5017 Slog.i(TAG, "WINDOW DIED " + windowState);
5018 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005019 }
5020 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005021
Jeff Brown349703e2010-06-22 01:27:15 -07005022 /* Notifies the window manager about an input channel that is not responding.
5023 * The method can either cause dispatching to be aborted by returning -2 or
5024 * return a new timeout in nanoseconds.
5025 *
5026 * Called by the InputManager.
5027 */
5028 public long notifyInputChannelANR(InputChannel inputChannel) {
5029 AppWindowToken token;
5030 synchronized (mWindowMap) {
5031 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5032 if (windowState == null) {
5033 return -2; // irrelevant, abort dispatching (-2)
5034 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005035
Jeff Brown349703e2010-06-22 01:27:15 -07005036 Slog.i(TAG, "Input event dispatching timed out sending to "
5037 + windowState.mAttrs.getTitle());
5038 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005039 }
5040
Jeff Brown349703e2010-06-22 01:27:15 -07005041 return notifyANRInternal(token);
5042 }
5043
5044 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5045 * by successfully delivering the event that originally timed out.
5046 *
5047 * Called by the InputManager.
5048 */
5049 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5050 // Nothing to do just now.
5051 // Just wait for the user to dismiss the ANR dialog.
5052 }
5053
5054 /* Notifies the window manager about an application that is not responding
5055 * in general rather than with respect to a particular input channel.
5056 * The method can either cause dispatching to be aborted by returning -2 or
5057 * return a new timeout in nanoseconds.
5058 *
5059 * Called by the InputManager.
5060 */
5061 public long notifyANR(Object token) {
5062 AppWindowToken appWindowToken = (AppWindowToken) token;
5063
5064 Slog.i(TAG, "Input event dispatching timed out sending to application "
5065 + appWindowToken.stringName);
5066 return notifyANRInternal(appWindowToken);
5067 }
5068
5069 private long notifyANRInternal(AppWindowToken token) {
5070 if (token != null && token.appToken != null) {
5071 try {
5072 // Notify the activity manager about the timeout and let it decide whether
5073 // to abort dispatching or keep waiting.
5074 boolean abort = token.appToken.keyDispatchingTimedOut();
5075 if (! abort) {
5076 // The activity manager declined to abort dispatching.
5077 // Wait a bit longer and timeout again later.
5078 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005079 }
Jeff Brown349703e2010-06-22 01:27:15 -07005080 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005081 }
5082 }
Jeff Brown349703e2010-06-22 01:27:15 -07005083 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005084 }
5085
Jeff Brown349703e2010-06-22 01:27:15 -07005086 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5087 synchronized (mWindowMap) {
5088 return getWindowStateForInputChannelLocked(inputChannel);
5089 }
5090 }
5091
5092 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5093 int windowCount = mWindows.size();
5094 for (int i = 0; i < windowCount; i++) {
5095 WindowState windowState = (WindowState) mWindows.get(i);
5096 if (windowState.mInputChannel == inputChannel) {
5097 return windowState;
5098 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005099 }
5100
Jeff Brown349703e2010-06-22 01:27:15 -07005101 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005102 }
5103
Jeff Brown349703e2010-06-22 01:27:15 -07005104 /* Updates the cached window information provided to the input dispatcher. */
5105 public void updateInputWindowsLw() {
5106 // Populate the input window list with information about all of the windows that
5107 // could potentially receive input.
5108 // As an optimization, we could try to prune the list of windows but this turns
5109 // out to be difficult because only the native code knows for sure which window
5110 // currently has touch focus.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005111 final ArrayList windows = mWindows;
5112 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005113 for (int i = N - 1; i >= 0; i--) {
5114 final WindowState child = (WindowState) windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005115 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005116 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005117 continue;
5118 }
5119
Jeff Brown349703e2010-06-22 01:27:15 -07005120 final int flags = child.mAttrs.flags;
5121 final int type = child.mAttrs.type;
5122
5123 final boolean hasFocus = (child == mInputFocus);
5124 final boolean isVisible = child.isVisibleLw();
5125 final boolean hasWallpaper = (child == mWallpaperTarget)
5126 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5127
5128 // Add a window to our list of input windows.
5129 final InputWindow inputWindow = mTempInputWindows.add();
5130 inputWindow.inputChannel = child.mInputChannel;
5131 inputWindow.layoutParamsFlags = flags;
5132 inputWindow.layoutParamsType = type;
5133 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5134 inputWindow.visible = isVisible;
5135 inputWindow.hasFocus = hasFocus;
5136 inputWindow.hasWallpaper = hasWallpaper;
5137 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5138 inputWindow.ownerPid = child.mSession.mPid;
5139 inputWindow.ownerUid = child.mSession.mUid;
5140
5141 final Rect frame = child.mFrame;
5142 inputWindow.frameLeft = frame.left;
5143 inputWindow.frameTop = frame.top;
5144
5145 switch (child.mTouchableInsets) {
5146 default:
5147 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5148 inputWindow.touchableAreaLeft = frame.left;
5149 inputWindow.touchableAreaTop = frame.top;
5150 inputWindow.touchableAreaRight = frame.right;
5151 inputWindow.touchableAreaBottom = frame.bottom;
5152 break;
5153
5154 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5155 Rect inset = child.mGivenContentInsets;
5156 inputWindow.touchableAreaLeft = frame.left + inset.left;
5157 inputWindow.touchableAreaTop = frame.top + inset.top;
5158 inputWindow.touchableAreaRight = frame.right - inset.right;
5159 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5160 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005161 }
Jeff Brown349703e2010-06-22 01:27:15 -07005162
5163 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5164 Rect inset = child.mGivenVisibleInsets;
5165 inputWindow.touchableAreaLeft = frame.left + inset.left;
5166 inputWindow.touchableAreaTop = frame.top + inset.top;
5167 inputWindow.touchableAreaRight = frame.right - inset.right;
5168 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005169 break;
5170 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005171 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005172 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005173
Jeff Brown349703e2010-06-22 01:27:15 -07005174 // Send windows to native code.
5175 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005176
Jeff Brown349703e2010-06-22 01:27:15 -07005177 // Clear the list in preparation for the next round.
5178 // Also avoids keeping InputChannel objects referenced unnecessarily.
5179 mTempInputWindows.clear();
5180 }
5181
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005182 /* Provides feedback for a virtual key down. */
5183 public void virtualKeyDownFeedback() {
5184 synchronized (mWindowMap) {
5185 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5186 }
5187 }
5188
Jeff Brown349703e2010-06-22 01:27:15 -07005189 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5190 * This essentially starts a .5 second timeout for the application to process
5191 * subsequent input events while waiting for the app switch to occur. If it takes longer
5192 * than this, the pending events will be dropped.
5193 */
5194 public void notifyAppSwitchComing() {
5195 // TODO Not implemented yet. Should go in the native side.
5196 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005197
5198 /* Notifies that the lid switch changed state. */
5199 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5200 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5201 }
5202
Jeff Brown349703e2010-06-22 01:27:15 -07005203 /* Provides an opportunity for the window manager policy to intercept early key
5204 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005205 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5206 int policyFlags, boolean isScreenOn) {
5207 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5208 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005209 }
5210
5211 /* Provides an opportunity for the window manager policy to process a key before
5212 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005213 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5214 int action, int flags, int keyCode, int metaState, int repeatCount,
5215 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005216 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005217 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5218 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005219 }
5220
5221 /* Called when the current input focus changes.
5222 * Layer assignment is assumed to be complete by the time this is called.
5223 */
5224 public void setInputFocusLw(WindowState newWindow) {
5225 if (DEBUG_INPUT) {
5226 Slog.d(TAG, "Input focus has changed to " + newWindow);
5227 }
5228
5229 if (newWindow != mInputFocus) {
5230 if (newWindow != null && newWindow.canReceiveKeys()) {
5231 // If the new input focus is an error window or appears above the current
5232 // input focus, preempt any pending synchronous dispatch so that we can
5233 // start delivering events to the new input focus as soon as possible.
5234 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5235 if (DEBUG_INPUT) {
5236 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005237 }
Jeff Brown349703e2010-06-22 01:27:15 -07005238 preemptInputDispatchLw();
5239 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5240 if (DEBUG_INPUT) {
5241 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5242 + "old win layer=" + mInputFocus.mLayer
5243 + ", new win layer=" + newWindow.mLayer);
5244 }
5245 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005246 }
Jeff Brown349703e2010-06-22 01:27:15 -07005247
5248 // Displaying a window implicitly causes dispatching to be unpaused.
5249 // This is to protect against bugs if someone pauses dispatching but
5250 // forgets to resume.
5251 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005252 }
Jeff Brown349703e2010-06-22 01:27:15 -07005253
5254 mInputFocus = newWindow;
5255 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005256 }
5257 }
5258
Jeff Brown349703e2010-06-22 01:27:15 -07005259 public void windowIsBecomingInvisibleLw(WindowState window) {
5260 // The window is becoming invisible. Preempt input dispatch in progress
5261 // so that the next window below can receive focus.
5262 if (window == mInputFocus) {
5263 mInputFocus = null;
5264 preemptInputDispatchLw();
5265 }
5266
5267 updateInputWindowsLw();
5268 }
5269
5270 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5271 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5272 * can begin.
5273 */
5274 private void preemptInputDispatchLw() {
5275 mInputManager.preemptInputDispatch();
5276 }
5277
5278 public void setFocusedAppLw(AppWindowToken newApp) {
5279 // Focused app has changed.
5280 if (newApp == null) {
5281 mInputManager.setFocusedApplication(null);
5282 } else {
5283 mTempInputApplication.name = newApp.toString();
5284 mTempInputApplication.dispatchingTimeoutNanos =
5285 newApp.inputDispatchingTimeoutNanos;
5286 mTempInputApplication.token = newApp;
5287
5288 mInputManager.setFocusedApplication(mTempInputApplication);
5289 }
5290 }
5291
Jeff Brown349703e2010-06-22 01:27:15 -07005292 public void pauseDispatchingLw(WindowToken window) {
5293 if (! window.paused) {
5294 if (DEBUG_INPUT) {
5295 Slog.v(TAG, "Pausing WindowToken " + window);
5296 }
5297
5298 window.paused = true;
5299 updateInputWindowsLw();
5300 }
5301 }
5302
5303 public void resumeDispatchingLw(WindowToken window) {
5304 if (window.paused) {
5305 if (DEBUG_INPUT) {
5306 Slog.v(TAG, "Resuming WindowToken " + window);
5307 }
5308
5309 window.paused = false;
5310 updateInputWindowsLw();
5311 }
5312 }
5313
5314 public void freezeInputDispatchingLw() {
5315 if (! mInputDispatchFrozen) {
5316 if (DEBUG_INPUT) {
5317 Slog.v(TAG, "Freezing input dispatching");
5318 }
5319
5320 mInputDispatchFrozen = true;
5321 updateInputDispatchModeLw();
5322 }
5323 }
5324
5325 public void thawInputDispatchingLw() {
5326 if (mInputDispatchFrozen) {
5327 if (DEBUG_INPUT) {
5328 Slog.v(TAG, "Thawing input dispatching");
5329 }
5330
5331 mInputDispatchFrozen = false;
5332 updateInputDispatchModeLw();
5333 }
5334 }
5335
5336 public void setEventDispatchingLw(boolean enabled) {
5337 if (mInputDispatchEnabled != enabled) {
5338 if (DEBUG_INPUT) {
5339 Slog.v(TAG, "Setting event dispatching to " + enabled);
5340 }
5341
5342 mInputDispatchEnabled = enabled;
5343 updateInputDispatchModeLw();
5344 }
5345 }
5346
5347 private void updateInputDispatchModeLw() {
5348 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5349 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005350 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005352 public void pauseKeyDispatching(IBinder _token) {
5353 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5354 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005355 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005356 }
5357
5358 synchronized (mWindowMap) {
5359 WindowToken token = mTokenMap.get(_token);
5360 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005361 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362 }
5363 }
5364 }
5365
5366 public void resumeKeyDispatching(IBinder _token) {
5367 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5368 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005369 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005370 }
5371
5372 synchronized (mWindowMap) {
5373 WindowToken token = mTokenMap.get(_token);
5374 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005375 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005376 }
5377 }
5378 }
5379
5380 public void setEventDispatching(boolean enabled) {
5381 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5382 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005383 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005384 }
5385
5386 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005387 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005388 }
5389 }
Romain Guy06882f82009-06-10 13:36:04 -07005390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005391 /**
5392 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005393 *
5394 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005395 * {@link SystemClock#uptimeMillis()} as the timebase.)
5396 * @param sync If true, wait for the event to be completed before returning to the caller.
5397 * @return Returns true if event was dispatched, false if it was dropped for any reason
5398 */
5399 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5400 long downTime = ev.getDownTime();
5401 long eventTime = ev.getEventTime();
5402
5403 int action = ev.getAction();
5404 int code = ev.getKeyCode();
5405 int repeatCount = ev.getRepeatCount();
5406 int metaState = ev.getMetaState();
5407 int deviceId = ev.getDeviceId();
5408 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005409 int source = ev.getSource();
5410
5411 if (source == InputDevice.SOURCE_UNKNOWN) {
5412 source = InputDevice.SOURCE_KEYBOARD;
5413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005414
5415 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5416 if (downTime == 0) downTime = eventTime;
5417
5418 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005419 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005420
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005421 final int pid = Binder.getCallingPid();
5422 final int uid = Binder.getCallingUid();
5423 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005424
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005425 final int result = mInputManager.injectKeyEvent(newEvent,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005426 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005427
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005428 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005429 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005430 }
5431
5432 /**
5433 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005434 *
5435 * @param ev A motion event describing the pointer (touch) action. (As noted in
5436 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005437 * {@link SystemClock#uptimeMillis()} as the timebase.)
5438 * @param sync If true, wait for the event to be completed before returning to the caller.
5439 * @return Returns true if event was dispatched, false if it was dropped for any reason
5440 */
5441 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005442 final int pid = Binder.getCallingPid();
5443 final int uid = Binder.getCallingUid();
5444 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005445
Jeff Brownc5ed5912010-07-14 18:48:53 -07005446 MotionEvent newEvent = MotionEvent.obtain(ev);
5447 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5448 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5449 }
5450
5451 final int result = mInputManager.injectMotionEvent(newEvent,
5452 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005453
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005454 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005455 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005456 }
Romain Guy06882f82009-06-10 13:36:04 -07005457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005458 /**
5459 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005460 *
5461 * @param ev A motion event describing the trackball action. (As noted in
5462 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005463 * {@link SystemClock#uptimeMillis()} as the timebase.)
5464 * @param sync If true, wait for the event to be completed before returning to the caller.
5465 * @return Returns true if event was dispatched, false if it was dropped for any reason
5466 */
5467 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005468 final int pid = Binder.getCallingPid();
5469 final int uid = Binder.getCallingUid();
5470 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005471
Jeff Brownc5ed5912010-07-14 18:48:53 -07005472 MotionEvent newEvent = MotionEvent.obtain(ev);
5473 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5474 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5475 }
5476
5477 final int result = mInputManager.injectMotionEvent(newEvent,
5478 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005479
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005480 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005481 return reportInjectionResult(result);
5482 }
5483
5484 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005485 switch (result) {
5486 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5487 Slog.w(TAG, "Input event injection permission denied.");
5488 throw new SecurityException(
5489 "Injecting to another application requires INJECT_EVENTS permission");
5490 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
5491 Slog.v(TAG, "Input event injection succeeded.");
5492 return true;
5493 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5494 Slog.w(TAG, "Input event injection timed out.");
5495 return false;
5496 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5497 default:
5498 Slog.w(TAG, "Input event injection failed.");
5499 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005501 }
Romain Guy06882f82009-06-10 13:36:04 -07005502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005503 private WindowState getFocusedWindow() {
5504 synchronized (mWindowMap) {
5505 return getFocusedWindowLocked();
5506 }
5507 }
5508
5509 private WindowState getFocusedWindowLocked() {
5510 return mCurrentFocus;
5511 }
Romain Guy06882f82009-06-10 13:36:04 -07005512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005513 public boolean detectSafeMode() {
5514 mSafeMode = mPolicy.detectSafeMode();
5515 return mSafeMode;
5516 }
Romain Guy06882f82009-06-10 13:36:04 -07005517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005518 public void systemReady() {
5519 mPolicy.systemReady();
5520 }
Romain Guy06882f82009-06-10 13:36:04 -07005521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005522 // -------------------------------------------------------------
5523 // Client Session State
5524 // -------------------------------------------------------------
5525
5526 private final class Session extends IWindowSession.Stub
5527 implements IBinder.DeathRecipient {
5528 final IInputMethodClient mClient;
5529 final IInputContext mInputContext;
5530 final int mUid;
5531 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005532 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005533 SurfaceSession mSurfaceSession;
5534 int mNumWindow = 0;
5535 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005537 public Session(IInputMethodClient client, IInputContext inputContext) {
5538 mClient = client;
5539 mInputContext = inputContext;
5540 mUid = Binder.getCallingUid();
5541 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005542 StringBuilder sb = new StringBuilder();
5543 sb.append("Session{");
5544 sb.append(Integer.toHexString(System.identityHashCode(this)));
5545 sb.append(" uid ");
5546 sb.append(mUid);
5547 sb.append("}");
5548 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005550 synchronized (mWindowMap) {
5551 if (mInputMethodManager == null && mHaveInputMethods) {
5552 IBinder b = ServiceManager.getService(
5553 Context.INPUT_METHOD_SERVICE);
5554 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5555 }
5556 }
5557 long ident = Binder.clearCallingIdentity();
5558 try {
5559 // Note: it is safe to call in to the input method manager
5560 // here because we are not holding our lock.
5561 if (mInputMethodManager != null) {
5562 mInputMethodManager.addClient(client, inputContext,
5563 mUid, mPid);
5564 } else {
5565 client.setUsingInputMethod(false);
5566 }
5567 client.asBinder().linkToDeath(this, 0);
5568 } catch (RemoteException e) {
5569 // The caller has died, so we can just forget about this.
5570 try {
5571 if (mInputMethodManager != null) {
5572 mInputMethodManager.removeClient(client);
5573 }
5574 } catch (RemoteException ee) {
5575 }
5576 } finally {
5577 Binder.restoreCallingIdentity(ident);
5578 }
5579 }
Romain Guy06882f82009-06-10 13:36:04 -07005580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005581 @Override
5582 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5583 throws RemoteException {
5584 try {
5585 return super.onTransact(code, data, reply, flags);
5586 } catch (RuntimeException e) {
5587 // Log all 'real' exceptions thrown to the caller
5588 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005589 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005590 }
5591 throw e;
5592 }
5593 }
5594
5595 public void binderDied() {
5596 // Note: it is safe to call in to the input method manager
5597 // here because we are not holding our lock.
5598 try {
5599 if (mInputMethodManager != null) {
5600 mInputMethodManager.removeClient(mClient);
5601 }
5602 } catch (RemoteException e) {
5603 }
5604 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005605 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005606 mClientDead = true;
5607 killSessionLocked();
5608 }
5609 }
5610
5611 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005612 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5613 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5614 outInputChannel);
5615 }
5616
5617 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005618 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005619 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005620 }
Romain Guy06882f82009-06-10 13:36:04 -07005621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005622 public void remove(IWindow window) {
5623 removeWindow(this, window);
5624 }
Romain Guy06882f82009-06-10 13:36:04 -07005625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005626 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5627 int requestedWidth, int requestedHeight, int viewFlags,
5628 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005629 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005630 return relayoutWindow(this, window, attrs,
5631 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005632 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005633 }
Romain Guy06882f82009-06-10 13:36:04 -07005634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005635 public void setTransparentRegion(IWindow window, Region region) {
5636 setTransparentRegionWindow(this, window, region);
5637 }
Romain Guy06882f82009-06-10 13:36:04 -07005638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005639 public void setInsets(IWindow window, int touchableInsets,
5640 Rect contentInsets, Rect visibleInsets) {
5641 setInsetsWindow(this, window, touchableInsets, contentInsets,
5642 visibleInsets);
5643 }
Romain Guy06882f82009-06-10 13:36:04 -07005644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005645 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5646 getWindowDisplayFrame(this, window, outDisplayFrame);
5647 }
Romain Guy06882f82009-06-10 13:36:04 -07005648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005649 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005650 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005651 TAG, "IWindow finishDrawing called for " + window);
5652 finishDrawingWindow(this, window);
5653 }
5654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005655 public void setInTouchMode(boolean mode) {
5656 synchronized(mWindowMap) {
5657 mInTouchMode = mode;
5658 }
5659 }
5660
5661 public boolean getInTouchMode() {
5662 synchronized(mWindowMap) {
5663 return mInTouchMode;
5664 }
5665 }
5666
5667 public boolean performHapticFeedback(IWindow window, int effectId,
5668 boolean always) {
5669 synchronized(mWindowMap) {
5670 long ident = Binder.clearCallingIdentity();
5671 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005672 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005673 windowForClientLocked(this, window, true),
5674 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005675 } finally {
5676 Binder.restoreCallingIdentity(ident);
5677 }
5678 }
5679 }
Romain Guy06882f82009-06-10 13:36:04 -07005680
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005681 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005682 synchronized(mWindowMap) {
5683 long ident = Binder.clearCallingIdentity();
5684 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005685 setWindowWallpaperPositionLocked(
5686 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005687 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005688 } finally {
5689 Binder.restoreCallingIdentity(ident);
5690 }
5691 }
5692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005693
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005694 public void wallpaperOffsetsComplete(IBinder window) {
5695 WindowManagerService.this.wallpaperOffsetsComplete(window);
5696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005697
Dianne Hackborn75804932009-10-20 20:15:20 -07005698 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5699 int z, Bundle extras, boolean sync) {
5700 synchronized(mWindowMap) {
5701 long ident = Binder.clearCallingIdentity();
5702 try {
5703 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005704 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005705 action, x, y, z, extras, sync);
5706 } finally {
5707 Binder.restoreCallingIdentity(ident);
5708 }
5709 }
5710 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005711
Dianne Hackborn75804932009-10-20 20:15:20 -07005712 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5713 WindowManagerService.this.wallpaperCommandComplete(window, result);
5714 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005716 void windowAddedLocked() {
5717 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005718 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005719 TAG, "First window added to " + this + ", creating SurfaceSession");
5720 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005721 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005722 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005723 mSessions.add(this);
5724 }
5725 mNumWindow++;
5726 }
5727
5728 void windowRemovedLocked() {
5729 mNumWindow--;
5730 killSessionLocked();
5731 }
Romain Guy06882f82009-06-10 13:36:04 -07005732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005733 void killSessionLocked() {
5734 if (mNumWindow <= 0 && mClientDead) {
5735 mSessions.remove(this);
5736 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005737 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005738 TAG, "Last window removed from " + this
5739 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005740 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005741 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005742 try {
5743 mSurfaceSession.kill();
5744 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005745 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005746 + mSurfaceSession + " in session " + this
5747 + ": " + e.toString());
5748 }
5749 mSurfaceSession = null;
5750 }
5751 }
5752 }
Romain Guy06882f82009-06-10 13:36:04 -07005753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005754 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005755 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5756 pw.print(" mClientDead="); pw.print(mClientDead);
5757 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005758 }
5759
5760 @Override
5761 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005762 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005763 }
5764 }
5765
5766 // -------------------------------------------------------------
5767 // Client Window State
5768 // -------------------------------------------------------------
5769
5770 private final class WindowState implements WindowManagerPolicy.WindowState {
5771 final Session mSession;
5772 final IWindow mClient;
5773 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005774 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005775 AppWindowToken mAppToken;
5776 AppWindowToken mTargetAppToken;
5777 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5778 final DeathRecipient mDeathRecipient;
5779 final WindowState mAttachedWindow;
5780 final ArrayList mChildWindows = new ArrayList();
5781 final int mBaseLayer;
5782 final int mSubLayer;
5783 final boolean mLayoutAttached;
5784 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005785 final boolean mIsWallpaper;
5786 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 int mViewVisibility;
5788 boolean mPolicyVisibility = true;
5789 boolean mPolicyVisibilityAfterAnim = true;
5790 boolean mAppFreezing;
5791 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005792 boolean mReportDestroySurface;
5793 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005794 boolean mAttachedHidden; // is our parent window hidden?
5795 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005796 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005797 int mRequestedWidth;
5798 int mRequestedHeight;
5799 int mLastRequestedWidth;
5800 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005801 int mLayer;
5802 int mAnimLayer;
5803 int mLastLayer;
5804 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005805 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005806 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005807
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005808 int mLayoutSeq = -1;
5809
5810 Configuration mConfiguration = null;
5811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005812 // Actual frame shown on-screen (may be modified by animation)
5813 final Rect mShownFrame = new Rect();
5814 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005816 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005817 * Set when we have changed the size of the surface, to know that
5818 * we must tell them application to resize (and thus redraw itself).
5819 */
5820 boolean mSurfaceResized;
5821
5822 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 * Insets that determine the actually visible area
5824 */
5825 final Rect mVisibleInsets = new Rect();
5826 final Rect mLastVisibleInsets = new Rect();
5827 boolean mVisibleInsetsChanged;
5828
5829 /**
5830 * Insets that are covered by system windows
5831 */
5832 final Rect mContentInsets = new Rect();
5833 final Rect mLastContentInsets = new Rect();
5834 boolean mContentInsetsChanged;
5835
5836 /**
5837 * Set to true if we are waiting for this window to receive its
5838 * given internal insets before laying out other windows based on it.
5839 */
5840 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005842 /**
5843 * These are the content insets that were given during layout for
5844 * this window, to be applied to windows behind it.
5845 */
5846 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005848 /**
5849 * These are the visible insets that were given during layout for
5850 * this window, to be applied to windows behind it.
5851 */
5852 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005854 /**
5855 * Flag indicating whether the touchable region should be adjusted by
5856 * the visible insets; if false the area outside the visible insets is
5857 * NOT touchable, so we must use those to adjust the frame during hit
5858 * tests.
5859 */
5860 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005862 // Current transformation being applied.
5863 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5864 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5865 float mHScale=1, mVScale=1;
5866 float mLastHScale=1, mLastVScale=1;
5867 final Matrix mTmpMatrix = new Matrix();
5868
5869 // "Real" frame that the application sees.
5870 final Rect mFrame = new Rect();
5871 final Rect mLastFrame = new Rect();
5872
5873 final Rect mContainingFrame = new Rect();
5874 final Rect mDisplayFrame = new Rect();
5875 final Rect mContentFrame = new Rect();
5876 final Rect mVisibleFrame = new Rect();
5877
5878 float mShownAlpha = 1;
5879 float mAlpha = 1;
5880 float mLastAlpha = 1;
5881
5882 // Set to true if, when the window gets displayed, it should perform
5883 // an enter animation.
5884 boolean mEnterAnimationPending;
5885
5886 // Currently running animation.
5887 boolean mAnimating;
5888 boolean mLocalAnimating;
5889 Animation mAnimation;
5890 boolean mAnimationIsEntrance;
5891 boolean mHasTransformation;
5892 boolean mHasLocalTransformation;
5893 final Transformation mTransformation = new Transformation();
5894
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005895 // If a window showing a wallpaper: the requested offset for the
5896 // wallpaper; if a wallpaper window: the currently applied offset.
5897 float mWallpaperX = -1;
5898 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005899
5900 // If a window showing a wallpaper: what fraction of the offset
5901 // range corresponds to a full virtual screen.
5902 float mWallpaperXStep = -1;
5903 float mWallpaperYStep = -1;
5904
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005905 // Wallpaper windows: pixels offset based on above variables.
5906 int mXOffset;
5907 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005909 // This is set after IWindowSession.relayout() has been called at
5910 // least once for the window. It allows us to detect the situation
5911 // where we don't yet have a surface, but should have one soon, so
5912 // we can give the window focus before waiting for the relayout.
5913 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 // This is set after the Surface has been created but before the
5916 // window has been drawn. During this time the surface is hidden.
5917 boolean mDrawPending;
5918
5919 // This is set after the window has finished drawing for the first
5920 // time but before its surface is shown. The surface will be
5921 // displayed when the next layout is run.
5922 boolean mCommitDrawPending;
5923
5924 // This is set during the time after the window's drawing has been
5925 // committed, and before its surface is actually shown. It is used
5926 // to delay showing the surface until all windows in a token are ready
5927 // to be shown.
5928 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005930 // Set when the window has been shown in the screen the first time.
5931 boolean mHasDrawn;
5932
5933 // Currently running an exit animation?
5934 boolean mExiting;
5935
5936 // Currently on the mDestroySurface list?
5937 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005939 // Completely remove from window manager after exit animation?
5940 boolean mRemoveOnExit;
5941
5942 // Set when the orientation is changing and this window has not yet
5943 // been updated for the new orientation.
5944 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005946 // Is this window now (or just being) removed?
5947 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005948
Dianne Hackborn16064f92010-03-25 00:47:24 -07005949 // For debugging, this is the last information given to the surface flinger.
5950 boolean mSurfaceShown;
5951 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
5952 int mSurfaceLayer;
5953 float mSurfaceAlpha;
5954
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005955 // Input channel
5956 InputChannel mInputChannel;
5957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005958 WindowState(Session s, IWindow c, WindowToken token,
5959 WindowState attachedWindow, WindowManager.LayoutParams a,
5960 int viewVisibility) {
5961 mSession = s;
5962 mClient = c;
5963 mToken = token;
5964 mAttrs.copyFrom(a);
5965 mViewVisibility = viewVisibility;
5966 DeathRecipient deathRecipient = new DeathRecipient();
5967 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005968 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005969 TAG, "Window " + this + " client=" + c.asBinder()
5970 + " token=" + token + " (" + mAttrs.token + ")");
5971 try {
5972 c.asBinder().linkToDeath(deathRecipient, 0);
5973 } catch (RemoteException e) {
5974 mDeathRecipient = null;
5975 mAttachedWindow = null;
5976 mLayoutAttached = false;
5977 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005978 mIsWallpaper = false;
5979 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005980 mBaseLayer = 0;
5981 mSubLayer = 0;
5982 return;
5983 }
5984 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07005985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005986 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
5987 mAttrs.type <= LAST_SUB_WINDOW)) {
5988 // The multiplier here is to reserve space for multiple
5989 // windows in the same type layer.
5990 mBaseLayer = mPolicy.windowTypeToLayerLw(
5991 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
5992 + TYPE_LAYER_OFFSET;
5993 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
5994 mAttachedWindow = attachedWindow;
5995 mAttachedWindow.mChildWindows.add(this);
5996 mLayoutAttached = mAttrs.type !=
5997 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
5998 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
5999 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006000 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6001 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006002 } else {
6003 // The multiplier here is to reserve space for multiple
6004 // windows in the same type layer.
6005 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6006 * TYPE_LAYER_MULTIPLIER
6007 + TYPE_LAYER_OFFSET;
6008 mSubLayer = 0;
6009 mAttachedWindow = null;
6010 mLayoutAttached = false;
6011 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6012 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006013 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6014 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006015 }
6016
6017 WindowState appWin = this;
6018 while (appWin.mAttachedWindow != null) {
6019 appWin = mAttachedWindow;
6020 }
6021 WindowToken appToken = appWin.mToken;
6022 while (appToken.appWindowToken == null) {
6023 WindowToken parent = mTokenMap.get(appToken.token);
6024 if (parent == null || appToken == parent) {
6025 break;
6026 }
6027 appToken = parent;
6028 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006029 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006030 mAppToken = appToken.appWindowToken;
6031
6032 mSurface = null;
6033 mRequestedWidth = 0;
6034 mRequestedHeight = 0;
6035 mLastRequestedWidth = 0;
6036 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006037 mXOffset = 0;
6038 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006039 mLayer = 0;
6040 mAnimLayer = 0;
6041 mLastLayer = 0;
6042 }
6043
6044 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006045 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006046 TAG, "Attaching " + this + " token=" + mToken
6047 + ", list=" + mToken.windows);
6048 mSession.windowAddedLocked();
6049 }
6050
6051 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6052 mHaveFrame = true;
6053
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006054 final Rect container = mContainingFrame;
6055 container.set(pf);
6056
6057 final Rect display = mDisplayFrame;
6058 display.set(df);
6059
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006060 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006061 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006062 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6063 display.intersect(mCompatibleScreenFrame);
6064 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006065 }
6066
6067 final int pw = container.right - container.left;
6068 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006069
6070 int w,h;
6071 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6072 w = mAttrs.width < 0 ? pw : mAttrs.width;
6073 h = mAttrs.height< 0 ? ph : mAttrs.height;
6074 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006075 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6076 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006077 }
Romain Guy06882f82009-06-10 13:36:04 -07006078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006079 final Rect content = mContentFrame;
6080 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006082 final Rect visible = mVisibleFrame;
6083 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006085 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006086 final int fw = frame.width();
6087 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006089 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6090 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6091
6092 Gravity.apply(mAttrs.gravity, w, h, container,
6093 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6094 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6095
6096 //System.out.println("Out: " + mFrame);
6097
6098 // Now make sure the window fits in the overall display.
6099 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 // Make sure the content and visible frames are inside of the
6102 // final window frame.
6103 if (content.left < frame.left) content.left = frame.left;
6104 if (content.top < frame.top) content.top = frame.top;
6105 if (content.right > frame.right) content.right = frame.right;
6106 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6107 if (visible.left < frame.left) visible.left = frame.left;
6108 if (visible.top < frame.top) visible.top = frame.top;
6109 if (visible.right > frame.right) visible.right = frame.right;
6110 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006112 final Rect contentInsets = mContentInsets;
6113 contentInsets.left = content.left-frame.left;
6114 contentInsets.top = content.top-frame.top;
6115 contentInsets.right = frame.right-content.right;
6116 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 final Rect visibleInsets = mVisibleInsets;
6119 visibleInsets.left = visible.left-frame.left;
6120 visibleInsets.top = visible.top-frame.top;
6121 visibleInsets.right = frame.right-visible.right;
6122 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006123
Dianne Hackborn284ac932009-08-28 10:34:25 -07006124 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6125 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006126 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006127 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006129 if (localLOGV) {
6130 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6131 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006132 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006133 + mRequestedWidth + ", mRequestedheight="
6134 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6135 + "): frame=" + mFrame.toShortString()
6136 + " ci=" + contentInsets.toShortString()
6137 + " vi=" + visibleInsets.toShortString());
6138 //}
6139 }
6140 }
Romain Guy06882f82009-06-10 13:36:04 -07006141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006142 public Rect getFrameLw() {
6143 return mFrame;
6144 }
6145
6146 public Rect getShownFrameLw() {
6147 return mShownFrame;
6148 }
6149
6150 public Rect getDisplayFrameLw() {
6151 return mDisplayFrame;
6152 }
6153
6154 public Rect getContentFrameLw() {
6155 return mContentFrame;
6156 }
6157
6158 public Rect getVisibleFrameLw() {
6159 return mVisibleFrame;
6160 }
6161
6162 public boolean getGivenInsetsPendingLw() {
6163 return mGivenInsetsPending;
6164 }
6165
6166 public Rect getGivenContentInsetsLw() {
6167 return mGivenContentInsets;
6168 }
Romain Guy06882f82009-06-10 13:36:04 -07006169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 public Rect getGivenVisibleInsetsLw() {
6171 return mGivenVisibleInsets;
6172 }
Romain Guy06882f82009-06-10 13:36:04 -07006173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006174 public WindowManager.LayoutParams getAttrs() {
6175 return mAttrs;
6176 }
6177
6178 public int getSurfaceLayer() {
6179 return mLayer;
6180 }
Romain Guy06882f82009-06-10 13:36:04 -07006181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006182 public IApplicationToken getAppToken() {
6183 return mAppToken != null ? mAppToken.appToken : null;
6184 }
Jeff Brown349703e2010-06-22 01:27:15 -07006185
6186 public long getInputDispatchingTimeoutNanos() {
6187 return mAppToken != null
6188 ? mAppToken.inputDispatchingTimeoutNanos
6189 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191
6192 public boolean hasAppShownWindows() {
6193 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6194 }
6195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006196 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006197 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006198 TAG, "Setting animation in " + this + ": " + anim);
6199 mAnimating = false;
6200 mLocalAnimating = false;
6201 mAnimation = anim;
6202 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6203 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6204 }
6205
6206 public void clearAnimation() {
6207 if (mAnimation != null) {
6208 mAnimating = true;
6209 mLocalAnimating = false;
6210 mAnimation = null;
6211 }
6212 }
Romain Guy06882f82009-06-10 13:36:04 -07006213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006214 Surface createSurfaceLocked() {
6215 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006216 mReportDestroySurface = false;
6217 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 mDrawPending = true;
6219 mCommitDrawPending = false;
6220 mReadyToShow = false;
6221 if (mAppToken != null) {
6222 mAppToken.allDrawn = false;
6223 }
6224
6225 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006226 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006227 flags |= Surface.PUSH_BUFFERS;
6228 }
6229
6230 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6231 flags |= Surface.SECURE;
6232 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006233 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006234 TAG, "Creating surface in session "
6235 + mSession.mSurfaceSession + " window " + this
6236 + " w=" + mFrame.width()
6237 + " h=" + mFrame.height() + " format="
6238 + mAttrs.format + " flags=" + flags);
6239
6240 int w = mFrame.width();
6241 int h = mFrame.height();
6242 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6243 // for a scaled surface, we always want the requested
6244 // size.
6245 w = mRequestedWidth;
6246 h = mRequestedHeight;
6247 }
6248
Romain Guy9825ec62009-10-01 00:58:09 -07006249 // Something is wrong and SurfaceFlinger will not like this,
6250 // try to revert to sane values
6251 if (w <= 0) w = 1;
6252 if (h <= 0) h = 1;
6253
Dianne Hackborn16064f92010-03-25 00:47:24 -07006254 mSurfaceShown = false;
6255 mSurfaceLayer = 0;
6256 mSurfaceAlpha = 1;
6257 mSurfaceX = 0;
6258 mSurfaceY = 0;
6259 mSurfaceW = w;
6260 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006261 try {
6262 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006263 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006264 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006265 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006266 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006267 + mSurface + " IN SESSION "
6268 + mSession.mSurfaceSession
6269 + ": pid=" + mSession.mPid + " format="
6270 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006271 + Integer.toHexString(flags)
6272 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006273 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006274 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006275 reclaimSomeSurfaceMemoryLocked(this, "create");
6276 return null;
6277 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006278 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006279 return null;
6280 }
Romain Guy06882f82009-06-10 13:36:04 -07006281
Joe Onorato8a9b2202010-02-26 18:56:32 -08006282 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006283 TAG, "Got surface: " + mSurface
6284 + ", set left=" + mFrame.left + " top=" + mFrame.top
6285 + ", animLayer=" + mAnimLayer);
6286 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006287 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006288 if (SHOW_TRANSACTIONS) logSurface(this,
6289 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6290 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6291 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 }
6293 Surface.openTransaction();
6294 try {
6295 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006296 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006297 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006298 mSurface.setPosition(mSurfaceX, mSurfaceY);
6299 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006300 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006301 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006302 mSurface.hide();
6303 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006304 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305 mSurface.setFlags(Surface.SURFACE_DITHER,
6306 Surface.SURFACE_DITHER);
6307 }
6308 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006309 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006310 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6311 }
6312 mLastHidden = true;
6313 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006314 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006315 Surface.closeTransaction();
6316 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006317 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006318 TAG, "Created surface " + this);
6319 }
6320 return mSurface;
6321 }
Romain Guy06882f82009-06-10 13:36:04 -07006322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006323 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 if (mAppToken != null && this == mAppToken.startingWindow) {
6325 mAppToken.startingDisplayed = false;
6326 }
Romain Guy06882f82009-06-10 13:36:04 -07006327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006328 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006329 mDrawPending = false;
6330 mCommitDrawPending = false;
6331 mReadyToShow = false;
6332
6333 int i = mChildWindows.size();
6334 while (i > 0) {
6335 i--;
6336 WindowState c = (WindowState)mChildWindows.get(i);
6337 c.mAttachedHidden = true;
Jeff Brown349703e2010-06-22 01:27:15 -07006338
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006339 mInputMonitor.windowIsBecomingInvisibleLw(c);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006340 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006341
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006342 if (mReportDestroySurface) {
6343 mReportDestroySurface = false;
6344 mSurfacePendingDestroy = true;
6345 try {
6346 mClient.dispatchGetNewSurface();
6347 // We'll really destroy on the next time around.
6348 return;
6349 } catch (RemoteException e) {
6350 }
6351 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006353 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006354 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006355 RuntimeException e = null;
6356 if (!HIDE_STACK_CRAWLS) {
6357 e = new RuntimeException();
6358 e.fillInStackTrace();
6359 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006360 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006361 + mSurface + ", session " + mSession, e);
6362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006363 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006364 RuntimeException e = null;
6365 if (!HIDE_STACK_CRAWLS) {
6366 e = new RuntimeException();
6367 e.fillInStackTrace();
6368 }
6369 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006371 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006373 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 + " surface " + mSurface + " session " + mSession
6375 + ": " + e.toString());
6376 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006377
Dianne Hackborn16064f92010-03-25 00:47:24 -07006378 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006380 }
6381 }
6382
6383 boolean finishDrawingLocked() {
6384 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006385 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 TAG, "finishDrawingLocked: " + mSurface);
6387 mCommitDrawPending = true;
6388 mDrawPending = false;
6389 return true;
6390 }
6391 return false;
6392 }
6393
6394 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006395 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006396 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006398 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006399 }
6400 mCommitDrawPending = false;
6401 mReadyToShow = true;
6402 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6403 final AppWindowToken atoken = mAppToken;
6404 if (atoken == null || atoken.allDrawn || starting) {
6405 performShowLocked();
6406 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006407 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 }
6409
6410 // This must be called while inside a transaction.
6411 boolean performShowLocked() {
6412 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006413 RuntimeException e = null;
6414 if (!HIDE_STACK_CRAWLS) {
6415 e = new RuntimeException();
6416 e.fillInStackTrace();
6417 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006418 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6420 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6421 }
6422 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006423 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6424 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006425 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006426 + " during animation: policyVis=" + mPolicyVisibility
6427 + " attHidden=" + mAttachedHidden
6428 + " tok.hiddenRequested="
6429 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006430 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006431 + (mAppToken != null ? mAppToken.hidden : false)
6432 + " animating=" + mAnimating
6433 + " tok animating="
6434 + (mAppToken != null ? mAppToken.animating : false));
6435 if (!showSurfaceRobustlyLocked(this)) {
6436 return false;
6437 }
6438 mLastAlpha = -1;
6439 mHasDrawn = true;
6440 mLastHidden = false;
6441 mReadyToShow = false;
6442 enableScreenIfNeededLocked();
6443
6444 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006446 int i = mChildWindows.size();
6447 while (i > 0) {
6448 i--;
6449 WindowState c = (WindowState)mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006450 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006452 if (c.mSurface != null) {
6453 c.performShowLocked();
6454 // It hadn't been shown, which means layout not
6455 // performed on it, so now we want to make sure to
6456 // do a layout. If called from within the transaction
6457 // loop, this will cause it to restart with a new
6458 // layout.
6459 mLayoutNeeded = true;
6460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006461 }
6462 }
Romain Guy06882f82009-06-10 13:36:04 -07006463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006464 if (mAttrs.type != TYPE_APPLICATION_STARTING
6465 && mAppToken != null) {
6466 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006467
Dianne Hackborn248b1882009-09-16 16:46:44 -07006468 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006469 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006470 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006471 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006472 // If this initial window is animating, stop it -- we
6473 // will do an animation to reveal it from behind the
6474 // starting window, so there is no need for it to also
6475 // be doing its own stuff.
6476 if (mAnimation != null) {
6477 mAnimation = null;
6478 // Make sure we clean up the animation.
6479 mAnimating = true;
6480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 mFinishedStarting.add(mAppToken);
6482 mH.sendEmptyMessage(H.FINISHED_STARTING);
6483 }
6484 mAppToken.updateReportedVisibilityLocked();
6485 }
6486 }
6487 return true;
6488 }
Romain Guy06882f82009-06-10 13:36:04 -07006489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 // This must be called while inside a transaction. Returns true if
6491 // there is more animation to run.
6492 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006493 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6497 mHasTransformation = true;
6498 mHasLocalTransformation = true;
6499 if (!mLocalAnimating) {
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, "Starting animation in " + this +
6502 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6503 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6504 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6505 mAnimation.setStartTime(currentTime);
6506 mLocalAnimating = true;
6507 mAnimating = true;
6508 }
6509 mTransformation.clear();
6510 final boolean more = mAnimation.getTransformation(
6511 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006512 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 TAG, "Stepped animation in " + this +
6514 ": more=" + more + ", xform=" + mTransformation);
6515 if (more) {
6516 // we're not done!
6517 return true;
6518 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006519 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006520 TAG, "Finished animation in " + this +
6521 " @ " + currentTime);
6522 mAnimation = null;
6523 //WindowManagerService.this.dump();
6524 }
6525 mHasLocalTransformation = false;
6526 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006527 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006528 // When our app token is animating, we kind-of pretend like
6529 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6530 // part of this check means that we will only do this if
6531 // our window is not currently exiting, or it is not
6532 // locally animating itself. The idea being that one that
6533 // is exiting and doing a local animation should be removed
6534 // once that animation is done.
6535 mAnimating = true;
6536 mHasTransformation = true;
6537 mTransformation.clear();
6538 return false;
6539 } else if (mHasTransformation) {
6540 // Little trick to get through the path below to act like
6541 // we have finished an animation.
6542 mAnimating = true;
6543 } else if (isAnimating()) {
6544 mAnimating = true;
6545 }
6546 } else if (mAnimation != null) {
6547 // If the display is frozen, and there is a pending animation,
6548 // clear it and make sure we run the cleanup code.
6549 mAnimating = true;
6550 mLocalAnimating = true;
6551 mAnimation = null;
6552 }
Romain Guy06882f82009-06-10 13:36:04 -07006553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006554 if (!mAnimating && !mLocalAnimating) {
6555 return false;
6556 }
6557
Joe Onorato8a9b2202010-02-26 18:56:32 -08006558 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006559 TAG, "Animation done in " + this + ": exiting=" + mExiting
6560 + ", reportedVisible="
6561 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 mAnimating = false;
6564 mLocalAnimating = false;
6565 mAnimation = null;
6566 mAnimLayer = mLayer;
6567 if (mIsImWindow) {
6568 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006569 } else if (mIsWallpaper) {
6570 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006572 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 + " anim layer: " + mAnimLayer);
6574 mHasTransformation = false;
6575 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006576 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6577 if (DEBUG_VISIBILITY) {
6578 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6579 + mPolicyVisibilityAfterAnim);
6580 }
6581 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6582 if (!mPolicyVisibility) {
6583 if (mCurrentFocus == this) {
6584 mFocusMayChange = true;
6585 }
6586 // Window is no longer visible -- make sure if we were waiting
6587 // for it to be displayed before enabling the display, that
6588 // we allow the display to be enabled now.
6589 enableScreenIfNeededLocked();
6590 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006592 mTransformation.clear();
6593 if (mHasDrawn
6594 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6595 && mAppToken != null
6596 && mAppToken.firstWindowDrawn
6597 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006598 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006599 + mToken + ": first real window done animating");
6600 mFinishedStarting.add(mAppToken);
6601 mH.sendEmptyMessage(H.FINISHED_STARTING);
6602 }
Romain Guy06882f82009-06-10 13:36:04 -07006603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006604 finishExit();
6605
6606 if (mAppToken != null) {
6607 mAppToken.updateReportedVisibilityLocked();
6608 }
6609
6610 return false;
6611 }
6612
6613 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006614 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 TAG, "finishExit in " + this
6616 + ": exiting=" + mExiting
6617 + " remove=" + mRemoveOnExit
6618 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 final int N = mChildWindows.size();
6621 for (int i=0; i<N; i++) {
6622 ((WindowState)mChildWindows.get(i)).finishExit();
6623 }
Romain Guy06882f82009-06-10 13:36:04 -07006624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006625 if (!mExiting) {
6626 return;
6627 }
Romain Guy06882f82009-06-10 13:36:04 -07006628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 if (isWindowAnimating()) {
6630 return;
6631 }
6632
Joe Onorato8a9b2202010-02-26 18:56:32 -08006633 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006634 TAG, "Exit animation finished in " + this
6635 + ": remove=" + mRemoveOnExit);
6636 if (mSurface != null) {
6637 mDestroySurface.add(this);
6638 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006639 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006640 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006641 try {
6642 mSurface.hide();
6643 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006644 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006645 }
6646 mLastHidden = true;
Jeff Brown349703e2010-06-22 01:27:15 -07006647
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006648 for (int i=0; i<N; i++) {
6649 mInputMonitor.windowIsBecomingInvisibleLw((WindowState)mChildWindows.get(i));
Jeff Brown349703e2010-06-22 01:27:15 -07006650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 }
6652 mExiting = false;
6653 if (mRemoveOnExit) {
6654 mPendingRemove.add(this);
6655 mRemoveOnExit = false;
6656 }
6657 }
Romain Guy06882f82009-06-10 13:36:04 -07006658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006659 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6660 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6661 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6662 if (dtdx < -.000001f || dtdx > .000001f) return false;
6663 if (dsdy < -.000001f || dsdy > .000001f) return false;
6664 return true;
6665 }
Romain Guy06882f82009-06-10 13:36:04 -07006666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006667 void computeShownFrameLocked() {
6668 final boolean selfTransformation = mHasLocalTransformation;
6669 Transformation attachedTransformation =
6670 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6671 ? mAttachedWindow.mTransformation : null;
6672 Transformation appTransformation =
6673 (mAppToken != null && mAppToken.hasTransformation)
6674 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006675
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006676 // Wallpapers are animated based on the "real" window they
6677 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006678 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006679 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006680 if (mWallpaperTarget.mHasLocalTransformation &&
6681 mWallpaperTarget.mAnimation != null &&
6682 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006683 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006684 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006685 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006686 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006687 }
6688 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006689 mWallpaperTarget.mAppToken.hasTransformation &&
6690 mWallpaperTarget.mAppToken.animation != null &&
6691 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006692 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006693 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006694 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006695 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006696 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006697 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 if (selfTransformation || attachedTransformation != null
6700 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006701 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 final Rect frame = mFrame;
6703 final float tmpFloats[] = mTmpFloats;
6704 final Matrix tmpMatrix = mTmpMatrix;
6705
6706 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006707 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006708 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006709 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006710 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006711 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006713 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006714 }
6715 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006716 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 }
6718
6719 // "convert" it into SurfaceFlinger's format
6720 // (a 2x2 matrix + an offset)
6721 // Here we must not transform the position of the surface
6722 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006723 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 tmpMatrix.getValues(tmpFloats);
6726 mDsDx = tmpFloats[Matrix.MSCALE_X];
6727 mDtDx = tmpFloats[Matrix.MSKEW_X];
6728 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6729 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006730 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6731 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 int w = frame.width();
6733 int h = frame.height();
6734 mShownFrame.set(x, y, x+w, y+h);
6735
6736 // Now set the alpha... but because our current hardware
6737 // can't do alpha transformation on a non-opaque surface,
6738 // turn it off if we are running an animation that is also
6739 // transforming since it is more important to have that
6740 // animation be smooth.
6741 mShownAlpha = mAlpha;
6742 if (!mLimitedAlphaCompositing
6743 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6744 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6745 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006746 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 if (selfTransformation) {
6748 mShownAlpha *= mTransformation.getAlpha();
6749 }
6750 if (attachedTransformation != null) {
6751 mShownAlpha *= attachedTransformation.getAlpha();
6752 }
6753 if (appTransformation != null) {
6754 mShownAlpha *= appTransformation.getAlpha();
6755 }
6756 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006757 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006758 }
Romain Guy06882f82009-06-10 13:36:04 -07006759
Joe Onorato8a9b2202010-02-26 18:56:32 -08006760 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006761 TAG, "Continuing animation in " + this +
6762 ": " + mShownFrame +
6763 ", alpha=" + mTransformation.getAlpha());
6764 return;
6765 }
Romain Guy06882f82009-06-10 13:36:04 -07006766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006768 if (mXOffset != 0 || mYOffset != 0) {
6769 mShownFrame.offset(mXOffset, mYOffset);
6770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 mShownAlpha = mAlpha;
6772 mDsDx = 1;
6773 mDtDx = 0;
6774 mDsDy = 0;
6775 mDtDy = 1;
6776 }
Romain Guy06882f82009-06-10 13:36:04 -07006777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006778 /**
6779 * Is this window visible? It is not visible if there is no
6780 * surface, or we are in the process of running an exit animation
6781 * that will remove the surface, or its app token has been hidden.
6782 */
6783 public boolean isVisibleLw() {
6784 final AppWindowToken atoken = mAppToken;
6785 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6786 && (atoken == null || !atoken.hiddenRequested)
6787 && !mExiting && !mDestroying;
6788 }
6789
6790 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006791 * Like {@link #isVisibleLw}, but also counts a window that is currently
6792 * "hidden" behind the keyguard as visible. This allows us to apply
6793 * things like window flags that impact the keyguard.
6794 * XXX I am starting to think we need to have ANOTHER visibility flag
6795 * for this "hidden behind keyguard" state rather than overloading
6796 * mPolicyVisibility. Ungh.
6797 */
6798 public boolean isVisibleOrBehindKeyguardLw() {
6799 final AppWindowToken atoken = mAppToken;
6800 return mSurface != null && !mAttachedHidden
6801 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006802 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006803 && !mExiting && !mDestroying;
6804 }
6805
6806 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 * Is this window visible, ignoring its app token? It is not visible
6808 * if there is no surface, or we are in the process of running an exit animation
6809 * that will remove the surface.
6810 */
6811 public boolean isWinVisibleLw() {
6812 final AppWindowToken atoken = mAppToken;
6813 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6814 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6815 && !mExiting && !mDestroying;
6816 }
6817
6818 /**
6819 * The same as isVisible(), but follows the current hidden state of
6820 * the associated app token, not the pending requested hidden state.
6821 */
6822 boolean isVisibleNow() {
6823 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006824 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 }
6826
6827 /**
6828 * Same as isVisible(), but we also count it as visible between the
6829 * call to IWindowSession.add() and the first relayout().
6830 */
6831 boolean isVisibleOrAdding() {
6832 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006833 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6835 && mPolicyVisibility && !mAttachedHidden
6836 && (atoken == null || !atoken.hiddenRequested)
6837 && !mExiting && !mDestroying;
6838 }
6839
6840 /**
6841 * Is this window currently on-screen? It is on-screen either if it
6842 * is visible or it is currently running an animation before no longer
6843 * being visible.
6844 */
6845 boolean isOnScreen() {
6846 final AppWindowToken atoken = mAppToken;
6847 if (atoken != null) {
6848 return mSurface != null && mPolicyVisibility && !mDestroying
6849 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006850 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851 } else {
6852 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006853 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 }
6855 }
Romain Guy06882f82009-06-10 13:36:04 -07006856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 /**
6858 * Like isOnScreen(), but we don't return true if the window is part
6859 * of a transition that has not yet been started.
6860 */
6861 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006862 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006863 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006864 return false;
6865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006867 final boolean animating = atoken != null
6868 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006870 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6871 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006872 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006873 }
6874
6875 /** Is the window or its container currently animating? */
6876 boolean isAnimating() {
6877 final WindowState attached = mAttachedWindow;
6878 final AppWindowToken atoken = mAppToken;
6879 return mAnimation != null
6880 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006881 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006882 (atoken.animation != null
6883 || atoken.inPendingTransaction));
6884 }
6885
6886 /** Is this window currently animating? */
6887 boolean isWindowAnimating() {
6888 return mAnimation != null;
6889 }
6890
6891 /**
6892 * Like isOnScreen, but returns false if the surface hasn't yet
6893 * been drawn.
6894 */
6895 public boolean isDisplayedLw() {
6896 final AppWindowToken atoken = mAppToken;
6897 return mSurface != null && mPolicyVisibility && !mDestroying
6898 && !mDrawPending && !mCommitDrawPending
6899 && ((!mAttachedHidden &&
6900 (atoken == null || !atoken.hiddenRequested))
6901 || mAnimating);
6902 }
6903
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006904 /**
6905 * Returns true if the window has a surface that it has drawn a
6906 * complete UI in to.
6907 */
6908 public boolean isDrawnLw() {
6909 final AppWindowToken atoken = mAppToken;
6910 return mSurface != null && !mDestroying
6911 && !mDrawPending && !mCommitDrawPending;
6912 }
6913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6915 boolean shownFrame, boolean onlyOpaque) {
6916 if (mSurface == null) {
6917 return false;
6918 }
6919 if (mAppToken != null && !mAppToken.appFullscreen) {
6920 return false;
6921 }
6922 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6923 return false;
6924 }
6925 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006926
6927 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6928 return frame.left <= mCompatibleScreenFrame.left &&
6929 frame.top <= mCompatibleScreenFrame.top &&
6930 frame.right >= mCompatibleScreenFrame.right &&
6931 frame.bottom >= mCompatibleScreenFrame.bottom;
6932 } else {
6933 return frame.left <= 0 && frame.top <= 0
6934 && frame.right >= screenWidth
6935 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006937 }
Romain Guy06882f82009-06-10 13:36:04 -07006938
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006939 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006940 * Return true if the window is opaque and fully drawn. This indicates
6941 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006942 */
6943 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006944 return (mAttrs.format == PixelFormat.OPAQUE
6945 || mAttrs.type == TYPE_WALLPAPER)
6946 && mSurface != null && mAnimation == null
6947 && (mAppToken == null || mAppToken.animation == null)
6948 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006949 }
6950
6951 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6952 return
6953 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006954 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6955 // only if it's visible
6956 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006957 // and only if the application fills the compatible screen
6958 mFrame.left <= mCompatibleScreenFrame.left &&
6959 mFrame.top <= mCompatibleScreenFrame.top &&
6960 mFrame.right >= mCompatibleScreenFrame.right &&
6961 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006962 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006963 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006964 }
6965
6966 boolean isFullscreen(int screenWidth, int screenHeight) {
6967 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006968 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006969 }
6970
6971 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07006972 disposeInputChannel();
6973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 if (mAttachedWindow != null) {
6975 mAttachedWindow.mChildWindows.remove(this);
6976 }
6977 destroySurfaceLocked();
6978 mSession.windowRemovedLocked();
6979 try {
6980 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
6981 } catch (RuntimeException e) {
6982 // Ignore if it has already been removed (usually because
6983 // we are doing this as part of processing a death note.)
6984 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07006985 }
6986
6987 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006988 if (mInputChannel != null) {
6989 mInputManager.unregisterInputChannel(mInputChannel);
6990
6991 mInputChannel.dispose();
6992 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006993 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006994 }
6995
6996 private class DeathRecipient implements IBinder.DeathRecipient {
6997 public void binderDied() {
6998 try {
6999 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007000 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007001 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007002 if (win != null) {
7003 removeWindowLocked(mSession, win);
7004 }
7005 }
7006 } catch (IllegalArgumentException ex) {
7007 // This will happen if the window has already been
7008 // removed.
7009 }
7010 }
7011 }
7012
7013 /** Returns true if this window desires key events. */
7014 public final boolean canReceiveKeys() {
7015 return isVisibleOrAdding()
7016 && (mViewVisibility == View.VISIBLE)
7017 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7018 }
7019
7020 public boolean hasDrawnLw() {
7021 return mHasDrawn;
7022 }
7023
7024 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007025 return showLw(doAnimation, true);
7026 }
7027
7028 boolean showLw(boolean doAnimation, boolean requestAnim) {
7029 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7030 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007031 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007032 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007033 if (doAnimation) {
7034 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7035 + mPolicyVisibility + " mAnimation=" + mAnimation);
7036 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7037 doAnimation = false;
7038 } else if (mPolicyVisibility && mAnimation == null) {
7039 // Check for the case where we are currently visible and
7040 // not animating; we do not want to do animation at such a
7041 // point to become visible when we already are.
7042 doAnimation = false;
7043 }
7044 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007045 mPolicyVisibility = true;
7046 mPolicyVisibilityAfterAnim = true;
7047 if (doAnimation) {
7048 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7049 }
7050 if (requestAnim) {
7051 requestAnimationLocked(0);
7052 }
7053 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 }
7055
7056 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007057 return hideLw(doAnimation, true);
7058 }
7059
7060 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007061 if (doAnimation) {
7062 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7063 doAnimation = false;
7064 }
7065 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007066 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7067 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007068 if (!current) {
7069 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007071 if (doAnimation) {
7072 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7073 if (mAnimation == null) {
7074 doAnimation = false;
7075 }
7076 }
7077 if (doAnimation) {
7078 mPolicyVisibilityAfterAnim = false;
7079 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007080 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007081 mPolicyVisibilityAfterAnim = false;
7082 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007083 // Window is no longer visible -- make sure if we were waiting
7084 // for it to be displayed before enabling the display, that
7085 // we allow the display to be enabled now.
7086 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007087 if (mCurrentFocus == this) {
7088 mFocusMayChange = true;
7089 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007090 }
7091 if (requestAnim) {
7092 requestAnimationLocked(0);
7093 }
7094 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095 }
7096
7097 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007098 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7099 pw.print(" mClient="); pw.println(mClient.asBinder());
7100 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7101 if (mAttachedWindow != null || mLayoutAttached) {
7102 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7103 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7104 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007105 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7106 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7107 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007108 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7109 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007110 }
7111 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7112 pw.print(" mSubLayer="); pw.print(mSubLayer);
7113 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7114 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7115 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7116 pw.print("="); pw.print(mAnimLayer);
7117 pw.print(" mLastLayer="); pw.println(mLastLayer);
7118 if (mSurface != null) {
7119 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007120 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7121 pw.print(" layer="); pw.print(mSurfaceLayer);
7122 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7123 pw.print(" rect=("); pw.print(mSurfaceX);
7124 pw.print(","); pw.print(mSurfaceY);
7125 pw.print(") "); pw.print(mSurfaceW);
7126 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007127 }
7128 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7129 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7130 if (mAppToken != null) {
7131 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7132 }
7133 if (mTargetAppToken != null) {
7134 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7135 }
7136 pw.print(prefix); pw.print("mViewVisibility=0x");
7137 pw.print(Integer.toHexString(mViewVisibility));
7138 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007139 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7140 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007141 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7142 pw.print(prefix); pw.print("mPolicyVisibility=");
7143 pw.print(mPolicyVisibility);
7144 pw.print(" mPolicyVisibilityAfterAnim=");
7145 pw.print(mPolicyVisibilityAfterAnim);
7146 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7147 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007148 if (!mRelayoutCalled) {
7149 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7150 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007151 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007152 pw.print(" h="); pw.print(mRequestedHeight);
7153 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007154 if (mXOffset != 0 || mYOffset != 0) {
7155 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7156 pw.print(" y="); pw.println(mYOffset);
7157 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007158 pw.print(prefix); pw.print("mGivenContentInsets=");
7159 mGivenContentInsets.printShortString(pw);
7160 pw.print(" mGivenVisibleInsets=");
7161 mGivenVisibleInsets.printShortString(pw);
7162 pw.println();
7163 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7164 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7165 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7166 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007167 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007168 pw.print(prefix); pw.print("mShownFrame=");
7169 mShownFrame.printShortString(pw);
7170 pw.print(" last="); mLastShownFrame.printShortString(pw);
7171 pw.println();
7172 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7173 pw.print(" last="); mLastFrame.printShortString(pw);
7174 pw.println();
7175 pw.print(prefix); pw.print("mContainingFrame=");
7176 mContainingFrame.printShortString(pw);
7177 pw.print(" mDisplayFrame=");
7178 mDisplayFrame.printShortString(pw);
7179 pw.println();
7180 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7181 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7182 pw.println();
7183 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7184 pw.print(" last="); mLastContentInsets.printShortString(pw);
7185 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7186 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7187 pw.println();
7188 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7189 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7190 pw.print(" mAlpha="); pw.print(mAlpha);
7191 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7192 }
7193 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7194 || mAnimation != null) {
7195 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7196 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7197 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7198 pw.print(" mAnimation="); pw.println(mAnimation);
7199 }
7200 if (mHasTransformation || mHasLocalTransformation) {
7201 pw.print(prefix); pw.print("XForm: has=");
7202 pw.print(mHasTransformation);
7203 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7204 pw.print(" "); mTransformation.printShortString(pw);
7205 pw.println();
7206 }
7207 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7208 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7209 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7210 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7211 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7212 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7213 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7214 pw.print(" mDestroying="); pw.print(mDestroying);
7215 pw.print(" mRemoved="); pw.println(mRemoved);
7216 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007217 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007218 pw.print(prefix); pw.print("mOrientationChanging=");
7219 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007220 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7221 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007222 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007223 if (mHScale != 1 || mVScale != 1) {
7224 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7225 pw.print(" mVScale="); pw.println(mVScale);
7226 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007227 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007228 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7229 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7230 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007231 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7232 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7233 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007235 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007236
7237 String makeInputChannelName() {
7238 return Integer.toHexString(System.identityHashCode(this))
7239 + " " + mAttrs.getTitle();
7240 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007241
7242 @Override
7243 public String toString() {
7244 return "Window{"
7245 + Integer.toHexString(System.identityHashCode(this))
7246 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7247 }
7248 }
Romain Guy06882f82009-06-10 13:36:04 -07007249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007250 // -------------------------------------------------------------
7251 // Window Token State
7252 // -------------------------------------------------------------
7253
7254 class WindowToken {
7255 // The actual token.
7256 final IBinder token;
7257
7258 // The type of window this token is for, as per WindowManager.LayoutParams.
7259 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 // Set if this token was explicitly added by a client, so should
7262 // not be removed when all windows are removed.
7263 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007264
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007265 // For printing.
7266 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 // If this is an AppWindowToken, this is non-null.
7269 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 // All of the windows associated with this token.
7272 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7273
7274 // Is key dispatching paused for this token?
7275 boolean paused = false;
7276
7277 // Should this token's windows be hidden?
7278 boolean hidden;
7279
7280 // Temporary for finding which tokens no longer have visible windows.
7281 boolean hasVisible;
7282
Dianne Hackborna8f60182009-09-01 19:01:50 -07007283 // Set to true when this token is in a pending transaction where it
7284 // will be shown.
7285 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007286
Dianne Hackborna8f60182009-09-01 19:01:50 -07007287 // Set to true when this token is in a pending transaction where it
7288 // will be hidden.
7289 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007290
Dianne Hackborna8f60182009-09-01 19:01:50 -07007291 // Set to true when this token is in a pending transaction where its
7292 // windows will be put to the bottom of the list.
7293 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007294
Dianne Hackborna8f60182009-09-01 19:01:50 -07007295 // Set to true when this token is in a pending transaction where its
7296 // windows will be put to the top of the list.
7297 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 WindowToken(IBinder _token, int type, boolean _explicit) {
7300 token = _token;
7301 windowType = type;
7302 explicit = _explicit;
7303 }
7304
7305 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007306 pw.print(prefix); pw.print("token="); pw.println(token);
7307 pw.print(prefix); pw.print("windows="); pw.println(windows);
7308 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7309 pw.print(" hidden="); pw.print(hidden);
7310 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007311 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7312 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7313 pw.print(" waitingToHide="); pw.print(waitingToHide);
7314 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7315 pw.print(" sendingToTop="); pw.println(sendingToTop);
7316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 }
7318
7319 @Override
7320 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007321 if (stringName == null) {
7322 StringBuilder sb = new StringBuilder();
7323 sb.append("WindowToken{");
7324 sb.append(Integer.toHexString(System.identityHashCode(this)));
7325 sb.append(" token="); sb.append(token); sb.append('}');
7326 stringName = sb.toString();
7327 }
7328 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 }
7330 };
7331
7332 class AppWindowToken extends WindowToken {
7333 // Non-null only for application tokens.
7334 final IApplicationToken appToken;
7335
7336 // All of the windows and child windows that are included in this
7337 // application token. Note this list is NOT sorted!
7338 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7339
7340 int groupId = -1;
7341 boolean appFullscreen;
7342 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007343
7344 // The input dispatching timeout for this application token in nanoseconds.
7345 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 // These are used for determining when all windows associated with
7348 // an activity have been drawn, so they can be made visible together
7349 // at the same time.
7350 int lastTransactionSequence = mTransactionSequence-1;
7351 int numInterestingWindows;
7352 int numDrawnWindows;
7353 boolean inPendingTransaction;
7354 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007356 // Is this token going to be hidden in a little while? If so, it
7357 // won't be taken into account for setting the screen orientation.
7358 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007360 // Is this window's surface needed? This is almost like hidden, except
7361 // it will sometimes be true a little earlier: when the token has
7362 // been shown, but is still waiting for its app transition to execute
7363 // before making its windows shown.
7364 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007366 // Have we told the window clients to hide themselves?
7367 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 // Last visibility state we reported to the app token.
7370 boolean reportedVisible;
7371
7372 // Set to true when the token has been removed from the window mgr.
7373 boolean removed;
7374
7375 // Have we been asked to have this token keep the screen frozen?
7376 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 boolean animating;
7379 Animation animation;
7380 boolean hasTransformation;
7381 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 // Offset to the window of all layers in the token, for use by
7384 // AppWindowToken animations.
7385 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 // Information about an application starting window if displayed.
7388 StartingData startingData;
7389 WindowState startingWindow;
7390 View startingView;
7391 boolean startingDisplayed;
7392 boolean startingMoved;
7393 boolean firstWindowDrawn;
7394
7395 AppWindowToken(IApplicationToken _token) {
7396 super(_token.asBinder(),
7397 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7398 appWindowToken = this;
7399 appToken = _token;
7400 }
Romain Guy06882f82009-06-10 13:36:04 -07007401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007403 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 TAG, "Setting animation in " + this + ": " + anim);
7405 animation = anim;
7406 animating = false;
7407 anim.restrictDuration(MAX_ANIMATION_DURATION);
7408 anim.scaleCurrentDuration(mTransitionAnimationScale);
7409 int zorder = anim.getZAdjustment();
7410 int adj = 0;
7411 if (zorder == Animation.ZORDER_TOP) {
7412 adj = TYPE_LAYER_OFFSET;
7413 } else if (zorder == Animation.ZORDER_BOTTOM) {
7414 adj = -TYPE_LAYER_OFFSET;
7415 }
Romain Guy06882f82009-06-10 13:36:04 -07007416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007417 if (animLayerAdjustment != adj) {
7418 animLayerAdjustment = adj;
7419 updateLayers();
7420 }
7421 }
Romain Guy06882f82009-06-10 13:36:04 -07007422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007423 public void setDummyAnimation() {
7424 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007425 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007426 TAG, "Setting dummy animation in " + this);
7427 animation = sDummyAnimation;
7428 }
7429 }
7430
7431 public void clearAnimation() {
7432 if (animation != null) {
7433 animation = null;
7434 animating = true;
7435 }
7436 }
Romain Guy06882f82009-06-10 13:36:04 -07007437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 void updateLayers() {
7439 final int N = allAppWindows.size();
7440 final int adj = animLayerAdjustment;
7441 for (int i=0; i<N; i++) {
7442 WindowState w = allAppWindows.get(i);
7443 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007444 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 + w.mAnimLayer);
7446 if (w == mInputMethodTarget) {
7447 setInputMethodAnimLayerAdjustment(adj);
7448 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007449 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007450 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007451 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 }
7453 }
Romain Guy06882f82009-06-10 13:36:04 -07007454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007455 void sendAppVisibilityToClients() {
7456 final int N = allAppWindows.size();
7457 for (int i=0; i<N; i++) {
7458 WindowState win = allAppWindows.get(i);
7459 if (win == startingWindow && clientHidden) {
7460 // Don't hide the starting window.
7461 continue;
7462 }
7463 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007464 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007465 "Setting visibility of " + win + ": " + (!clientHidden));
7466 win.mClient.dispatchAppVisibility(!clientHidden);
7467 } catch (RemoteException e) {
7468 }
7469 }
7470 }
Romain Guy06882f82009-06-10 13:36:04 -07007471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007472 void showAllWindowsLocked() {
7473 final int NW = allAppWindows.size();
7474 for (int i=0; i<NW; i++) {
7475 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007476 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 "performing show on: " + w);
7478 w.performShowLocked();
7479 }
7480 }
Romain Guy06882f82009-06-10 13:36:04 -07007481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007482 // This must be called while inside a transaction.
7483 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007484 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007485 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007487 if (animation == sDummyAnimation) {
7488 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007489 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 // when it is really time to animate, this will be set to
7491 // a real animation and the next call will execute normally.
7492 return false;
7493 }
Romain Guy06882f82009-06-10 13:36:04 -07007494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7496 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007497 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 TAG, "Starting animation in " + this +
7499 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7500 + " scale=" + mTransitionAnimationScale
7501 + " allDrawn=" + allDrawn + " animating=" + animating);
7502 animation.initialize(dw, dh, dw, dh);
7503 animation.setStartTime(currentTime);
7504 animating = true;
7505 }
7506 transformation.clear();
7507 final boolean more = animation.getTransformation(
7508 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007509 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 TAG, "Stepped animation in " + this +
7511 ": more=" + more + ", xform=" + transformation);
7512 if (more) {
7513 // we're done!
7514 hasTransformation = true;
7515 return true;
7516 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007517 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007518 TAG, "Finished animation in " + this +
7519 " @ " + currentTime);
7520 animation = null;
7521 }
7522 } else if (animation != null) {
7523 // If the display is frozen, and there is a pending animation,
7524 // clear it and make sure we run the cleanup code.
7525 animating = true;
7526 animation = null;
7527 }
7528
7529 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 if (!animating) {
7532 return false;
7533 }
7534
7535 clearAnimation();
7536 animating = false;
7537 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7538 moveInputMethodWindowsIfNeededLocked(true);
7539 }
Romain Guy06882f82009-06-10 13:36:04 -07007540
Joe Onorato8a9b2202010-02-26 18:56:32 -08007541 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007542 TAG, "Animation done in " + this
7543 + ": reportedVisible=" + reportedVisible);
7544
7545 transformation.clear();
7546 if (animLayerAdjustment != 0) {
7547 animLayerAdjustment = 0;
7548 updateLayers();
7549 }
Romain Guy06882f82009-06-10 13:36:04 -07007550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007551 final int N = windows.size();
7552 for (int i=0; i<N; i++) {
7553 ((WindowState)windows.get(i)).finishExit();
7554 }
7555 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 return false;
7558 }
7559
7560 void updateReportedVisibilityLocked() {
7561 if (appToken == null) {
7562 return;
7563 }
Romain Guy06882f82009-06-10 13:36:04 -07007564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 int numInteresting = 0;
7566 int numVisible = 0;
7567 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007568
Joe Onorato8a9b2202010-02-26 18:56:32 -08007569 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007570 final int N = allAppWindows.size();
7571 for (int i=0; i<N; i++) {
7572 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007573 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007574 || win.mViewVisibility != View.VISIBLE
7575 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007576 continue;
7577 }
7578 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007579 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007580 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007581 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007582 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007583 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 + " pv=" + win.mPolicyVisibility
7585 + " dp=" + win.mDrawPending
7586 + " cdp=" + win.mCommitDrawPending
7587 + " ah=" + win.mAttachedHidden
7588 + " th="
7589 + (win.mAppToken != null
7590 ? win.mAppToken.hiddenRequested : false)
7591 + " a=" + win.mAnimating);
7592 }
7593 }
7594 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007595 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596 if (!win.isAnimating()) {
7597 numVisible++;
7598 }
7599 nowGone = false;
7600 } else if (win.isAnimating()) {
7601 nowGone = false;
7602 }
7603 }
Romain Guy06882f82009-06-10 13:36:04 -07007604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007606 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 + numInteresting + " visible=" + numVisible);
7608 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007609 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007610 TAG, "Visibility changed in " + this
7611 + ": vis=" + nowVisible);
7612 reportedVisible = nowVisible;
7613 Message m = mH.obtainMessage(
7614 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7615 nowVisible ? 1 : 0,
7616 nowGone ? 1 : 0,
7617 this);
7618 mH.sendMessage(m);
7619 }
7620 }
Romain Guy06882f82009-06-10 13:36:04 -07007621
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007622 WindowState findMainWindow() {
7623 int j = windows.size();
7624 while (j > 0) {
7625 j--;
7626 WindowState win = windows.get(j);
7627 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7628 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7629 return win;
7630 }
7631 }
7632 return null;
7633 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007635 void dump(PrintWriter pw, String prefix) {
7636 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007637 if (appToken != null) {
7638 pw.print(prefix); pw.println("app=true");
7639 }
7640 if (allAppWindows.size() > 0) {
7641 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7642 }
7643 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007644 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007645 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7646 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7647 pw.print(" clientHidden="); pw.print(clientHidden);
7648 pw.print(" willBeHidden="); pw.print(willBeHidden);
7649 pw.print(" reportedVisible="); pw.println(reportedVisible);
7650 if (paused || freezingScreen) {
7651 pw.print(prefix); pw.print("paused="); pw.print(paused);
7652 pw.print(" freezingScreen="); pw.println(freezingScreen);
7653 }
7654 if (numInterestingWindows != 0 || numDrawnWindows != 0
7655 || inPendingTransaction || allDrawn) {
7656 pw.print(prefix); pw.print("numInterestingWindows=");
7657 pw.print(numInterestingWindows);
7658 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7659 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7660 pw.print(" allDrawn="); pw.println(allDrawn);
7661 }
7662 if (animating || animation != null) {
7663 pw.print(prefix); pw.print("animating="); pw.print(animating);
7664 pw.print(" animation="); pw.println(animation);
7665 }
7666 if (animLayerAdjustment != 0) {
7667 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7668 }
7669 if (hasTransformation) {
7670 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7671 pw.print(" transformation="); transformation.printShortString(pw);
7672 pw.println();
7673 }
7674 if (startingData != null || removed || firstWindowDrawn) {
7675 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7676 pw.print(" removed="); pw.print(removed);
7677 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7678 }
7679 if (startingWindow != null || startingView != null
7680 || startingDisplayed || startingMoved) {
7681 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7682 pw.print(" startingView="); pw.print(startingView);
7683 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7684 pw.print(" startingMoved"); pw.println(startingMoved);
7685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 }
7687
7688 @Override
7689 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007690 if (stringName == null) {
7691 StringBuilder sb = new StringBuilder();
7692 sb.append("AppWindowToken{");
7693 sb.append(Integer.toHexString(System.identityHashCode(this)));
7694 sb.append(" token="); sb.append(token); sb.append('}');
7695 stringName = sb.toString();
7696 }
7697 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 }
7699 }
Romain Guy06882f82009-06-10 13:36:04 -07007700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007701 // -------------------------------------------------------------
7702 // DummyAnimation
7703 // -------------------------------------------------------------
7704
7705 // This is an animation that does nothing: it just immediately finishes
7706 // itself every time it is called. It is used as a stub animation in cases
7707 // where we want to synchronize multiple things that may be animating.
7708 static final class DummyAnimation extends Animation {
7709 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7710 return false;
7711 }
7712 }
7713 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007715 // -------------------------------------------------------------
7716 // Async Handler
7717 // -------------------------------------------------------------
7718
7719 static final class StartingData {
7720 final String pkg;
7721 final int theme;
7722 final CharSequence nonLocalizedLabel;
7723 final int labelRes;
7724 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007726 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7727 int _labelRes, int _icon) {
7728 pkg = _pkg;
7729 theme = _theme;
7730 nonLocalizedLabel = _nonLocalizedLabel;
7731 labelRes = _labelRes;
7732 icon = _icon;
7733 }
7734 }
7735
7736 private final class H extends Handler {
7737 public static final int REPORT_FOCUS_CHANGE = 2;
7738 public static final int REPORT_LOSING_FOCUS = 3;
7739 public static final int ANIMATE = 4;
7740 public static final int ADD_STARTING = 5;
7741 public static final int REMOVE_STARTING = 6;
7742 public static final int FINISHED_STARTING = 7;
7743 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007744 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7745 public static final int HOLD_SCREEN_CHANGED = 12;
7746 public static final int APP_TRANSITION_TIMEOUT = 13;
7747 public static final int PERSIST_ANIMATION_SCALE = 14;
7748 public static final int FORCE_GC = 15;
7749 public static final int ENABLE_SCREEN = 16;
7750 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007751 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007752 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007754 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007756 public H() {
7757 }
Romain Guy06882f82009-06-10 13:36:04 -07007758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 @Override
7760 public void handleMessage(Message msg) {
7761 switch (msg.what) {
7762 case REPORT_FOCUS_CHANGE: {
7763 WindowState lastFocus;
7764 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007766 synchronized(mWindowMap) {
7767 lastFocus = mLastFocus;
7768 newFocus = mCurrentFocus;
7769 if (lastFocus == newFocus) {
7770 // Focus is not changing, so nothing to do.
7771 return;
7772 }
7773 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007774 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 // + " to " + newFocus);
7776 if (newFocus != null && lastFocus != null
7777 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007778 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007779 mLosingFocus.add(lastFocus);
7780 lastFocus = null;
7781 }
7782 }
7783
7784 if (lastFocus != newFocus) {
7785 //System.out.println("Changing focus from " + lastFocus
7786 // + " to " + newFocus);
7787 if (newFocus != null) {
7788 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007789 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7791 } catch (RemoteException e) {
7792 // Ignore if process has died.
7793 }
7794 }
7795
7796 if (lastFocus != null) {
7797 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007798 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7800 } catch (RemoteException e) {
7801 // Ignore if process has died.
7802 }
7803 }
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007804 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007805 }
7806 } break;
7807
7808 case REPORT_LOSING_FOCUS: {
7809 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007811 synchronized(mWindowMap) {
7812 losers = mLosingFocus;
7813 mLosingFocus = new ArrayList<WindowState>();
7814 }
7815
7816 final int N = losers.size();
7817 for (int i=0; i<N; i++) {
7818 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007819 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007820 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7821 } catch (RemoteException e) {
7822 // Ignore if process has died.
7823 }
7824 }
7825 } break;
7826
7827 case ANIMATE: {
7828 synchronized(mWindowMap) {
7829 mAnimationPending = false;
7830 performLayoutAndPlaceSurfacesLocked();
7831 }
7832 } break;
7833
7834 case ADD_STARTING: {
7835 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7836 final StartingData sd = wtoken.startingData;
7837
7838 if (sd == null) {
7839 // Animation has been canceled... do nothing.
7840 return;
7841 }
Romain Guy06882f82009-06-10 13:36:04 -07007842
Joe Onorato8a9b2202010-02-26 18:56:32 -08007843 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007844 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007846 View view = null;
7847 try {
7848 view = mPolicy.addStartingWindow(
7849 wtoken.token, sd.pkg,
7850 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7851 sd.icon);
7852 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007853 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007854 }
7855
7856 if (view != null) {
7857 boolean abort = false;
7858
7859 synchronized(mWindowMap) {
7860 if (wtoken.removed || wtoken.startingData == null) {
7861 // If the window was successfully added, then
7862 // we need to remove it.
7863 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007864 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007865 "Aborted starting " + wtoken
7866 + ": removed=" + wtoken.removed
7867 + " startingData=" + wtoken.startingData);
7868 wtoken.startingWindow = null;
7869 wtoken.startingData = null;
7870 abort = true;
7871 }
7872 } else {
7873 wtoken.startingView = view;
7874 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007875 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876 "Added starting " + wtoken
7877 + ": startingWindow="
7878 + wtoken.startingWindow + " startingView="
7879 + wtoken.startingView);
7880 }
7881
7882 if (abort) {
7883 try {
7884 mPolicy.removeStartingWindow(wtoken.token, view);
7885 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007886 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007887 }
7888 }
7889 }
7890 } break;
7891
7892 case REMOVE_STARTING: {
7893 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7894 IBinder token = null;
7895 View view = null;
7896 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007897 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 + wtoken + ": startingWindow="
7899 + wtoken.startingWindow + " startingView="
7900 + wtoken.startingView);
7901 if (wtoken.startingWindow != null) {
7902 view = wtoken.startingView;
7903 token = wtoken.token;
7904 wtoken.startingData = null;
7905 wtoken.startingView = null;
7906 wtoken.startingWindow = null;
7907 }
7908 }
7909 if (view != null) {
7910 try {
7911 mPolicy.removeStartingWindow(token, view);
7912 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007913 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007914 }
7915 }
7916 } break;
7917
7918 case FINISHED_STARTING: {
7919 IBinder token = null;
7920 View view = null;
7921 while (true) {
7922 synchronized (mWindowMap) {
7923 final int N = mFinishedStarting.size();
7924 if (N <= 0) {
7925 break;
7926 }
7927 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7928
Joe Onorato8a9b2202010-02-26 18:56:32 -08007929 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007930 "Finished starting " + wtoken
7931 + ": startingWindow=" + wtoken.startingWindow
7932 + " startingView=" + wtoken.startingView);
7933
7934 if (wtoken.startingWindow == null) {
7935 continue;
7936 }
7937
7938 view = wtoken.startingView;
7939 token = wtoken.token;
7940 wtoken.startingData = null;
7941 wtoken.startingView = null;
7942 wtoken.startingWindow = null;
7943 }
7944
7945 try {
7946 mPolicy.removeStartingWindow(token, view);
7947 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007948 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007949 }
7950 }
7951 } break;
7952
7953 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7954 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7955
7956 boolean nowVisible = msg.arg1 != 0;
7957 boolean nowGone = msg.arg2 != 0;
7958
7959 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007960 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007961 TAG, "Reporting visible in " + wtoken
7962 + " visible=" + nowVisible
7963 + " gone=" + nowGone);
7964 if (nowVisible) {
7965 wtoken.appToken.windowsVisible();
7966 } else {
7967 wtoken.appToken.windowsGone();
7968 }
7969 } catch (RemoteException ex) {
7970 }
7971 } break;
Romain Guy06882f82009-06-10 13:36:04 -07007972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 case WINDOW_FREEZE_TIMEOUT: {
7974 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007975 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007976 int i = mWindows.size();
7977 while (i > 0) {
7978 i--;
7979 WindowState w = (WindowState)mWindows.get(i);
7980 if (w.mOrientationChanging) {
7981 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007982 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007983 }
7984 }
7985 performLayoutAndPlaceSurfacesLocked();
7986 }
7987 break;
7988 }
Romain Guy06882f82009-06-10 13:36:04 -07007989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007990 case HOLD_SCREEN_CHANGED: {
7991 Session oldHold;
7992 Session newHold;
7993 synchronized (mWindowMap) {
7994 oldHold = mLastReportedHold;
7995 newHold = (Session)msg.obj;
7996 mLastReportedHold = newHold;
7997 }
Romain Guy06882f82009-06-10 13:36:04 -07007998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007999 if (oldHold != newHold) {
8000 try {
8001 if (oldHold != null) {
8002 mBatteryStats.noteStopWakelock(oldHold.mUid,
8003 "window",
8004 BatteryStats.WAKE_TYPE_WINDOW);
8005 }
8006 if (newHold != null) {
8007 mBatteryStats.noteStartWakelock(newHold.mUid,
8008 "window",
8009 BatteryStats.WAKE_TYPE_WINDOW);
8010 }
8011 } catch (RemoteException e) {
8012 }
8013 }
8014 break;
8015 }
Romain Guy06882f82009-06-10 13:36:04 -07008016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008017 case APP_TRANSITION_TIMEOUT: {
8018 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008019 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008020 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 "*** APP TRANSITION TIMEOUT");
8022 mAppTransitionReady = true;
8023 mAppTransitionTimeout = true;
8024 performLayoutAndPlaceSurfacesLocked();
8025 }
8026 }
8027 break;
8028 }
Romain Guy06882f82009-06-10 13:36:04 -07008029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008030 case PERSIST_ANIMATION_SCALE: {
8031 Settings.System.putFloat(mContext.getContentResolver(),
8032 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8033 Settings.System.putFloat(mContext.getContentResolver(),
8034 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8035 break;
8036 }
Romain Guy06882f82009-06-10 13:36:04 -07008037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 case FORCE_GC: {
8039 synchronized(mWindowMap) {
8040 if (mAnimationPending) {
8041 // If we are animating, don't do the gc now but
8042 // delay a bit so we don't interrupt the animation.
8043 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8044 2000);
8045 return;
8046 }
8047 // If we are currently rotating the display, it will
8048 // schedule a new message when done.
8049 if (mDisplayFrozen) {
8050 return;
8051 }
8052 mFreezeGcPending = 0;
8053 }
8054 Runtime.getRuntime().gc();
8055 break;
8056 }
Romain Guy06882f82009-06-10 13:36:04 -07008057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008058 case ENABLE_SCREEN: {
8059 performEnableScreen();
8060 break;
8061 }
Romain Guy06882f82009-06-10 13:36:04 -07008062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008063 case APP_FREEZE_TIMEOUT: {
8064 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008065 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008066 int i = mAppTokens.size();
8067 while (i > 0) {
8068 i--;
8069 AppWindowToken tok = mAppTokens.get(i);
8070 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008071 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008072 unsetAppFreezingScreenLocked(tok, true, true);
8073 }
8074 }
8075 }
8076 break;
8077 }
Romain Guy06882f82009-06-10 13:36:04 -07008078
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008079 case SEND_NEW_CONFIGURATION: {
8080 removeMessages(SEND_NEW_CONFIGURATION);
8081 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008082 break;
8083 }
Romain Guy06882f82009-06-10 13:36:04 -07008084
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008085 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008086 if (mWindowsChanged) {
8087 synchronized (mWindowMap) {
8088 mWindowsChanged = false;
8089 }
8090 notifyWindowsChanged();
8091 }
8092 break;
8093 }
8094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008095 }
8096 }
8097 }
8098
8099 // -------------------------------------------------------------
8100 // IWindowManager API
8101 // -------------------------------------------------------------
8102
8103 public IWindowSession openSession(IInputMethodClient client,
8104 IInputContext inputContext) {
8105 if (client == null) throw new IllegalArgumentException("null client");
8106 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008107 Session session = new Session(client, inputContext);
8108 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008109 }
8110
8111 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8112 synchronized (mWindowMap) {
8113 // The focus for the client is the window immediately below
8114 // where we would place the input method window.
8115 int idx = findDesiredInputMethodWindowIndexLocked(false);
8116 WindowState imFocus;
8117 if (idx > 0) {
8118 imFocus = (WindowState)mWindows.get(idx-1);
8119 if (imFocus != null) {
8120 if (imFocus.mSession.mClient != null &&
8121 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8122 return true;
8123 }
8124 }
8125 }
8126 }
8127 return false;
8128 }
Romain Guy06882f82009-06-10 13:36:04 -07008129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008130 // -------------------------------------------------------------
8131 // Internals
8132 // -------------------------------------------------------------
8133
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008134 final WindowState windowForClientLocked(Session session, IWindow client,
8135 boolean throwOnError) {
8136 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 }
Romain Guy06882f82009-06-10 13:36:04 -07008138
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008139 final WindowState windowForClientLocked(Session session, IBinder client,
8140 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008141 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008142 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008143 TAG, "Looking up client " + client + ": " + win);
8144 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008145 RuntimeException ex = new IllegalArgumentException(
8146 "Requested window " + client + " does not exist");
8147 if (throwOnError) {
8148 throw ex;
8149 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008150 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 return null;
8152 }
8153 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008154 RuntimeException ex = new IllegalArgumentException(
8155 "Requested window " + client + " is in session " +
8156 win.mSession + ", not " + session);
8157 if (throwOnError) {
8158 throw ex;
8159 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008160 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008161 return null;
8162 }
8163
8164 return win;
8165 }
8166
Dianne Hackborna8f60182009-09-01 19:01:50 -07008167 final void rebuildAppWindowListLocked() {
8168 int NW = mWindows.size();
8169 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008170 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008171 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008172
Dianne Hackborna8f60182009-09-01 19:01:50 -07008173 // First remove all existing app windows.
8174 i=0;
8175 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008176 WindowState w = (WindowState)mWindows.get(i);
8177 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008178 WindowState win = (WindowState)mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008179 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008180 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008181 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008182 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008183 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008184 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008185 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8186 && lastWallpaper == i-1) {
8187 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008188 }
8189 i++;
8190 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008191
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008192 // The wallpaper window(s) typically live at the bottom of the stack,
8193 // so skip them before adding app tokens.
8194 lastWallpaper++;
8195 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008196
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008197 // First add all of the exiting app tokens... these are no longer
8198 // in the main app list, but still have windows shown. We put them
8199 // in the back because now that the animation is over we no longer
8200 // will care about them.
8201 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008202 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008203 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8204 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008205
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008206 // And add in the still active app tokens in Z order.
8207 NT = mAppTokens.size();
8208 for (int j=0; j<NT; j++) {
8209 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008210 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008211
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008212 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008213 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008214 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008215 + " windows but added " + i);
8216 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008217 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008219 private final void assignLayersLocked() {
8220 int N = mWindows.size();
8221 int curBaseLayer = 0;
8222 int curLayer = 0;
8223 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008225 for (i=0; i<N; i++) {
8226 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008227 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8228 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008229 curLayer += WINDOW_LAYER_MULTIPLIER;
8230 w.mLayer = curLayer;
8231 } else {
8232 curBaseLayer = curLayer = w.mBaseLayer;
8233 w.mLayer = curLayer;
8234 }
8235 if (w.mTargetAppToken != null) {
8236 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8237 } else if (w.mAppToken != null) {
8238 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8239 } else {
8240 w.mAnimLayer = w.mLayer;
8241 }
8242 if (w.mIsImWindow) {
8243 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008244 } else if (w.mIsWallpaper) {
8245 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008246 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008247 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008248 + w.mAnimLayer);
8249 //System.out.println(
8250 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8251 }
8252 }
8253
8254 private boolean mInLayout = false;
8255 private final void performLayoutAndPlaceSurfacesLocked() {
8256 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008257 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008258 throw new RuntimeException("Recursive call!");
8259 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008260 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008261 return;
8262 }
8263
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008264 if (mWaitingForConfig) {
8265 // Our configuration has changed (most likely rotation), but we
8266 // don't yet have the complete configuration to report to
8267 // applications. Don't do any window layout until we have it.
8268 return;
8269 }
8270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008271 boolean recoveringMemory = false;
8272 if (mForceRemoves != null) {
8273 recoveringMemory = true;
8274 // Wait a little it for things to settle down, and off we go.
8275 for (int i=0; i<mForceRemoves.size(); i++) {
8276 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008277 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008278 removeWindowInnerLocked(ws.mSession, ws);
8279 }
8280 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008281 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008282 Object tmp = new Object();
8283 synchronized (tmp) {
8284 try {
8285 tmp.wait(250);
8286 } catch (InterruptedException e) {
8287 }
8288 }
8289 }
Romain Guy06882f82009-06-10 13:36:04 -07008290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008291 mInLayout = true;
8292 try {
8293 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008295 int i = mPendingRemove.size()-1;
8296 if (i >= 0) {
8297 while (i >= 0) {
8298 WindowState w = mPendingRemove.get(i);
8299 removeWindowInnerLocked(w.mSession, w);
8300 i--;
8301 }
8302 mPendingRemove.clear();
8303
8304 mInLayout = false;
8305 assignLayersLocked();
8306 mLayoutNeeded = true;
8307 performLayoutAndPlaceSurfacesLocked();
8308
8309 } else {
8310 mInLayout = false;
8311 if (mLayoutNeeded) {
8312 requestAnimationLocked(0);
8313 }
8314 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008315 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008316 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8317 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008319 } catch (RuntimeException e) {
8320 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008321 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008322 }
8323 }
8324
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008325 private final int performLayoutLockedInner() {
8326 if (!mLayoutNeeded) {
8327 return 0;
8328 }
8329
8330 mLayoutNeeded = false;
8331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008332 final int dw = mDisplay.getWidth();
8333 final int dh = mDisplay.getHeight();
8334
8335 final int N = mWindows.size();
8336 int i;
8337
Joe Onorato8a9b2202010-02-26 18:56:32 -08008338 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008339 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8340
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008341 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008342
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008343 int seq = mLayoutSeq+1;
8344 if (seq < 0) seq = 0;
8345 mLayoutSeq = seq;
8346
8347 // First perform layout of any root windows (not attached
8348 // to another window).
8349 int topAttached = -1;
8350 for (i = N-1; i >= 0; i--) {
8351 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008352
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008353 // Don't do layout of a window if it is not visible, or
8354 // soon won't be visible, to avoid wasting time and funky
8355 // changes while a window is animating away.
8356 final AppWindowToken atoken = win.mAppToken;
8357 final boolean gone = win.mViewVisibility == View.GONE
8358 || !win.mRelayoutCalled
8359 || win.mRootToken.hidden
8360 || (atoken != null && atoken.hiddenRequested)
8361 || win.mAttachedHidden
8362 || win.mExiting || win.mDestroying;
8363
8364 if (!win.mLayoutAttached) {
8365 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8366 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8367 + " mLayoutAttached=" + win.mLayoutAttached);
8368 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8369 + win.mViewVisibility + " mRelayoutCalled="
8370 + win.mRelayoutCalled + " hidden="
8371 + win.mRootToken.hidden + " hiddenRequested="
8372 + (atoken != null && atoken.hiddenRequested)
8373 + " mAttachedHidden=" + win.mAttachedHidden);
8374 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008375
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008376 // If this view is GONE, then skip it -- keep the current
8377 // frame, and let the caller know so they can ignore it
8378 // if they want. (We do the normal layout for INVISIBLE
8379 // windows, since that means "perform layout as normal,
8380 // just don't display").
8381 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008382 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008383 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8384 win.mLayoutSeq = seq;
8385 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8386 + win.mFrame + " mContainingFrame="
8387 + win.mContainingFrame + " mDisplayFrame="
8388 + win.mDisplayFrame);
8389 } else {
8390 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008391 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008393 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008394
8395 // Now perform layout of attached windows, which usually
8396 // depend on the position of the window they are attached to.
8397 // XXX does not deal with windows that are attached to windows
8398 // that are themselves attached.
8399 for (i = topAttached; i >= 0; i--) {
8400 WindowState win = (WindowState) mWindows.get(i);
8401
8402 // If this view is GONE, then skip it -- keep the current
8403 // frame, and let the caller know so they can ignore it
8404 // if they want. (We do the normal layout for INVISIBLE
8405 // windows, since that means "perform layout as normal,
8406 // just don't display").
8407 if (win.mLayoutAttached) {
8408 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8409 + " mHaveFrame=" + win.mHaveFrame
8410 + " mViewVisibility=" + win.mViewVisibility
8411 + " mRelayoutCalled=" + win.mRelayoutCalled);
8412 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8413 || !win.mHaveFrame) {
8414 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8415 win.mLayoutSeq = seq;
8416 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8417 + win.mFrame + " mContainingFrame="
8418 + win.mContainingFrame + " mDisplayFrame="
8419 + win.mDisplayFrame);
8420 }
8421 }
8422 }
Jeff Brown349703e2010-06-22 01:27:15 -07008423
8424 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008425 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008426
8427 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008428 }
Romain Guy06882f82009-06-10 13:36:04 -07008429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008430 private final void performLayoutAndPlaceSurfacesLockedInner(
8431 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008432 if (mDisplay == null) {
8433 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8434 return;
8435 }
8436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 final long currentTime = SystemClock.uptimeMillis();
8438 final int dw = mDisplay.getWidth();
8439 final int dh = mDisplay.getHeight();
8440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 int i;
8442
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008443 if (mFocusMayChange) {
8444 mFocusMayChange = false;
8445 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8446 }
8447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008448 if (mFxSession == null) {
8449 mFxSession = new SurfaceSession();
8450 }
Romain Guy06882f82009-06-10 13:36:04 -07008451
Joe Onorato8a9b2202010-02-26 18:56:32 -08008452 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453
8454 // Initialize state of exiting tokens.
8455 for (i=mExitingTokens.size()-1; i>=0; i--) {
8456 mExitingTokens.get(i).hasVisible = false;
8457 }
8458
8459 // Initialize state of exiting applications.
8460 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8461 mExitingAppTokens.get(i).hasVisible = false;
8462 }
8463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008464 boolean orientationChangeComplete = true;
8465 Session holdScreen = null;
8466 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008467 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008468 boolean focusDisplayed = false;
8469 boolean animating = false;
8470
8471 Surface.openTransaction();
8472 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008473 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008474 int repeats = 0;
8475 int changes = 0;
8476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008477 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008478 repeats++;
8479 if (repeats > 6) {
8480 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8481 mLayoutNeeded = false;
8482 break;
8483 }
8484
8485 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8486 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8487 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8488 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8489 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8490 assignLayersLocked();
8491 mLayoutNeeded = true;
8492 }
8493 }
8494 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8495 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8496 if (updateOrientationFromAppTokensLocked()) {
8497 mLayoutNeeded = true;
8498 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8499 }
8500 }
8501 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8502 mLayoutNeeded = true;
8503 }
8504 }
8505
8506 // FIRST LOOP: Perform a layout, if needed.
8507 if (repeats < 4) {
8508 changes = performLayoutLockedInner();
8509 if (changes != 0) {
8510 continue;
8511 }
8512 } else {
8513 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8514 changes = 0;
8515 }
8516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008517 final int transactionSequence = ++mTransactionSequence;
8518
8519 // Update animations of all applications, including those
8520 // associated with exiting/removed apps
8521 boolean tokensAnimating = false;
8522 final int NAT = mAppTokens.size();
8523 for (i=0; i<NAT; i++) {
8524 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8525 tokensAnimating = true;
8526 }
8527 }
8528 final int NEAT = mExitingAppTokens.size();
8529 for (i=0; i<NEAT; i++) {
8530 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8531 tokensAnimating = true;
8532 }
8533 }
8534
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008535 // SECOND LOOP: Execute animations and update visibility of windows.
8536
Joe Onorato8a9b2202010-02-26 18:56:32 -08008537 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008538 + transactionSequence + " tokensAnimating="
8539 + tokensAnimating);
8540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008542
8543 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008544 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008545 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008546
8547 mPolicy.beginAnimationLw(dw, dh);
8548
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008549 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008551 for (i=N-1; i>=0; i--) {
8552 WindowState w = (WindowState)mWindows.get(i);
8553
8554 final WindowManager.LayoutParams attrs = w.mAttrs;
8555
8556 if (w.mSurface != null) {
8557 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008558 if (w.commitFinishDrawingLocked(currentTime)) {
8559 if ((w.mAttrs.flags
8560 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008561 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008562 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008563 wallpaperMayChange = true;
8564 }
8565 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008566
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008567 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8569 animating = true;
8570 //w.dump(" ");
8571 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008572 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8573 wallpaperMayChange = true;
8574 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008575
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008576 if (mPolicy.doesForceHide(w, attrs)) {
8577 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008578 if (DEBUG_VISIBILITY) Slog.v(TAG,
8579 "Animation done that could impact force hide: "
8580 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008581 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008582 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008583 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8584 forceHiding = true;
8585 }
8586 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8587 boolean changed;
8588 if (forceHiding) {
8589 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008590 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8591 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008592 } else {
8593 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008594 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8595 "Now policy shown: " + w);
8596 if (changed) {
8597 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008598 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008599 // Assume we will need to animate. If
8600 // we don't (because the wallpaper will
8601 // stay with the lock screen), then we will
8602 // clean up later.
8603 Animation a = mPolicy.createForceHideEnterAnimation();
8604 if (a != null) {
8605 w.setAnimation(a);
8606 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008607 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008608 if (mCurrentFocus == null ||
8609 mCurrentFocus.mLayer < w.mLayer) {
8610 // We are showing on to of the current
8611 // focus, so re-evaluate focus to make
8612 // sure it is correct.
8613 mFocusMayChange = true;
8614 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008615 }
8616 }
8617 if (changed && (attrs.flags
8618 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8619 wallpaperMayChange = true;
8620 }
8621 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 mPolicy.animatingWindowLw(w, attrs);
8624 }
8625
8626 final AppWindowToken atoken = w.mAppToken;
8627 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8628 if (atoken.lastTransactionSequence != transactionSequence) {
8629 atoken.lastTransactionSequence = transactionSequence;
8630 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8631 atoken.startingDisplayed = false;
8632 }
8633 if ((w.isOnScreen() || w.mAttrs.type
8634 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8635 && !w.mExiting && !w.mDestroying) {
8636 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008637 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008638 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008639 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008640 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008641 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008642 + " pv=" + w.mPolicyVisibility
8643 + " dp=" + w.mDrawPending
8644 + " cdp=" + w.mCommitDrawPending
8645 + " ah=" + w.mAttachedHidden
8646 + " th=" + atoken.hiddenRequested
8647 + " a=" + w.mAnimating);
8648 }
8649 }
8650 if (w != atoken.startingWindow) {
8651 if (!atoken.freezingScreen || !w.mAppFreezing) {
8652 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008653 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008655 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008656 "tokenMayBeDrawn: " + atoken
8657 + " freezingScreen=" + atoken.freezingScreen
8658 + " mAppFreezing=" + w.mAppFreezing);
8659 tokenMayBeDrawn = true;
8660 }
8661 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008662 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008663 atoken.startingDisplayed = true;
8664 }
8665 }
8666 } else if (w.mReadyToShow) {
8667 w.performShowLocked();
8668 }
8669 }
8670
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008671 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008672
8673 if (tokenMayBeDrawn) {
8674 // See if any windows have been drawn, so they (and others
8675 // associated with them) can now be shown.
8676 final int NT = mTokenList.size();
8677 for (i=0; i<NT; i++) {
8678 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8679 if (wtoken == null) {
8680 continue;
8681 }
8682 if (wtoken.freezingScreen) {
8683 int numInteresting = wtoken.numInterestingWindows;
8684 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008685 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 "allDrawn: " + wtoken
8687 + " interesting=" + numInteresting
8688 + " drawn=" + wtoken.numDrawnWindows);
8689 wtoken.showAllWindowsLocked();
8690 unsetAppFreezingScreenLocked(wtoken, false, true);
8691 orientationChangeComplete = true;
8692 }
8693 } else if (!wtoken.allDrawn) {
8694 int numInteresting = wtoken.numInterestingWindows;
8695 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008696 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008697 "allDrawn: " + wtoken
8698 + " interesting=" + numInteresting
8699 + " drawn=" + wtoken.numDrawnWindows);
8700 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008701 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008702
8703 // We can now show all of the drawn windows!
8704 if (!mOpeningApps.contains(wtoken)) {
8705 wtoken.showAllWindowsLocked();
8706 }
8707 }
8708 }
8709 }
8710 }
8711
8712 // If we are ready to perform an app transition, check through
8713 // all of the app tokens to be shown and see if they are ready
8714 // to go.
8715 if (mAppTransitionReady) {
8716 int NN = mOpeningApps.size();
8717 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008718 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 "Checking " + NN + " opening apps (frozen="
8720 + mDisplayFrozen + " timeout="
8721 + mAppTransitionTimeout + ")...");
8722 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8723 // If the display isn't frozen, wait to do anything until
8724 // all of the apps are ready. Otherwise just go because
8725 // we'll unfreeze the display when everyone is ready.
8726 for (i=0; i<NN && goodToGo; i++) {
8727 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008728 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008729 "Check opening app" + wtoken + ": allDrawn="
8730 + wtoken.allDrawn + " startingDisplayed="
8731 + wtoken.startingDisplayed);
8732 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8733 && !wtoken.startingMoved) {
8734 goodToGo = false;
8735 }
8736 }
8737 }
8738 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008739 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 int transit = mNextAppTransition;
8741 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008742 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008743 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008744 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008745 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008746 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008747 mAppTransitionTimeout = false;
8748 mStartingIconInTransition = false;
8749 mSkipAppTransitionAnimation = false;
8750
8751 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8752
Dianne Hackborna8f60182009-09-01 19:01:50 -07008753 // If there are applications waiting to come to the
8754 // top of the stack, now is the time to move their windows.
8755 // (Note that we don't do apps going to the bottom
8756 // here -- we want to keep their windows in the old
8757 // Z-order until the animation completes.)
8758 if (mToTopApps.size() > 0) {
8759 NN = mAppTokens.size();
8760 for (i=0; i<NN; i++) {
8761 AppWindowToken wtoken = mAppTokens.get(i);
8762 if (wtoken.sendingToTop) {
8763 wtoken.sendingToTop = false;
8764 moveAppWindowsLocked(wtoken, NN, false);
8765 }
8766 }
8767 mToTopApps.clear();
8768 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008769
Dianne Hackborn25994b42009-09-04 14:21:19 -07008770 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008771
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008772 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008773 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008774
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008775 // The top-most window will supply the layout params,
8776 // and we will determine it below.
8777 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008778 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008779 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008780
Joe Onorato8a9b2202010-02-26 18:56:32 -08008781 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008782 "New wallpaper target=" + mWallpaperTarget
8783 + ", lower target=" + mLowerWallpaperTarget
8784 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008785 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008786 // Do a first pass through the tokens for two
8787 // things:
8788 // (1) Determine if both the closing and opening
8789 // app token sets are wallpaper targets, in which
8790 // case special animations are needed
8791 // (since the wallpaper needs to stay static
8792 // behind them).
8793 // (2) Find the layout params of the top-most
8794 // application window in the tokens, which is
8795 // what will control the animation theme.
8796 final int NC = mClosingApps.size();
8797 NN = NC + mOpeningApps.size();
8798 for (i=0; i<NN; i++) {
8799 AppWindowToken wtoken;
8800 int mode;
8801 if (i < NC) {
8802 wtoken = mClosingApps.get(i);
8803 mode = 1;
8804 } else {
8805 wtoken = mOpeningApps.get(i-NC);
8806 mode = 2;
8807 }
8808 if (mLowerWallpaperTarget != null) {
8809 if (mLowerWallpaperTarget.mAppToken == wtoken
8810 || mUpperWallpaperTarget.mAppToken == wtoken) {
8811 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008812 }
8813 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008814 if (wtoken.appFullscreen) {
8815 WindowState ws = wtoken.findMainWindow();
8816 if (ws != null) {
8817 // If this is a compatibility mode
8818 // window, we will always use its anim.
8819 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8820 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008821 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008822 bestAnimLayer = Integer.MAX_VALUE;
8823 } else if (ws.mLayer > bestAnimLayer) {
8824 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008825 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008826 bestAnimLayer = ws.mLayer;
8827 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008828 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008829 }
8830 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008831
Dianne Hackborn25994b42009-09-04 14:21:19 -07008832 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008833 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008834 "Wallpaper animation!");
8835 switch (transit) {
8836 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8837 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8838 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8839 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8840 break;
8841 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8842 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8843 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8844 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8845 break;
8846 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008847 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008848 "New transit: " + transit);
8849 } else if (oldWallpaper != null) {
8850 // We are transitioning from an activity with
8851 // a wallpaper to one without.
8852 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008853 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008854 "New transit away from wallpaper: " + transit);
8855 } else if (mWallpaperTarget != null) {
8856 // We are transitioning from an activity without
8857 // a wallpaper to now showing the wallpaper
8858 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008859 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008860 "New transit into wallpaper: " + transit);
8861 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008862
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008863 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8864 mLastEnterAnimToken = animToken;
8865 mLastEnterAnimParams = animLp;
8866 } else if (mLastEnterAnimParams != null) {
8867 animLp = mLastEnterAnimParams;
8868 mLastEnterAnimToken = null;
8869 mLastEnterAnimParams = null;
8870 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008871
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008872 // If all closing windows are obscured, then there is
8873 // no need to do an animation. This is the case, for
8874 // example, when this transition is being done behind
8875 // the lock screen.
8876 if (!mPolicy.allowAppAnimationsLw()) {
8877 animLp = null;
8878 }
8879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008880 NN = mOpeningApps.size();
8881 for (i=0; i<NN; i++) {
8882 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008883 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008884 "Now opening app" + wtoken);
8885 wtoken.reportedVisible = false;
8886 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008887 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008888 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008889 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008890 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 wtoken.showAllWindowsLocked();
8892 }
8893 NN = mClosingApps.size();
8894 for (i=0; i<NN; i++) {
8895 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008896 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008897 "Now closing app" + wtoken);
8898 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008899 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008900 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008902 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008903 // Force the allDrawn flag, because we want to start
8904 // this guy's animations regardless of whether it's
8905 // gotten drawn.
8906 wtoken.allDrawn = true;
8907 }
8908
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008909 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008911 mOpeningApps.clear();
8912 mClosingApps.clear();
8913
8914 // This has changed the visibility of windows, so perform
8915 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008916 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008917 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008918 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8919 assignLayersLocked();
8920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008921 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008922 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008923 }
8924 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008925
Dianne Hackborn16064f92010-03-25 00:47:24 -07008926 int adjResult = 0;
8927
Dianne Hackborna8f60182009-09-01 19:01:50 -07008928 if (!animating && mAppTransitionRunning) {
8929 // We have finished the animation of an app transition. To do
8930 // this, we have delayed a lot of operations like showing and
8931 // hiding apps, moving apps in Z-order, etc. The app token list
8932 // reflects the correct Z-order, but the window list may now
8933 // be out of sync with it. So here we will just rebuild the
8934 // entire app window list. Fun!
8935 mAppTransitionRunning = false;
8936 // Clear information about apps that were moving.
8937 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008938
Dianne Hackborna8f60182009-09-01 19:01:50 -07008939 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008940 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008941 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008942 moveInputMethodWindowsIfNeededLocked(false);
8943 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008944 // Since the window list has been rebuilt, focus might
8945 // have to be recomputed since the actual order of windows
8946 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008947 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008948 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008949
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008950 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008951 // At this point, there was a window with a wallpaper that
8952 // was force hiding other windows behind it, but now it
8953 // is going away. This may be simple -- just animate
8954 // away the wallpaper and its window -- or it may be
8955 // hard -- the wallpaper now needs to be shown behind
8956 // something that was hidden.
8957 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008958 if (mLowerWallpaperTarget != null
8959 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008960 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008961 "wallpaperForceHiding changed with lower="
8962 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008963 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008964 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
8965 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
8966 if (mLowerWallpaperTarget.mAppToken.hidden) {
8967 // The lower target has become hidden before we
8968 // actually started the animation... let's completely
8969 // re-evaluate everything.
8970 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008971 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008972 }
8973 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07008974 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008975 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008976 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008977 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008978 + " NEW: " + mWallpaperTarget
8979 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008980 if (mLowerWallpaperTarget == null) {
8981 // Whoops, we don't need a special wallpaper animation.
8982 // Clear them out.
8983 forceHiding = false;
8984 for (i=N-1; i>=0; i--) {
8985 WindowState w = (WindowState)mWindows.get(i);
8986 if (w.mSurface != null) {
8987 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07008988 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008989 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008990 forceHiding = true;
8991 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8992 if (!w.mAnimating) {
8993 // We set the animation above so it
8994 // is not yet running.
8995 w.clearAnimation();
8996 }
8997 }
8998 }
8999 }
9000 }
9001 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009002
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009003 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009004 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009005 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009006 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009007 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009008
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009009 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009010 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009011 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009012 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009013 assignLayersLocked();
9014 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009015 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009016 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009017 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009018 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009019
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009020 if (mFocusMayChange) {
9021 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009022 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009023 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009024 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009025 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009026 }
9027
9028 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009029 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009030 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009031
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009032 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9033 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009034
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009035 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009036
9037 // THIRD LOOP: Update the surfaces of all windows.
9038
9039 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9040
9041 boolean obscured = false;
9042 boolean blurring = false;
9043 boolean dimming = false;
9044 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009045 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009046 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009047
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009048 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009050 for (i=N-1; i>=0; i--) {
9051 WindowState w = (WindowState)mWindows.get(i);
9052
9053 boolean displayed = false;
9054 final WindowManager.LayoutParams attrs = w.mAttrs;
9055 final int attrFlags = attrs.flags;
9056
9057 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009058 // XXX NOTE: The logic here could be improved. We have
9059 // the decision about whether to resize a window separated
9060 // from whether to hide the surface. This can cause us to
9061 // resize a surface even if we are going to hide it. You
9062 // can see this by (1) holding device in landscape mode on
9063 // home screen; (2) tapping browser icon (device will rotate
9064 // to landscape; (3) tap home. The wallpaper will be resized
9065 // in step 2 but then immediately hidden, causing us to
9066 // have to resize and then redraw it again in step 3. It
9067 // would be nice to figure out how to avoid this, but it is
9068 // difficult because we do need to resize surfaces in some
9069 // cases while they are hidden such as when first showing a
9070 // window.
9071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009072 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009073 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009074 TAG, "Placing surface #" + i + " " + w.mSurface
9075 + ": new=" + w.mShownFrame + ", old="
9076 + w.mLastShownFrame);
9077
9078 boolean resize;
9079 int width, height;
9080 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9081 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9082 w.mLastRequestedHeight != w.mRequestedHeight;
9083 // for a scaled surface, we just want to use
9084 // the requested size.
9085 width = w.mRequestedWidth;
9086 height = w.mRequestedHeight;
9087 w.mLastRequestedWidth = width;
9088 w.mLastRequestedHeight = height;
9089 w.mLastShownFrame.set(w.mShownFrame);
9090 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009091 if (SHOW_TRANSACTIONS) logSurface(w,
9092 "POS " + w.mShownFrame.left
9093 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009094 w.mSurfaceX = w.mShownFrame.left;
9095 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009096 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9097 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009098 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009099 if (!recoveringMemory) {
9100 reclaimSomeSurfaceMemoryLocked(w, "position");
9101 }
9102 }
9103 } else {
9104 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9105 width = w.mShownFrame.width();
9106 height = w.mShownFrame.height();
9107 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009108 }
9109
9110 if (resize) {
9111 if (width < 1) width = 1;
9112 if (height < 1) height = 1;
9113 if (w.mSurface != null) {
9114 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009115 if (SHOW_TRANSACTIONS) logSurface(w,
9116 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009117 + w.mShownFrame.top + " SIZE "
9118 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009119 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009120 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009121 w.mSurfaceW = width;
9122 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009123 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009124 w.mSurfaceX = w.mShownFrame.left;
9125 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009126 w.mSurface.setPosition(w.mShownFrame.left,
9127 w.mShownFrame.top);
9128 } catch (RuntimeException e) {
9129 // If something goes wrong with the surface (such
9130 // as running out of memory), don't take down the
9131 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009132 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009133 + "size=(" + width + "x" + height
9134 + "), pos=(" + w.mShownFrame.left
9135 + "," + w.mShownFrame.top + ")", e);
9136 if (!recoveringMemory) {
9137 reclaimSomeSurfaceMemoryLocked(w, "size");
9138 }
9139 }
9140 }
9141 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009142 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 w.mContentInsetsChanged =
9144 !w.mLastContentInsets.equals(w.mContentInsets);
9145 w.mVisibleInsetsChanged =
9146 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009147 boolean configChanged =
9148 w.mConfiguration != mCurConfiguration
9149 && (w.mConfiguration == null
9150 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009151 if (DEBUG_CONFIGURATION && configChanged) {
9152 Slog.v(TAG, "Win " + w + " config changed: "
9153 + mCurConfiguration);
9154 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009155 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009156 + ": configChanged=" + configChanged
9157 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009158 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009159 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009160 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009161 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009162 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009163 w.mLastFrame.set(w.mFrame);
9164 w.mLastContentInsets.set(w.mContentInsets);
9165 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009166 // If the screen is currently frozen, then keep
9167 // it frozen until this window draws at its new
9168 // orientation.
9169 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009170 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009171 "Resizing while display frozen: " + w);
9172 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009173 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009174 mWindowsFreezingScreen = true;
9175 // XXX should probably keep timeout from
9176 // when we first froze the display.
9177 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9178 mH.sendMessageDelayed(mH.obtainMessage(
9179 H.WINDOW_FREEZE_TIMEOUT), 2000);
9180 }
9181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009182 // If the orientation is changing, then we need to
9183 // hold off on unfreezing the display until this
9184 // window has been redrawn; to do that, we need
9185 // to go through the process of getting informed
9186 // by the application when it has finished drawing.
9187 if (w.mOrientationChanging) {
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 start waiting for draw in "
9190 + w + ", surface " + w.mSurface);
9191 w.mDrawPending = true;
9192 w.mCommitDrawPending = false;
9193 w.mReadyToShow = false;
9194 if (w.mAppToken != null) {
9195 w.mAppToken.allDrawn = false;
9196 }
9197 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009198 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 "Resizing window " + w + " to " + w.mFrame);
9200 mResizingWindows.add(w);
9201 } else if (w.mOrientationChanging) {
9202 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009203 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009204 "Orientation not waiting for draw in "
9205 + w + ", surface " + w.mSurface);
9206 w.mOrientationChanging = false;
9207 }
9208 }
9209 }
9210
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009211 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009212 if (!w.mLastHidden) {
9213 //dump();
9214 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009215 if (SHOW_TRANSACTIONS) logSurface(w,
9216 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009217 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009218 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 try {
9220 w.mSurface.hide();
9221 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009222 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009223 }
9224 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009225 mInputMonitor.windowIsBecomingInvisibleLw(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 }
9227 // If we are waiting for this window to handle an
9228 // orientation change, well, it is hidden, so
9229 // doesn't really matter. Note that this does
9230 // introduce a potential glitch if the window
9231 // becomes unhidden before it has drawn for the
9232 // new orientation.
9233 if (w.mOrientationChanging) {
9234 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009235 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 "Orientation change skips hidden " + w);
9237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009238 } else if (w.mLastLayer != w.mAnimLayer
9239 || w.mLastAlpha != w.mShownAlpha
9240 || w.mLastDsDx != w.mDsDx
9241 || w.mLastDtDx != w.mDtDx
9242 || w.mLastDsDy != w.mDsDy
9243 || w.mLastDtDy != w.mDtDy
9244 || w.mLastHScale != w.mHScale
9245 || w.mLastVScale != w.mVScale
9246 || w.mLastHidden) {
9247 displayed = true;
9248 w.mLastAlpha = w.mShownAlpha;
9249 w.mLastLayer = w.mAnimLayer;
9250 w.mLastDsDx = w.mDsDx;
9251 w.mLastDtDx = w.mDtDx;
9252 w.mLastDsDy = w.mDsDy;
9253 w.mLastDtDy = w.mDtDy;
9254 w.mLastHScale = w.mHScale;
9255 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009256 if (SHOW_TRANSACTIONS) logSurface(w,
9257 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009258 + " matrix=[" + (w.mDsDx*w.mHScale)
9259 + "," + (w.mDtDx*w.mVScale)
9260 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009261 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 if (w.mSurface != null) {
9263 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009264 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009265 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009266 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009267 w.mSurface.setLayer(w.mAnimLayer);
9268 w.mSurface.setMatrix(
9269 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9270 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9271 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009272 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009273 if (!recoveringMemory) {
9274 reclaimSomeSurfaceMemoryLocked(w, "update");
9275 }
9276 }
9277 }
9278
9279 if (w.mLastHidden && !w.mDrawPending
9280 && !w.mCommitDrawPending
9281 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009282 if (SHOW_TRANSACTIONS) logSurface(w,
9283 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009284 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009285 + " during relayout");
9286 if (showSurfaceRobustlyLocked(w)) {
9287 w.mHasDrawn = true;
9288 w.mLastHidden = false;
9289 } else {
9290 w.mOrientationChanging = false;
9291 }
9292 }
9293 if (w.mSurface != null) {
9294 w.mToken.hasVisible = true;
9295 }
9296 } else {
9297 displayed = true;
9298 }
9299
9300 if (displayed) {
9301 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009302 if (attrs.width == LayoutParams.MATCH_PARENT
9303 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009304 covered = true;
9305 }
9306 }
9307 if (w.mOrientationChanging) {
9308 if (w.mDrawPending || w.mCommitDrawPending) {
9309 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009310 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 "Orientation continue waiting for draw in " + w);
9312 } else {
9313 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009314 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009315 "Orientation change complete in " + w);
9316 }
9317 }
9318 w.mToken.hasVisible = true;
9319 }
9320 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009321 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 "Orientation change skips hidden " + w);
9323 w.mOrientationChanging = false;
9324 }
9325
9326 final boolean canBeSeen = w.isDisplayedLw();
9327
9328 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9329 focusDisplayed = true;
9330 }
9331
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009332 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009334 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009335 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009336 if (w.mSurface != null) {
9337 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9338 holdScreen = w.mSession;
9339 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009340 if (!syswin && w.mAttrs.screenBrightness >= 0
9341 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 screenBrightness = w.mAttrs.screenBrightness;
9343 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009344 if (!syswin && w.mAttrs.buttonBrightness >= 0
9345 && buttonBrightness < 0) {
9346 buttonBrightness = w.mAttrs.buttonBrightness;
9347 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009348 if (canBeSeen
9349 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9350 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9351 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009352 syswin = true;
9353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009355
Dianne Hackborn25994b42009-09-04 14:21:19 -07009356 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9357 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009358 // This window completely covers everything behind it,
9359 // so we want to leave all of them as unblurred (for
9360 // performance reasons).
9361 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009362 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009363 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009364 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009365 obscured = true;
9366 if (mBackgroundFillerSurface == null) {
9367 try {
9368 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009369 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009370 0, dw, dh,
9371 PixelFormat.OPAQUE,
9372 Surface.FX_SURFACE_NORMAL);
9373 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009374 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009375 }
9376 }
9377 try {
9378 mBackgroundFillerSurface.setPosition(0, 0);
9379 mBackgroundFillerSurface.setSize(dw, dh);
9380 // Using the same layer as Dim because they will never be shown at the
9381 // same time.
9382 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9383 mBackgroundFillerSurface.show();
9384 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009385 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009386 }
9387 backgroundFillerShown = true;
9388 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009389 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009390 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009391 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009392 + ": blurring=" + blurring
9393 + " obscured=" + obscured
9394 + " displayed=" + displayed);
9395 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9396 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009397 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009399 if (mDimAnimator == null) {
9400 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009401 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009402 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009403 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009405 }
9406 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9407 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009408 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009409 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009411 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009412 + mBlurSurface + ": CREATE");
9413 try {
Romain Guy06882f82009-06-10 13:36:04 -07009414 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009415 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009416 -1, 16, 16,
9417 PixelFormat.OPAQUE,
9418 Surface.FX_SURFACE_BLUR);
9419 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009420 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009421 }
9422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009423 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009424 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9425 + mBlurSurface + ": pos=(0,0) (" +
9426 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 mBlurSurface.setPosition(0, 0);
9428 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009429 mBlurSurface.setLayer(w.mAnimLayer-2);
9430 if (!mBlurShown) {
9431 try {
9432 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9433 + mBlurSurface + ": SHOW");
9434 mBlurSurface.show();
9435 } catch (RuntimeException e) {
9436 Slog.w(TAG, "Failure showing blur surface", e);
9437 }
9438 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009439 }
9440 }
9441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442 }
9443 }
9444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009445
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009446 if (obscuredChanged && mWallpaperTarget == w) {
9447 // This is the wallpaper target and its obscured state
9448 // changed... make sure the current wallaper's visibility
9449 // has been updated accordingly.
9450 updateWallpaperVisibilityLocked();
9451 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009452 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009453
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009454 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9455 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009456 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009457 try {
9458 mBackgroundFillerSurface.hide();
9459 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009460 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009461 }
9462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009463
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009464 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009465 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9466 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009467 }
Romain Guy06882f82009-06-10 13:36:04 -07009468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009470 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009471 + ": HIDE");
9472 try {
9473 mBlurSurface.hide();
9474 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009475 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 }
9477 mBlurShown = false;
9478 }
9479
Joe Onorato8a9b2202010-02-26 18:56:32 -08009480 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009481 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009482 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009483 }
9484
9485 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009486
Joe Onorato8a9b2202010-02-26 18:56:32 -08009487 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009488 "With display frozen, orientationChangeComplete="
9489 + orientationChangeComplete);
9490 if (orientationChangeComplete) {
9491 if (mWindowsFreezingScreen) {
9492 mWindowsFreezingScreen = false;
9493 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9494 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009495 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009496 }
Romain Guy06882f82009-06-10 13:36:04 -07009497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009498 i = mResizingWindows.size();
9499 if (i > 0) {
9500 do {
9501 i--;
9502 WindowState win = mResizingWindows.get(i);
9503 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009504 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9505 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009506 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009507 boolean configChanged =
9508 win.mConfiguration != mCurConfiguration
9509 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009510 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9511 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9512 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009513 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009514 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009515 + " / " + mCurConfiguration + " / 0x"
9516 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009517 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009518 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 win.mClient.resized(win.mFrame.width(),
9520 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009521 win.mLastVisibleInsets, win.mDrawPending,
9522 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 win.mContentInsetsChanged = false;
9524 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009525 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009526 } catch (RemoteException e) {
9527 win.mOrientationChanging = false;
9528 }
9529 } while (i > 0);
9530 mResizingWindows.clear();
9531 }
Romain Guy06882f82009-06-10 13:36:04 -07009532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009533 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009534 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009535 i = mDestroySurface.size();
9536 if (i > 0) {
9537 do {
9538 i--;
9539 WindowState win = mDestroySurface.get(i);
9540 win.mDestroying = false;
9541 if (mInputMethodWindow == win) {
9542 mInputMethodWindow = null;
9543 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009544 if (win == mWallpaperTarget) {
9545 wallpaperDestroyed = true;
9546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009547 win.destroySurfaceLocked();
9548 } while (i > 0);
9549 mDestroySurface.clear();
9550 }
9551
9552 // Time to remove any exiting tokens?
9553 for (i=mExitingTokens.size()-1; i>=0; i--) {
9554 WindowToken token = mExitingTokens.get(i);
9555 if (!token.hasVisible) {
9556 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009557 if (token.windowType == TYPE_WALLPAPER) {
9558 mWallpaperTokens.remove(token);
9559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009560 }
9561 }
9562
9563 // Time to remove any exiting applications?
9564 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9565 AppWindowToken token = mExitingAppTokens.get(i);
9566 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009567 // Make sure there is no animation running on this token,
9568 // so any windows associated with it will be removed as
9569 // soon as their animations are complete
9570 token.animation = null;
9571 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 mAppTokens.remove(token);
9573 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009574 if (mLastEnterAnimToken == token) {
9575 mLastEnterAnimToken = null;
9576 mLastEnterAnimParams = null;
9577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009578 }
9579 }
9580
Dianne Hackborna8f60182009-09-01 19:01:50 -07009581 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009582
Dianne Hackborna8f60182009-09-01 19:01:50 -07009583 if (!animating && mAppTransitionRunning) {
9584 // We have finished the animation of an app transition. To do
9585 // this, we have delayed a lot of operations like showing and
9586 // hiding apps, moving apps in Z-order, etc. The app token list
9587 // reflects the correct Z-order, but the window list may now
9588 // be out of sync with it. So here we will just rebuild the
9589 // entire app window list. Fun!
9590 mAppTransitionRunning = false;
9591 needRelayout = true;
9592 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009593 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009594 // Clear information about apps that were moving.
9595 mToBottomApps.clear();
9596 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009598 if (focusDisplayed) {
9599 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9600 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009601 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009602 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009603 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009604 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009605 requestAnimationLocked(0);
9606 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009607 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9608 }
Jeff Brown8e03b752010-06-13 19:16:55 -07009609 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009610 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9611 mPowerManager.setScreenBrightnessOverride(-1);
9612 } else {
9613 mPowerManager.setScreenBrightnessOverride((int)
9614 (screenBrightness * Power.BRIGHTNESS_ON));
9615 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009616 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9617 mPowerManager.setButtonBrightnessOverride(-1);
9618 } else {
9619 mPowerManager.setButtonBrightnessOverride((int)
9620 (buttonBrightness * Power.BRIGHTNESS_ON));
9621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009622 if (holdScreen != mHoldingScreenOn) {
9623 mHoldingScreenOn = holdScreen;
9624 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9625 mH.sendMessage(m);
9626 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009627
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009628 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009629 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009630 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9631 LocalPowerManager.BUTTON_EVENT, true);
9632 mTurnOnScreen = false;
9633 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009634
9635 // Check to see if we are now in a state where the screen should
9636 // be enabled, because the window obscured flags have changed.
9637 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009638 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009639
9640 /**
9641 * Must be called with the main window manager lock held.
9642 */
9643 void setHoldScreenLocked(boolean holding) {
9644 boolean state = mHoldingScreenWakeLock.isHeld();
9645 if (holding != state) {
9646 if (holding) {
9647 mHoldingScreenWakeLock.acquire();
9648 } else {
9649 mPolicy.screenOnStoppedLw();
9650 mHoldingScreenWakeLock.release();
9651 }
9652 }
9653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009654
9655 void requestAnimationLocked(long delay) {
9656 if (!mAnimationPending) {
9657 mAnimationPending = true;
9658 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9659 }
9660 }
Romain Guy06882f82009-06-10 13:36:04 -07009661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009662 /**
9663 * Have the surface flinger show a surface, robustly dealing with
9664 * error conditions. In particular, if there is not enough memory
9665 * to show the surface, then we will try to get rid of other surfaces
9666 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009667 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009668 * @return Returns true if the surface was successfully shown.
9669 */
9670 boolean showSurfaceRobustlyLocked(WindowState win) {
9671 try {
9672 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009673 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009674 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009675 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009676 if (DEBUG_VISIBILITY) Slog.v(TAG,
9677 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009678 win.mTurnOnScreen = false;
9679 mTurnOnScreen = true;
9680 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009681 }
9682 return true;
9683 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009684 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685 }
Romain Guy06882f82009-06-10 13:36:04 -07009686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009687 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009689 return false;
9690 }
Romain Guy06882f82009-06-10 13:36:04 -07009691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009692 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9693 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009694
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009695 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009696 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009698 if (mForceRemoves == null) {
9699 mForceRemoves = new ArrayList<WindowState>();
9700 }
Romain Guy06882f82009-06-10 13:36:04 -07009701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009702 long callingIdentity = Binder.clearCallingIdentity();
9703 try {
9704 // There was some problem... first, do a sanity check of the
9705 // window list to make sure we haven't left any dangling surfaces
9706 // around.
9707 int N = mWindows.size();
9708 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009709 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 for (int i=0; i<N; i++) {
9711 WindowState ws = (WindowState)mWindows.get(i);
9712 if (ws.mSurface != null) {
9713 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009714 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009715 + ws + " surface=" + ws.mSurface
9716 + " token=" + win.mToken
9717 + " pid=" + ws.mSession.mPid
9718 + " uid=" + ws.mSession.mUid);
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 mForceRemoves.add(ws);
9723 i--;
9724 N--;
9725 leakedSurface = true;
9726 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009727 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 + ws + " surface=" + ws.mSurface
9729 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009730 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009731 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009732 ws.mSurface = null;
9733 leakedSurface = true;
9734 }
9735 }
9736 }
Romain Guy06882f82009-06-10 13:36:04 -07009737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009738 boolean killedApps = false;
9739 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009740 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741 SparseIntArray pidCandidates = new SparseIntArray();
9742 for (int i=0; i<N; i++) {
9743 WindowState ws = (WindowState)mWindows.get(i);
9744 if (ws.mSurface != null) {
9745 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9746 }
9747 }
9748 if (pidCandidates.size() > 0) {
9749 int[] pids = new int[pidCandidates.size()];
9750 for (int i=0; i<pids.length; i++) {
9751 pids[i] = pidCandidates.keyAt(i);
9752 }
9753 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009754 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 killedApps = true;
9756 }
9757 } catch (RemoteException e) {
9758 }
9759 }
9760 }
Romain Guy06882f82009-06-10 13:36:04 -07009761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009762 if (leakedSurface || killedApps) {
9763 // We managed to reclaim some memory, so get rid of the trouble
9764 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009765 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009766 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009767 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009768 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 win.mSurface = null;
9770 }
Romain Guy06882f82009-06-10 13:36:04 -07009771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 try {
9773 win.mClient.dispatchGetNewSurface();
9774 } catch (RemoteException e) {
9775 }
9776 }
9777 } finally {
9778 Binder.restoreCallingIdentity(callingIdentity);
9779 }
9780 }
Romain Guy06882f82009-06-10 13:36:04 -07009781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009782 private boolean updateFocusedWindowLocked(int mode) {
9783 WindowState newFocus = computeFocusedWindowLocked();
9784 if (mCurrentFocus != newFocus) {
9785 // This check makes sure that we don't already have the focus
9786 // change message pending.
9787 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9788 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009789 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009790 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9791 final WindowState oldFocus = mCurrentFocus;
9792 mCurrentFocus = newFocus;
9793 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 final WindowState imWindow = mInputMethodWindow;
9796 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009797 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009798 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009799 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9800 mLayoutNeeded = true;
9801 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009802 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9803 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009804 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9805 // Client will do the layout, but we need to assign layers
9806 // for handleNewWindowLocked() below.
9807 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 }
9809 }
Jeff Brown349703e2010-06-22 01:27:15 -07009810
9811 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9812 // If we defer assigning layers, then the caller is responsible for
9813 // doing this part.
9814 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009815 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 return true;
9817 }
9818 return false;
9819 }
Jeff Brown349703e2010-06-22 01:27:15 -07009820
9821 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009822 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009824
9825 private WindowState computeFocusedWindowLocked() {
9826 WindowState result = null;
9827 WindowState win;
9828
9829 int i = mWindows.size() - 1;
9830 int nextAppIndex = mAppTokens.size()-1;
9831 WindowToken nextApp = nextAppIndex >= 0
9832 ? mAppTokens.get(nextAppIndex) : null;
9833
9834 while (i >= 0) {
9835 win = (WindowState)mWindows.get(i);
9836
Joe Onorato8a9b2202010-02-26 18:56:32 -08009837 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009838 TAG, "Looking for focus: " + i
9839 + " = " + win
9840 + ", flags=" + win.mAttrs.flags
9841 + ", canReceive=" + win.canReceiveKeys());
9842
9843 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009845 // If this window's application has been removed, just skip it.
9846 if (thisApp != null && thisApp.removed) {
9847 i--;
9848 continue;
9849 }
Romain Guy06882f82009-06-10 13:36:04 -07009850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 // If there is a focused app, don't allow focus to go to any
9852 // windows below it. If this is an application window, step
9853 // through the app tokens until we find its app.
9854 if (thisApp != null && nextApp != null && thisApp != nextApp
9855 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9856 int origAppIndex = nextAppIndex;
9857 while (nextAppIndex > 0) {
9858 if (nextApp == mFocusedApp) {
9859 // Whoops, we are below the focused app... no focus
9860 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009861 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009862 TAG, "Reached focused app: " + mFocusedApp);
9863 return null;
9864 }
9865 nextAppIndex--;
9866 nextApp = mAppTokens.get(nextAppIndex);
9867 if (nextApp == thisApp) {
9868 break;
9869 }
9870 }
9871 if (thisApp != nextApp) {
9872 // Uh oh, the app token doesn't exist! This shouldn't
9873 // happen, but if it does we can get totally hosed...
9874 // so restart at the original app.
9875 nextAppIndex = origAppIndex;
9876 nextApp = mAppTokens.get(nextAppIndex);
9877 }
9878 }
9879
9880 // Dispatch to this window if it is wants key events.
9881 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009882 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883 TAG, "Found focus @ " + i + " = " + win);
9884 result = win;
9885 break;
9886 }
9887
9888 i--;
9889 }
9890
9891 return result;
9892 }
9893
9894 private void startFreezingDisplayLocked() {
9895 if (mDisplayFrozen) {
9896 return;
9897 }
Romain Guy06882f82009-06-10 13:36:04 -07009898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009901 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009902 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009903 if (mFreezeGcPending != 0) {
9904 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009905 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009906 mH.removeMessages(H.FORCE_GC);
9907 Runtime.getRuntime().gc();
9908 mFreezeGcPending = now;
9909 }
9910 } else {
9911 mFreezeGcPending = now;
9912 }
Romain Guy06882f82009-06-10 13:36:04 -07009913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009914 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009915
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009916 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009917
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009918 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9919 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009920 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009921 mAppTransitionReady = true;
9922 }
Romain Guy06882f82009-06-10 13:36:04 -07009923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009924 if (PROFILE_ORIENTATION) {
9925 File file = new File("/data/system/frozen");
9926 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9927 }
9928 Surface.freezeDisplay(0);
9929 }
Romain Guy06882f82009-06-10 13:36:04 -07009930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009931 private void stopFreezingDisplayLocked() {
9932 if (!mDisplayFrozen) {
9933 return;
9934 }
Romain Guy06882f82009-06-10 13:36:04 -07009935
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009936 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9937 return;
9938 }
9939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009940 mDisplayFrozen = false;
9941 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9942 if (PROFILE_ORIENTATION) {
9943 Debug.stopMethodTracing();
9944 }
9945 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009946
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009947 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009948
Christopher Tateb696aee2010-04-02 19:08:30 -07009949 // While the display is frozen we don't re-compute the orientation
9950 // to avoid inconsistent states. However, something interesting
9951 // could have actually changed during that time so re-evaluate it
9952 // now to catch that.
9953 if (updateOrientationFromAppTokensLocked()) {
9954 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9955 }
9956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009957 // A little kludge: a lot could have happened while the
9958 // display was frozen, so now that we are coming back we
9959 // do a gc so that any remote references the system
9960 // processes holds on others can be released if they are
9961 // no longer needed.
9962 mH.removeMessages(H.FORCE_GC);
9963 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9964 2000);
Romain Guy06882f82009-06-10 13:36:04 -07009965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009966 mScreenFrozenLock.release();
9967 }
Romain Guy06882f82009-06-10 13:36:04 -07009968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009969 @Override
9970 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
9971 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
9972 != PackageManager.PERMISSION_GRANTED) {
9973 pw.println("Permission Denial: can't dump WindowManager from from pid="
9974 + Binder.getCallingPid()
9975 + ", uid=" + Binder.getCallingUid());
9976 return;
9977 }
Romain Guy06882f82009-06-10 13:36:04 -07009978
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009979 pw.println("Input Dispatcher State:");
9980 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -08009981 pw.println(" ");
9982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 synchronized(mWindowMap) {
9984 pw.println("Current Window Manager state:");
9985 for (int i=mWindows.size()-1; i>=0; i--) {
9986 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009987 pw.print(" Window #"); pw.print(i); pw.print(' ');
9988 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009989 w.dump(pw, " ");
9990 }
9991 if (mInputMethodDialogs.size() > 0) {
9992 pw.println(" ");
9993 pw.println(" Input method dialogs:");
9994 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
9995 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009996 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009997 }
9998 }
9999 if (mPendingRemove.size() > 0) {
10000 pw.println(" ");
10001 pw.println(" Remove pending for:");
10002 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10003 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010004 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10005 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 w.dump(pw, " ");
10007 }
10008 }
10009 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10010 pw.println(" ");
10011 pw.println(" Windows force removing:");
10012 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10013 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010014 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10015 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010016 w.dump(pw, " ");
10017 }
10018 }
10019 if (mDestroySurface.size() > 0) {
10020 pw.println(" ");
10021 pw.println(" Windows waiting to destroy their surface:");
10022 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10023 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010024 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10025 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010026 w.dump(pw, " ");
10027 }
10028 }
10029 if (mLosingFocus.size() > 0) {
10030 pw.println(" ");
10031 pw.println(" Windows losing focus:");
10032 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10033 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010034 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10035 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010036 w.dump(pw, " ");
10037 }
10038 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010039 if (mResizingWindows.size() > 0) {
10040 pw.println(" ");
10041 pw.println(" Windows waiting to resize:");
10042 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10043 WindowState w = mResizingWindows.get(i);
10044 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10045 pw.print(w); pw.println(":");
10046 w.dump(pw, " ");
10047 }
10048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010049 if (mSessions.size() > 0) {
10050 pw.println(" ");
10051 pw.println(" All active sessions:");
10052 Iterator<Session> it = mSessions.iterator();
10053 while (it.hasNext()) {
10054 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010055 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010056 s.dump(pw, " ");
10057 }
10058 }
10059 if (mTokenMap.size() > 0) {
10060 pw.println(" ");
10061 pw.println(" All tokens:");
10062 Iterator<WindowToken> it = mTokenMap.values().iterator();
10063 while (it.hasNext()) {
10064 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010065 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010066 token.dump(pw, " ");
10067 }
10068 }
10069 if (mTokenList.size() > 0) {
10070 pw.println(" ");
10071 pw.println(" Window token list:");
10072 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010073 pw.print(" #"); pw.print(i); pw.print(": ");
10074 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075 }
10076 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010077 if (mWallpaperTokens.size() > 0) {
10078 pw.println(" ");
10079 pw.println(" Wallpaper tokens:");
10080 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10081 WindowToken token = mWallpaperTokens.get(i);
10082 pw.print(" Wallpaper #"); pw.print(i);
10083 pw.print(' '); pw.print(token); pw.println(':');
10084 token.dump(pw, " ");
10085 }
10086 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 if (mAppTokens.size() > 0) {
10088 pw.println(" ");
10089 pw.println(" Application tokens in Z order:");
10090 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010091 pw.print(" App #"); pw.print(i); pw.print(": ");
10092 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010093 }
10094 }
10095 if (mFinishedStarting.size() > 0) {
10096 pw.println(" ");
10097 pw.println(" Finishing start of application tokens:");
10098 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10099 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010100 pw.print(" Finished Starting #"); pw.print(i);
10101 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010102 token.dump(pw, " ");
10103 }
10104 }
10105 if (mExitingTokens.size() > 0) {
10106 pw.println(" ");
10107 pw.println(" Exiting tokens:");
10108 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10109 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010110 pw.print(" Exiting #"); pw.print(i);
10111 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 token.dump(pw, " ");
10113 }
10114 }
10115 if (mExitingAppTokens.size() > 0) {
10116 pw.println(" ");
10117 pw.println(" Exiting application tokens:");
10118 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10119 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010120 pw.print(" Exiting App #"); pw.print(i);
10121 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010122 token.dump(pw, " ");
10123 }
10124 }
10125 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010126 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10127 pw.print(" mLastFocus="); pw.println(mLastFocus);
10128 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10129 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10130 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010131 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010132 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10133 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10134 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10135 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010136 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10137 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10138 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010139 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10140 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10141 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10142 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010143 if (mDimAnimator != null) {
10144 mDimAnimator.printTo(pw);
10145 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010146 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010147 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010148 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010149 pw.print(mInputMethodAnimLayerAdjustment);
10150 pw.print(" mWallpaperAnimLayerAdjustment=");
10151 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010152 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10153 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010154 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10155 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010156 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10157 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010158 pw.print(" mRotation="); pw.print(mRotation);
10159 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10160 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10161 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10162 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10163 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10164 pw.print(" mNextAppTransition=0x");
10165 pw.print(Integer.toHexString(mNextAppTransition));
10166 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010167 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010168 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010169 if (mNextAppTransitionPackage != null) {
10170 pw.print(" mNextAppTransitionPackage=");
10171 pw.print(mNextAppTransitionPackage);
10172 pw.print(", mNextAppTransitionEnter=0x");
10173 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10174 pw.print(", mNextAppTransitionExit=0x");
10175 pw.print(Integer.toHexString(mNextAppTransitionExit));
10176 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010177 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10178 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010179 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10180 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10181 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10182 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010183 if (mOpeningApps.size() > 0) {
10184 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10185 }
10186 if (mClosingApps.size() > 0) {
10187 pw.print(" mClosingApps="); pw.println(mClosingApps);
10188 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010189 if (mToTopApps.size() > 0) {
10190 pw.print(" mToTopApps="); pw.println(mToTopApps);
10191 }
10192 if (mToBottomApps.size() > 0) {
10193 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10194 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010195 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10196 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010197 }
10198 }
10199
Jeff Brown349703e2010-06-22 01:27:15 -070010200 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010201 public void monitor() {
10202 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010203 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010204 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010205
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010206 /**
10207 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010208 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010209 */
10210 private static class DimAnimator {
10211 Surface mDimSurface;
10212 boolean mDimShown = false;
10213 float mDimCurrentAlpha;
10214 float mDimTargetAlpha;
10215 float mDimDeltaPerMs;
10216 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010217
10218 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010219
10220 DimAnimator (SurfaceSession session) {
10221 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010222 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010223 + mDimSurface + ": CREATE");
10224 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010225 mDimSurface = new Surface(session, 0,
10226 "DimSurface",
10227 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010228 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010229 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010230 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010231 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010232 }
10233 }
10234 }
10235
10236 /**
10237 * Show the dim surface.
10238 */
10239 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010240 if (!mDimShown) {
10241 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10242 dw + "x" + dh + ")");
10243 mDimShown = true;
10244 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010245 mLastDimWidth = dw;
10246 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010247 mDimSurface.setPosition(0, 0);
10248 mDimSurface.setSize(dw, dh);
10249 mDimSurface.show();
10250 } catch (RuntimeException e) {
10251 Slog.w(TAG, "Failure showing dim surface", e);
10252 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010253 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10254 mLastDimWidth = dw;
10255 mLastDimHeight = dh;
10256 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010257 }
10258 }
10259
10260 /**
10261 * Set's the dim surface's layer and update dim parameters that will be used in
10262 * {@link updateSurface} after all windows are examined.
10263 */
10264 void updateParameters(WindowState w, long currentTime) {
10265 mDimSurface.setLayer(w.mAnimLayer-1);
10266
10267 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010268 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010269 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010270 if (mDimTargetAlpha != target) {
10271 // If the desired dim level has changed, then
10272 // start an animation to it.
10273 mLastDimAnimTime = currentTime;
10274 long duration = (w.mAnimating && w.mAnimation != null)
10275 ? w.mAnimation.computeDurationHint()
10276 : DEFAULT_DIM_DURATION;
10277 if (target > mDimTargetAlpha) {
10278 // This is happening behind the activity UI,
10279 // so we can make it run a little longer to
10280 // give a stronger impression without disrupting
10281 // the user.
10282 duration *= DIM_DURATION_MULTIPLIER;
10283 }
10284 if (duration < 1) {
10285 // Don't divide by zero
10286 duration = 1;
10287 }
10288 mDimTargetAlpha = target;
10289 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10290 }
10291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010292
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010293 /**
10294 * Updating the surface's alpha. Returns true if the animation continues, or returns
10295 * false when the animation is finished and the dim surface is hidden.
10296 */
10297 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10298 if (!dimming) {
10299 if (mDimTargetAlpha != 0) {
10300 mLastDimAnimTime = currentTime;
10301 mDimTargetAlpha = 0;
10302 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10303 }
10304 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010305
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010306 boolean animating = false;
10307 if (mLastDimAnimTime != 0) {
10308 mDimCurrentAlpha += mDimDeltaPerMs
10309 * (currentTime-mLastDimAnimTime);
10310 boolean more = true;
10311 if (displayFrozen) {
10312 // If the display is frozen, there is no reason to animate.
10313 more = false;
10314 } else if (mDimDeltaPerMs > 0) {
10315 if (mDimCurrentAlpha > mDimTargetAlpha) {
10316 more = false;
10317 }
10318 } else if (mDimDeltaPerMs < 0) {
10319 if (mDimCurrentAlpha < mDimTargetAlpha) {
10320 more = false;
10321 }
10322 } else {
10323 more = false;
10324 }
10325
10326 // Do we need to continue animating?
10327 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010328 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010329 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10330 mLastDimAnimTime = currentTime;
10331 mDimSurface.setAlpha(mDimCurrentAlpha);
10332 animating = true;
10333 } else {
10334 mDimCurrentAlpha = mDimTargetAlpha;
10335 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010336 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010337 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10338 mDimSurface.setAlpha(mDimCurrentAlpha);
10339 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010340 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010341 + ": HIDE");
10342 try {
10343 mDimSurface.hide();
10344 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010345 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010346 }
10347 mDimShown = false;
10348 }
10349 }
10350 }
10351 return animating;
10352 }
10353
10354 public void printTo(PrintWriter pw) {
10355 pw.print(" mDimShown="); pw.print(mDimShown);
10356 pw.print(" current="); pw.print(mDimCurrentAlpha);
10357 pw.print(" target="); pw.print(mDimTargetAlpha);
10358 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10359 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10360 }
10361 }
10362
10363 /**
10364 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10365 * This is used for opening/closing transition for apps in compatible mode.
10366 */
10367 private static class FadeInOutAnimation extends Animation {
10368 int mWidth;
10369 boolean mFadeIn;
10370
10371 public FadeInOutAnimation(boolean fadeIn) {
10372 setInterpolator(new AccelerateInterpolator());
10373 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10374 mFadeIn = fadeIn;
10375 }
10376
10377 @Override
10378 protected void applyTransformation(float interpolatedTime, Transformation t) {
10379 float x = interpolatedTime;
10380 if (!mFadeIn) {
10381 x = 1.0f - x; // reverse the interpolation for fade out
10382 }
10383 if (x < 0.5) {
10384 // move the window out of the screen.
10385 t.getMatrix().setTranslate(mWidth, 0);
10386 } else {
10387 t.getMatrix().setTranslate(0, 0);// show
10388 t.setAlpha((x - 0.5f) * 2);
10389 }
10390 }
10391
10392 @Override
10393 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10394 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10395 mWidth = width;
10396 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010397
10398 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010399 public int getZAdjustment() {
10400 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010401 }
10402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403}