blob: 38f1e1fb800ff30b80ecedf796aa7b04e5b83e17 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.am.BatteryStatsService;
52
53import android.Manifest;
54import android.app.ActivityManagerNative;
55import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070056import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070057import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070059import android.content.Intent;
60import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.pm.ActivityInfo;
62import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.content.res.Configuration;
65import android.graphics.Matrix;
66import android.graphics.PixelFormat;
67import android.graphics.Rect;
68import android.graphics.Region;
69import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070075import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.LocalPowerManager;
77import android.os.Looper;
78import android.os.Message;
79import android.os.Parcel;
80import android.os.ParcelFileDescriptor;
81import android.os.Power;
82import android.os.PowerManager;
83import android.os.Process;
84import android.os.RemoteException;
85import android.os.ServiceManager;
86import android.os.SystemClock;
87import android.os.SystemProperties;
88import android.os.TokenWatcher;
89import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070090import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070092import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080093import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.SparseIntArray;
95import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700104import android.view.InputChannel;
105import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106import android.view.KeyEvent;
107import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.Surface;
109import android.view.SurfaceSession;
110import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700111import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112import android.view.ViewTreeObserver;
113import android.view.WindowManager;
114import android.view.WindowManagerImpl;
115import android.view.WindowManagerPolicy;
116import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700117import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118import android.view.animation.Animation;
119import android.view.animation.AnimationUtils;
120import android.view.animation.Transformation;
121
122import java.io.BufferedWriter;
123import java.io.File;
124import java.io.FileDescriptor;
125import java.io.IOException;
126import java.io.OutputStream;
127import java.io.OutputStreamWriter;
128import java.io.PrintWriter;
129import java.io.StringWriter;
130import java.net.Socket;
131import java.util.ArrayList;
132import java.util.HashMap;
133import java.util.HashSet;
134import java.util.Iterator;
135import java.util.List;
136
137/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700138public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700139 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 static final String TAG = "WindowManager";
141 static final boolean DEBUG = false;
142 static final boolean DEBUG_FOCUS = false;
143 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800144 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800145 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 static final boolean DEBUG_LAYERS = false;
147 static final boolean DEBUG_INPUT = false;
148 static final boolean DEBUG_INPUT_METHOD = false;
149 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700150 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700152 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_APP_TRANSITIONS = false;
154 static final boolean DEBUG_STARTING_WINDOW = false;
155 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700156 static final boolean DEBUG_WALLPAPER = false;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700157 static final boolean DEBUG_FREEZE = 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 Brown46b9ac02010-04-22 18:58:52 -0700477 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478
479 // Who is holding the screen on.
480 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700481 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700482
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700483 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 /**
486 * Whether the UI is currently running in touch mode (not showing
487 * navigational focus because the user is directly pressing the screen).
488 */
489 boolean mInTouchMode = false;
490
491 private ViewServer mViewServer;
492
Dianne Hackbornc485a602009-03-24 22:39:49 -0700493 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700494 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700495
496 // The frame use to limit the size of the app running in compatibility mode.
497 Rect mCompatibleScreenFrame = new Rect();
498 // The surface used to fill the outer rim of the app running in compatibility mode.
499 Surface mBackgroundFillerSurface = null;
500 boolean mBackgroundFillerShown = false;
501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 public static WindowManagerService main(Context context,
503 PowerManagerService pm, boolean haveInputMethods) {
504 WMThread thr = new WMThread(context, pm, haveInputMethods);
505 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 synchronized (thr) {
508 while (thr.mService == null) {
509 try {
510 thr.wait();
511 } catch (InterruptedException e) {
512 }
513 }
514 }
Romain Guy06882f82009-06-10 13:36:04 -0700515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 return thr.mService;
517 }
Romain Guy06882f82009-06-10 13:36:04 -0700518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 static class WMThread extends Thread {
520 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 private final Context mContext;
523 private final PowerManagerService mPM;
524 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 public WMThread(Context context, PowerManagerService pm,
527 boolean haveInputMethods) {
528 super("WindowManager");
529 mContext = context;
530 mPM = pm;
531 mHaveInputMethods = haveInputMethods;
532 }
Romain Guy06882f82009-06-10 13:36:04 -0700533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 public void run() {
535 Looper.prepare();
536 WindowManagerService s = new WindowManagerService(mContext, mPM,
537 mHaveInputMethods);
538 android.os.Process.setThreadPriority(
539 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700540 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 synchronized (this) {
543 mService = s;
544 notifyAll();
545 }
Romain Guy06882f82009-06-10 13:36:04 -0700546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 Looper.loop();
548 }
549 }
550
551 static class PolicyThread extends Thread {
552 private final WindowManagerPolicy mPolicy;
553 private final WindowManagerService mService;
554 private final Context mContext;
555 private final PowerManagerService mPM;
556 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 public PolicyThread(WindowManagerPolicy policy,
559 WindowManagerService service, Context context,
560 PowerManagerService pm) {
561 super("WindowManagerPolicy");
562 mPolicy = policy;
563 mService = service;
564 mContext = context;
565 mPM = pm;
566 }
Romain Guy06882f82009-06-10 13:36:04 -0700567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 public void run() {
569 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800570 WindowManagerPolicyThread.set(this, Looper.myLooper());
571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800573 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 android.os.Process.setThreadPriority(
575 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700576 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 synchronized (this) {
580 mRunning = true;
581 notifyAll();
582 }
Romain Guy06882f82009-06-10 13:36:04 -0700583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 Looper.loop();
585 }
586 }
587
588 private WindowManagerService(Context context, PowerManagerService pm,
589 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700590 if (MEASURE_LATENCY) {
591 lt = new LatencyTimer(100, 1000);
592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 mContext = context;
595 mHaveInputMethods = haveInputMethods;
596 mLimitedAlphaCompositing = context.getResources().getBoolean(
597 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 mPowerManager = pm;
600 mPowerManager.setPolicy(mPolicy);
601 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
602 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
603 "SCREEN_FROZEN");
604 mScreenFrozenLock.setReferenceCounted(false);
605
606 mActivityManager = ActivityManagerNative.getDefault();
607 mBatteryStats = BatteryStatsService.getService();
608
609 // Get persisted window scale setting
610 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
611 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
612 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
613 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700614
Jim Miller284b62e2010-06-08 14:27:42 -0700615 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
616 IntentFilter filter = new IntentFilter();
617 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
618 mContext.registerReceiver(mBroadcastReceiver, filter);
619
Jeff Brown46b9ac02010-04-22 18:58:52 -0700620 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
621 "KEEP_SCREEN_ON_FLAG");
622 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700624 mInputManager = new InputManager(context, this, pmc, mPowerManager);
Romain Guy06882f82009-06-10 13:36:04 -0700625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
627 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 synchronized (thr) {
630 while (!thr.mRunning) {
631 try {
632 thr.wait();
633 } catch (InterruptedException e) {
634 }
635 }
636 }
Romain Guy06882f82009-06-10 13:36:04 -0700637
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700638 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 // Add ourself to the Watchdog monitors.
641 Watchdog.getInstance().addMonitor(this);
642 }
643
644 @Override
645 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
646 throws RemoteException {
647 try {
648 return super.onTransact(code, data, reply, flags);
649 } catch (RuntimeException e) {
650 // The window manager only throws security exceptions, so let's
651 // log all others.
652 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800653 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 }
655 throw e;
656 }
657 }
658
659 private void placeWindowAfter(Object pos, WindowState window) {
660 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800661 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 TAG, "Adding window " + window + " at "
663 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
664 mWindows.add(i+1, window);
665 }
666
667 private void placeWindowBefore(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 + " of " + mWindows.size() + " (before " + pos + ")");
672 mWindows.add(i, window);
673 }
674
675 //This method finds out the index of a window that has the same app token as
676 //win. used for z ordering the windows in mWindows
677 private int findIdxBasedOnAppTokens(WindowState win) {
678 //use a local variable to cache mWindows
679 ArrayList localmWindows = mWindows;
680 int jmax = localmWindows.size();
681 if(jmax == 0) {
682 return -1;
683 }
684 for(int j = (jmax-1); j >= 0; j--) {
685 WindowState wentry = (WindowState)localmWindows.get(j);
686 if(wentry.mAppToken == win.mAppToken) {
687 return j;
688 }
689 }
690 return -1;
691 }
Romain Guy06882f82009-06-10 13:36:04 -0700692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
694 final IWindow client = win.mClient;
695 final WindowToken token = win.mToken;
696 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 final int N = localmWindows.size();
699 final WindowState attached = win.mAttachedWindow;
700 int i;
701 if (attached == null) {
702 int tokenWindowsPos = token.windows.size();
703 if (token.appWindowToken != null) {
704 int index = tokenWindowsPos-1;
705 if (index >= 0) {
706 // If this application has existing windows, we
707 // simply place the new window on top of them... but
708 // keep the starting window on top.
709 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
710 // Base windows go behind everything else.
711 placeWindowBefore(token.windows.get(0), win);
712 tokenWindowsPos = 0;
713 } else {
714 AppWindowToken atoken = win.mAppToken;
715 if (atoken != null &&
716 token.windows.get(index) == atoken.startingWindow) {
717 placeWindowBefore(token.windows.get(index), win);
718 tokenWindowsPos--;
719 } else {
720 int newIdx = findIdxBasedOnAppTokens(win);
721 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700722 //there is a window above this one associated with the same
723 //apptoken note that the window could be a floating window
724 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800726 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700727 TAG, "Adding window " + win + " at "
728 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 }
732 }
733 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800734 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 TAG, "Figuring out where to add app window "
736 + client.asBinder() + " (token=" + token + ")");
737 // Figure out where the window should go, based on the
738 // order of applications.
739 final int NA = mAppTokens.size();
740 Object pos = null;
741 for (i=NA-1; i>=0; i--) {
742 AppWindowToken t = mAppTokens.get(i);
743 if (t == token) {
744 i--;
745 break;
746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800747
Dianne Hackborna8f60182009-09-01 19:01:50 -0700748 // We haven't reached the token yet; if this token
749 // is not going to the bottom and has windows, we can
750 // use it as an anchor for when we do reach the token.
751 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 pos = t.windows.get(0);
753 }
754 }
755 // We now know the index into the apps. If we found
756 // an app window above, that gives us the position; else
757 // we need to look some more.
758 if (pos != null) {
759 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700760 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 mTokenMap.get(((WindowState)pos).mClient.asBinder());
762 if (atoken != null) {
763 final int NC = atoken.windows.size();
764 if (NC > 0) {
765 WindowState bottom = atoken.windows.get(0);
766 if (bottom.mSubLayer < 0) {
767 pos = bottom;
768 }
769 }
770 }
771 placeWindowBefore(pos, win);
772 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700773 // Continue looking down until we find the first
774 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 while (i >= 0) {
776 AppWindowToken t = mAppTokens.get(i);
777 final int NW = t.windows.size();
778 if (NW > 0) {
779 pos = t.windows.get(NW-1);
780 break;
781 }
782 i--;
783 }
784 if (pos != null) {
785 // Move in front of any windows attached to this
786 // one.
787 WindowToken atoken =
788 mTokenMap.get(((WindowState)pos).mClient.asBinder());
789 if (atoken != null) {
790 final int NC = atoken.windows.size();
791 if (NC > 0) {
792 WindowState top = atoken.windows.get(NC-1);
793 if (top.mSubLayer >= 0) {
794 pos = top;
795 }
796 }
797 }
798 placeWindowAfter(pos, win);
799 } else {
800 // Just search for the start of this layer.
801 final int myLayer = win.mBaseLayer;
802 for (i=0; i<N; i++) {
803 WindowState w = (WindowState)localmWindows.get(i);
804 if (w.mBaseLayer > myLayer) {
805 break;
806 }
807 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800808 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700809 TAG, "Adding window " + win + " at "
810 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 localmWindows.add(i, win);
812 }
813 }
814 }
815 } else {
816 // Figure out where window should go, based on layer.
817 final int myLayer = win.mBaseLayer;
818 for (i=N-1; i>=0; i--) {
819 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
820 i++;
821 break;
822 }
823 }
824 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800825 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700826 TAG, "Adding window " + win + " at "
827 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 localmWindows.add(i, win);
829 }
830 if (addToToken) {
831 token.windows.add(tokenWindowsPos, win);
832 }
833
834 } else {
835 // Figure out this window's ordering relative to the window
836 // it is attached to.
837 final int NA = token.windows.size();
838 final int sublayer = win.mSubLayer;
839 int largestSublayer = Integer.MIN_VALUE;
840 WindowState windowWithLargestSublayer = null;
841 for (i=0; i<NA; i++) {
842 WindowState w = token.windows.get(i);
843 final int wSublayer = w.mSubLayer;
844 if (wSublayer >= largestSublayer) {
845 largestSublayer = wSublayer;
846 windowWithLargestSublayer = w;
847 }
848 if (sublayer < 0) {
849 // For negative sublayers, we go below all windows
850 // in the same sublayer.
851 if (wSublayer >= sublayer) {
852 if (addToToken) {
853 token.windows.add(i, win);
854 }
855 placeWindowBefore(
856 wSublayer >= 0 ? attached : w, win);
857 break;
858 }
859 } else {
860 // For positive sublayers, we go above all windows
861 // in the same sublayer.
862 if (wSublayer > sublayer) {
863 if (addToToken) {
864 token.windows.add(i, win);
865 }
866 placeWindowBefore(w, win);
867 break;
868 }
869 }
870 }
871 if (i >= NA) {
872 if (addToToken) {
873 token.windows.add(win);
874 }
875 if (sublayer < 0) {
876 placeWindowBefore(attached, win);
877 } else {
878 placeWindowAfter(largestSublayer >= 0
879 ? windowWithLargestSublayer
880 : attached,
881 win);
882 }
883 }
884 }
Romain Guy06882f82009-06-10 13:36:04 -0700885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 if (win.mAppToken != null && addToToken) {
887 win.mAppToken.allAppWindows.add(win);
888 }
889 }
Romain Guy06882f82009-06-10 13:36:04 -0700890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 static boolean canBeImeTarget(WindowState w) {
892 final int fl = w.mAttrs.flags
893 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
894 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
895 return w.isVisibleOrAdding();
896 }
897 return false;
898 }
Romain Guy06882f82009-06-10 13:36:04 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
901 final ArrayList localmWindows = mWindows;
902 final int N = localmWindows.size();
903 WindowState w = null;
904 int i = N;
905 while (i > 0) {
906 i--;
907 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700908
Joe Onorato8a9b2202010-02-26 18:56:32 -0800909 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 // + Integer.toHexString(w.mAttrs.flags));
911 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800912 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 // Yet more tricksyness! If this window is a "starting"
915 // window, we do actually want to be on top of it, but
916 // it is not -really- where input will go. So if the caller
917 // is not actually looking to move the IME, look down below
918 // for a real window to target...
919 if (!willMove
920 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
921 && i > 0) {
922 WindowState wb = (WindowState)localmWindows.get(i-1);
923 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
924 i--;
925 w = wb;
926 }
927 }
928 break;
929 }
930 }
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700933
Joe Onorato8a9b2202010-02-26 18:56:32 -0800934 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 if (willMove && w != null) {
938 final WindowState curTarget = mInputMethodTarget;
939 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 // Now some fun for dealing with window animations that
942 // modify the Z order. We need to look at all windows below
943 // the current target that are in this app, finding the highest
944 // visible one in layering.
945 AppWindowToken token = curTarget.mAppToken;
946 WindowState highestTarget = null;
947 int highestPos = 0;
948 if (token.animating || token.animation != null) {
949 int pos = 0;
950 pos = localmWindows.indexOf(curTarget);
951 while (pos >= 0) {
952 WindowState win = (WindowState)localmWindows.get(pos);
953 if (win.mAppToken != token) {
954 break;
955 }
956 if (!win.mRemoved) {
957 if (highestTarget == null || win.mAnimLayer >
958 highestTarget.mAnimLayer) {
959 highestTarget = win;
960 highestPos = pos;
961 }
962 }
963 pos--;
964 }
965 }
Romain Guy06882f82009-06-10 13:36:04 -0700966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800968 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 + mNextAppTransition + " " + highestTarget
970 + " animating=" + highestTarget.isAnimating()
971 + " layer=" + highestTarget.mAnimLayer
972 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700973
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700974 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 // If we are currently setting up for an animation,
976 // hold everything until we can find out what will happen.
977 mInputMethodTargetWaitingAnim = true;
978 mInputMethodTarget = highestTarget;
979 return highestPos + 1;
980 } else if (highestTarget.isAnimating() &&
981 highestTarget.mAnimLayer > w.mAnimLayer) {
982 // If the window we are currently targeting is involved
983 // with an animation, and it is on top of the next target
984 // we will be over, then hold off on moving until
985 // that is done.
986 mInputMethodTarget = highestTarget;
987 return highestPos + 1;
988 }
989 }
990 }
991 }
Romain Guy06882f82009-06-10 13:36:04 -0700992
Joe Onorato8a9b2202010-02-26 18:56:32 -0800993 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 if (w != null) {
995 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800996 if (DEBUG_INPUT_METHOD) {
997 RuntimeException e = null;
998 if (!HIDE_STACK_CRAWLS) {
999 e = new RuntimeException();
1000 e.fillInStackTrace();
1001 }
1002 Slog.w(TAG, "Moving IM target from "
1003 + mInputMethodTarget + " to " + w, e);
1004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 mInputMethodTarget = w;
1006 if (w.mAppToken != null) {
1007 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1008 } else {
1009 setInputMethodAnimLayerAdjustment(0);
1010 }
1011 }
1012 return i+1;
1013 }
1014 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001015 if (DEBUG_INPUT_METHOD) {
1016 RuntimeException e = null;
1017 if (!HIDE_STACK_CRAWLS) {
1018 e = new RuntimeException();
1019 e.fillInStackTrace();
1020 }
1021 Slog.w(TAG, "Moving IM target from "
1022 + mInputMethodTarget + " to null", e);
1023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 mInputMethodTarget = null;
1025 setInputMethodAnimLayerAdjustment(0);
1026 }
1027 return -1;
1028 }
Romain Guy06882f82009-06-10 13:36:04 -07001029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 void addInputMethodWindowToListLocked(WindowState win) {
1031 int pos = findDesiredInputMethodWindowIndexLocked(true);
1032 if (pos >= 0) {
1033 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001034 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001035 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 mWindows.add(pos, win);
1037 moveInputMethodDialogsLocked(pos+1);
1038 return;
1039 }
1040 win.mTargetAppToken = null;
1041 addWindowToListInOrderLocked(win, true);
1042 moveInputMethodDialogsLocked(pos);
1043 }
Romain Guy06882f82009-06-10 13:36:04 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001046 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 mInputMethodAnimLayerAdjustment = adj;
1048 WindowState imw = mInputMethodWindow;
1049 if (imw != null) {
1050 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001051 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 + " anim layer: " + imw.mAnimLayer);
1053 int wi = imw.mChildWindows.size();
1054 while (wi > 0) {
1055 wi--;
1056 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1057 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001058 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 + " anim layer: " + cw.mAnimLayer);
1060 }
1061 }
1062 int di = mInputMethodDialogs.size();
1063 while (di > 0) {
1064 di --;
1065 imw = mInputMethodDialogs.get(di);
1066 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001067 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 + " anim layer: " + imw.mAnimLayer);
1069 }
1070 }
Romain Guy06882f82009-06-10 13:36:04 -07001071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1073 int wpos = mWindows.indexOf(win);
1074 if (wpos >= 0) {
1075 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001076 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 mWindows.remove(wpos);
1078 int NC = win.mChildWindows.size();
1079 while (NC > 0) {
1080 NC--;
1081 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1082 int cpos = mWindows.indexOf(cw);
1083 if (cpos >= 0) {
1084 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001085 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001086 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 mWindows.remove(cpos);
1088 }
1089 }
1090 }
1091 return interestingPos;
1092 }
Romain Guy06882f82009-06-10 13:36:04 -07001093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 private void reAddWindowToListInOrderLocked(WindowState win) {
1095 addWindowToListInOrderLocked(win, false);
1096 // This is a hack to get all of the child windows added as well
1097 // at the right position. Child windows should be rare and
1098 // this case should be rare, so it shouldn't be that big a deal.
1099 int wpos = mWindows.indexOf(win);
1100 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001101 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001102 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 mWindows.remove(wpos);
1104 reAddWindowLocked(wpos, win);
1105 }
1106 }
Romain Guy06882f82009-06-10 13:36:04 -07001107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 void logWindowList(String prefix) {
1109 int N = mWindows.size();
1110 while (N > 0) {
1111 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001112 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114 }
Romain Guy06882f82009-06-10 13:36:04 -07001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 void moveInputMethodDialogsLocked(int pos) {
1117 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001120 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 for (int i=0; i<N; i++) {
1122 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1123 }
1124 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001125 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 logWindowList(" ");
1127 }
Romain Guy06882f82009-06-10 13:36:04 -07001128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 if (pos >= 0) {
1130 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1131 if (pos < mWindows.size()) {
1132 WindowState wp = (WindowState)mWindows.get(pos);
1133 if (wp == mInputMethodWindow) {
1134 pos++;
1135 }
1136 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001137 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 for (int i=0; i<N; i++) {
1139 WindowState win = dialogs.get(i);
1140 win.mTargetAppToken = targetAppToken;
1141 pos = reAddWindowLocked(pos, win);
1142 }
1143 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001144 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 logWindowList(" ");
1146 }
1147 return;
1148 }
1149 for (int i=0; i<N; i++) {
1150 WindowState win = dialogs.get(i);
1151 win.mTargetAppToken = null;
1152 reAddWindowToListInOrderLocked(win);
1153 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001154 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 logWindowList(" ");
1156 }
1157 }
1158 }
Romain Guy06882f82009-06-10 13:36:04 -07001159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1161 final WindowState imWin = mInputMethodWindow;
1162 final int DN = mInputMethodDialogs.size();
1163 if (imWin == null && DN == 0) {
1164 return false;
1165 }
Romain Guy06882f82009-06-10 13:36:04 -07001166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1168 if (imPos >= 0) {
1169 // In this case, the input method windows are to be placed
1170 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 // First check to see if the input method windows are already
1173 // located here, and contiguous.
1174 final int N = mWindows.size();
1175 WindowState firstImWin = imPos < N
1176 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 // Figure out the actual input method window that should be
1179 // at the bottom of their stack.
1180 WindowState baseImWin = imWin != null
1181 ? imWin : mInputMethodDialogs.get(0);
1182 if (baseImWin.mChildWindows.size() > 0) {
1183 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1184 if (cw.mSubLayer < 0) baseImWin = cw;
1185 }
Romain Guy06882f82009-06-10 13:36:04 -07001186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 if (firstImWin == baseImWin) {
1188 // The windows haven't moved... but are they still contiguous?
1189 // First find the top IM window.
1190 int pos = imPos+1;
1191 while (pos < N) {
1192 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1193 break;
1194 }
1195 pos++;
1196 }
1197 pos++;
1198 // Now there should be no more input method windows above.
1199 while (pos < N) {
1200 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1201 break;
1202 }
1203 pos++;
1204 }
1205 if (pos >= N) {
1206 // All is good!
1207 return false;
1208 }
1209 }
Romain Guy06882f82009-06-10 13:36:04 -07001210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 if (imWin != null) {
1212 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001213 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 logWindowList(" ");
1215 }
1216 imPos = tmpRemoveWindowLocked(imPos, imWin);
1217 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001218 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 logWindowList(" ");
1220 }
1221 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1222 reAddWindowLocked(imPos, imWin);
1223 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001224 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 logWindowList(" ");
1226 }
1227 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1228 } else {
1229 moveInputMethodDialogsLocked(imPos);
1230 }
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 } else {
1233 // In this case, the input method windows go in a fixed layer,
1234 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001237 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 tmpRemoveWindowLocked(0, imWin);
1239 imWin.mTargetAppToken = null;
1240 reAddWindowToListInOrderLocked(imWin);
1241 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001242 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 logWindowList(" ");
1244 }
1245 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1246 } else {
1247 moveInputMethodDialogsLocked(-1);;
1248 }
Romain Guy06882f82009-06-10 13:36:04 -07001249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
Romain Guy06882f82009-06-10 13:36:04 -07001251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 if (needAssignLayers) {
1253 assignLayersLocked();
1254 }
Romain Guy06882f82009-06-10 13:36:04 -07001255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 return true;
1257 }
Romain Guy06882f82009-06-10 13:36:04 -07001258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 void adjustInputMethodDialogsLocked() {
1260 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1261 }
Romain Guy06882f82009-06-10 13:36:04 -07001262
Dianne Hackborn25994b42009-09-04 14:21:19 -07001263 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001264 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001265 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1266 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1267 ? wallpaperTarget.mAppToken.animation : null)
1268 + " upper=" + mUpperWallpaperTarget
1269 + " lower=" + mLowerWallpaperTarget);
1270 return (wallpaperTarget != null
1271 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1272 && wallpaperTarget.mAppToken.animation != null)))
1273 || mUpperWallpaperTarget != null
1274 || mLowerWallpaperTarget != null;
1275 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001276
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001277 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1278 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001279
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001280 int adjustWallpaperWindowsLocked() {
1281 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001282
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001283 final int dw = mDisplay.getWidth();
1284 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001285
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001286 // First find top-most window that has asked to be on top of the
1287 // wallpaper; all wallpapers go behind it.
1288 final ArrayList localmWindows = mWindows;
1289 int N = localmWindows.size();
1290 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001291 WindowState foundW = null;
1292 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001293 WindowState topCurW = null;
1294 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001295 int i = N;
1296 while (i > 0) {
1297 i--;
1298 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001299 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1300 if (topCurW == null) {
1301 topCurW = w;
1302 topCurI = i;
1303 }
1304 continue;
1305 }
1306 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001307 if (w.mAppToken != null) {
1308 // If this window's app token is hidden and not animating,
1309 // it is of no interest to us.
1310 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001311 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001312 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001313 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001314 continue;
1315 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001316 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001317 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001318 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1319 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001320 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001321 && (mWallpaperTarget == w
1322 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001323 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001324 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001325 foundW = w;
1326 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001327 if (w == mWallpaperTarget && ((w.mAppToken != null
1328 && w.mAppToken.animation != null)
1329 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001330 // The current wallpaper target is animating, so we'll
1331 // look behind it for another possible target and figure
1332 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001334 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001335 continue;
1336 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001337 break;
1338 }
1339 }
1340
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001341 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001342 // If we are currently waiting for an app transition, and either
1343 // the current target or the next target are involved with it,
1344 // then hold off on doing anything with the wallpaper.
1345 // Note that we are checking here for just whether the target
1346 // is part of an app token... which is potentially overly aggressive
1347 // (the app token may not be involved in the transition), but good
1348 // enough (we'll just wait until whatever transition is pending
1349 // executes).
1350 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001351 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001352 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001353 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001354 }
1355 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001356 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001357 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001358 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001359 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001360 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001361
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001362 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001363 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001364 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001365 + " oldTarget: " + mWallpaperTarget);
1366 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001367
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001368 mLowerWallpaperTarget = null;
1369 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001370
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001371 WindowState oldW = mWallpaperTarget;
1372 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001373
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001374 // Now what is happening... if the current and new targets are
1375 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001376 if (foundW != null && oldW != null) {
1377 boolean oldAnim = oldW.mAnimation != null
1378 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1379 boolean foundAnim = foundW.mAnimation != null
1380 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001382 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001383 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001384 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001385 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 int oldI = localmWindows.indexOf(oldW);
1387 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001388 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001389 }
1390 if (oldI >= 0) {
1391 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001392 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 + "=" + oldW + "; new#" + foundI
1394 + "=" + foundW);
1395 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001396
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001398 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001399 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001400 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 }
1402 mWallpaperTarget = oldW;
1403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001404
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001405 // Now set the upper and lower wallpaper targets
1406 // correctly, and make sure that we are positioning
1407 // the wallpaper below the lower.
1408 if (foundI > oldI) {
1409 // The new target is on top of the old one.
1410 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001411 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001412 }
1413 mUpperWallpaperTarget = foundW;
1414 mLowerWallpaperTarget = oldW;
1415 foundW = oldW;
1416 foundI = oldI;
1417 } else {
1418 // The new target is below the old one.
1419 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001420 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001421 }
1422 mUpperWallpaperTarget = oldW;
1423 mLowerWallpaperTarget = foundW;
1424 }
1425 }
1426 }
1427 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001428
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001429 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001430 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001431 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1432 || (mLowerWallpaperTarget.mAppToken != null
1433 && mLowerWallpaperTarget.mAppToken.animation != null);
1434 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1435 || (mUpperWallpaperTarget.mAppToken != null
1436 && mUpperWallpaperTarget.mAppToken.animation != null);
1437 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001438 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001439 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001440 }
1441 mLowerWallpaperTarget = null;
1442 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001443 }
1444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001445
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001446 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001447 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001448 // The window is visible to the compositor... but is it visible
1449 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001450 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001452
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001453 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001454 // its layer adjustment. Only do this if we are not transfering
1455 // between two wallpaper targets.
1456 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001457 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001459
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001460 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1461 * TYPE_LAYER_MULTIPLIER
1462 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001463
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001464 // Now w is the window we are supposed to be behind... but we
1465 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001466 // AND any starting window associated with it, AND below the
1467 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001468 while (foundI > 0) {
1469 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001470 if (wb.mBaseLayer < maxLayer &&
1471 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001472 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001473 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001474 // This window is not related to the previous one in any
1475 // interesting way, so stop here.
1476 break;
1477 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001478 foundW = wb;
1479 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001480 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001481 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001482 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001483 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001484
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001485 if (foundW == null && topCurW != null) {
1486 // There is no wallpaper target, so it goes at the bottom.
1487 // We will assume it is the same place as last time, if known.
1488 foundW = topCurW;
1489 foundI = topCurI+1;
1490 } else {
1491 // Okay i is the position immediately above the wallpaper. Look at
1492 // what is below it for later.
1493 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1494 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001495
Dianne Hackborn284ac932009-08-28 10:34:25 -07001496 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001497 if (mWallpaperTarget.mWallpaperX >= 0) {
1498 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001499 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001500 }
1501 if (mWallpaperTarget.mWallpaperY >= 0) {
1502 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001503 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001504 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001505 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001506
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001507 // Start stepping backwards from here, ensuring that our wallpaper windows
1508 // are correctly placed.
1509 int curTokenIndex = mWallpaperTokens.size();
1510 while (curTokenIndex > 0) {
1511 curTokenIndex--;
1512 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001513 if (token.hidden == visible) {
1514 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1515 token.hidden = !visible;
1516 // Need to do a layout to ensure the wallpaper now has the
1517 // correct size.
1518 mLayoutNeeded = true;
1519 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001520
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001521 int curWallpaperIndex = token.windows.size();
1522 while (curWallpaperIndex > 0) {
1523 curWallpaperIndex--;
1524 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001525
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001526 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001527 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001528 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001529
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001530 // First, make sure the client has the current visibility
1531 // state.
1532 if (wallpaper.mWallpaperVisible != visible) {
1533 wallpaper.mWallpaperVisible = visible;
1534 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001535 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001536 "Setting visibility of wallpaper " + wallpaper
1537 + ": " + visible);
1538 wallpaper.mClient.dispatchAppVisibility(visible);
1539 } catch (RemoteException e) {
1540 }
1541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001543 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001544 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001545 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001546
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001547 // First, if this window is at the current index, then all
1548 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001549 if (wallpaper == foundW) {
1550 foundI--;
1551 foundW = foundI > 0
1552 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001553 continue;
1554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001555
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001556 // The window didn't match... the current wallpaper window,
1557 // wherever it is, is in the wrong place, so make sure it is
1558 // not in the list.
1559 int oldIndex = localmWindows.indexOf(wallpaper);
1560 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001561 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001562 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001563 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001564 if (oldIndex < foundI) {
1565 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001566 }
1567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001568
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001570 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001571 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001572 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001573
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001574 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001575 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001576 }
1577 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001578
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001579 return changed;
1580 }
1581
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001582 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001583 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001584 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001585 mWallpaperAnimLayerAdjustment = adj;
1586 int curTokenIndex = mWallpaperTokens.size();
1587 while (curTokenIndex > 0) {
1588 curTokenIndex--;
1589 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1590 int curWallpaperIndex = token.windows.size();
1591 while (curWallpaperIndex > 0) {
1592 curWallpaperIndex--;
1593 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1594 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001595 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001596 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001597 }
1598 }
1599 }
1600
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001601 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1602 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001603 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001604 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001605 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001606 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001607 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1608 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1609 changed = wallpaperWin.mXOffset != offset;
1610 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001611 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001612 + wallpaperWin + " x: " + offset);
1613 wallpaperWin.mXOffset = offset;
1614 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001615 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001616 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001617 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001618 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001620
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001621 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001622 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1624 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1625 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001627 + wallpaperWin + " y: " + offset);
1628 changed = true;
1629 wallpaperWin.mYOffset = offset;
1630 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001631 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001632 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001636
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001637 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001638 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001639 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001640 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1641 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001642 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001643 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001644 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001645 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001646 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1647 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001648 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001649 if (mWaitingOnWallpaper != null) {
1650 long start = SystemClock.uptimeMillis();
1651 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1652 < start) {
1653 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001655 "Waiting for offset complete...");
1656 mWindowMap.wait(WALLPAPER_TIMEOUT);
1657 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001658 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001659 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001660 if ((start+WALLPAPER_TIMEOUT)
1661 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001662 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001663 + wallpaperWin);
1664 mLastWallpaperTimeoutTime = start;
1665 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001666 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001667 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001668 }
1669 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001670 } catch (RemoteException e) {
1671 }
1672 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001673
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001674 return changed;
1675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001676
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001677 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001679 if (mWaitingOnWallpaper != null &&
1680 mWaitingOnWallpaper.mClient.asBinder() == window) {
1681 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001682 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
1684 }
1685 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001686
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001687 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001688 final int dw = mDisplay.getWidth();
1689 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001690
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001691 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001693 WindowState target = mWallpaperTarget;
1694 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001695 if (target.mWallpaperX >= 0) {
1696 mLastWallpaperX = target.mWallpaperX;
1697 } else if (changingTarget.mWallpaperX >= 0) {
1698 mLastWallpaperX = changingTarget.mWallpaperX;
1699 }
1700 if (target.mWallpaperY >= 0) {
1701 mLastWallpaperY = target.mWallpaperY;
1702 } else if (changingTarget.mWallpaperY >= 0) {
1703 mLastWallpaperY = changingTarget.mWallpaperY;
1704 }
1705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001706
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001707 int curTokenIndex = mWallpaperTokens.size();
1708 while (curTokenIndex > 0) {
1709 curTokenIndex--;
1710 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1711 int curWallpaperIndex = token.windows.size();
1712 while (curWallpaperIndex > 0) {
1713 curWallpaperIndex--;
1714 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1715 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1716 wallpaper.computeShownFrameLocked();
1717 changed = true;
1718 // We only want to be synchronous with one wallpaper.
1719 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001720 }
1721 }
1722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001724 return changed;
1725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001726
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001727 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001728 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001729 final int dw = mDisplay.getWidth();
1730 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001731
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001732 int curTokenIndex = mWallpaperTokens.size();
1733 while (curTokenIndex > 0) {
1734 curTokenIndex--;
1735 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001736 if (token.hidden == visible) {
1737 token.hidden = !visible;
1738 // Need to do a layout to ensure the wallpaper now has the
1739 // correct size.
1740 mLayoutNeeded = true;
1741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001743 int curWallpaperIndex = token.windows.size();
1744 while (curWallpaperIndex > 0) {
1745 curWallpaperIndex--;
1746 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1747 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001748 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001750
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001751 if (wallpaper.mWallpaperVisible != visible) {
1752 wallpaper.mWallpaperVisible = visible;
1753 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001754 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001755 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001756 + ": " + visible);
1757 wallpaper.mClient.dispatchAppVisibility(visible);
1758 } catch (RemoteException e) {
1759 }
1760 }
1761 }
1762 }
1763 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001765 public int addWindow(Session session, IWindow client,
1766 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001767 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001768 int res = mPolicy.checkAddPermission(attrs);
1769 if (res != WindowManagerImpl.ADD_OKAY) {
1770 return res;
1771 }
Romain Guy06882f82009-06-10 13:36:04 -07001772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001773 boolean reportNewConfig = false;
1774 WindowState attachedWindow = null;
1775 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001777 synchronized(mWindowMap) {
1778 // Instantiating a Display requires talking with the simulator,
1779 // so don't do it until we know the system is mostly up and
1780 // running.
1781 if (mDisplay == null) {
1782 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1783 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001784 mInitialDisplayWidth = mDisplay.getWidth();
1785 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001786 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 reportNewConfig = true;
1788 }
Romain Guy06882f82009-06-10 13:36:04 -07001789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001791 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1793 }
1794
1795 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001796 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001798 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 + attrs.token + ". Aborting.");
1800 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1801 }
1802 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1803 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001804 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 + attrs.token + ". Aborting.");
1806 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1807 }
1808 }
1809
1810 boolean addToken = false;
1811 WindowToken token = mTokenMap.get(attrs.token);
1812 if (token == null) {
1813 if (attrs.type >= FIRST_APPLICATION_WINDOW
1814 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 + attrs.token + ". Aborting.");
1817 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1818 }
1819 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001820 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 + attrs.token + ". Aborting.");
1822 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1823 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001824 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001825 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001826 + attrs.token + ". Aborting.");
1827 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 token = new WindowToken(attrs.token, -1, false);
1830 addToken = true;
1831 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1832 && attrs.type <= LAST_APPLICATION_WINDOW) {
1833 AppWindowToken atoken = token.appWindowToken;
1834 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001835 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 + token + ". Aborting.");
1837 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1838 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001839 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 + token + ". Aborting.");
1841 return WindowManagerImpl.ADD_APP_EXITING;
1842 }
1843 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1844 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001845 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1847 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1848 }
1849 } else if (attrs.type == TYPE_INPUT_METHOD) {
1850 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001851 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 + attrs.token + ". Aborting.");
1853 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1854 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001855 } else if (attrs.type == TYPE_WALLPAPER) {
1856 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001857 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001858 + attrs.token + ". Aborting.");
1859 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1860 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 }
1862
1863 win = new WindowState(session, client, token,
1864 attachedWindow, attrs, viewVisibility);
1865 if (win.mDeathRecipient == null) {
1866 // Client has apparently died, so there is no reason to
1867 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 + " that is dead, aborting.");
1870 return WindowManagerImpl.ADD_APP_EXITING;
1871 }
1872
1873 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 res = mPolicy.prepareAddWindowLw(win, attrs);
1876 if (res != WindowManagerImpl.ADD_OKAY) {
1877 return res;
1878 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001879
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001880 if (outInputChannel != null) {
1881 String name = win.makeInputChannelName();
1882 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1883 win.mInputChannel = inputChannels[0];
1884 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1885
1886 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001887 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888
1889 // From now on, no exceptions or errors allowed!
1890
1891 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 if (addToken) {
1896 mTokenMap.put(attrs.token, token);
1897 mTokenList.add(token);
1898 }
1899 win.attach();
1900 mWindowMap.put(client.asBinder(), win);
1901
1902 if (attrs.type == TYPE_APPLICATION_STARTING &&
1903 token.appWindowToken != null) {
1904 token.appWindowToken.startingWindow = win;
1905 }
1906
1907 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 if (attrs.type == TYPE_INPUT_METHOD) {
1910 mInputMethodWindow = win;
1911 addInputMethodWindowToListLocked(win);
1912 imMayMove = false;
1913 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1914 mInputMethodDialogs.add(win);
1915 addWindowToListInOrderLocked(win, true);
1916 adjustInputMethodDialogsLocked();
1917 imMayMove = false;
1918 } else {
1919 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001920 if (attrs.type == TYPE_WALLPAPER) {
1921 mLastWallpaperTimeoutTime = 0;
1922 adjustWallpaperWindowsLocked();
1923 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001924 adjustWallpaperWindowsLocked();
1925 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 }
Romain Guy06882f82009-06-10 13:36:04 -07001927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 if (mInTouchMode) {
1933 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1934 }
1935 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1936 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1937 }
Romain Guy06882f82009-06-10 13:36:04 -07001938
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001939 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001941 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1942 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 imMayMove = false;
1944 }
1945 }
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001948 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 }
Romain Guy06882f82009-06-10 13:36:04 -07001950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 assignLayersLocked();
1952 // Don't do layout here, the window must call
1953 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 //dump();
1956
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001957 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001958 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001959 }
Jeff Brown349703e2010-06-22 01:27:15 -07001960
Joe Onorato8a9b2202010-02-26 18:56:32 -08001961 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 TAG, "New client " + client.asBinder()
1963 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001964
1965 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1966 reportNewConfig = true;
1967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 }
1969
1970 // sendNewConfiguration() checks caller permissions so we must call it with
1971 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1972 // identity anyway, so it's safe to just clear & restore around this whole
1973 // block.
1974 final long origId = Binder.clearCallingIdentity();
1975 if (reportNewConfig) {
1976 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 }
1978 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 return res;
1981 }
Romain Guy06882f82009-06-10 13:36:04 -07001982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 public void removeWindow(Session session, IWindow client) {
1984 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001985 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 if (win == null) {
1987 return;
1988 }
1989 removeWindowLocked(session, win);
1990 }
1991 }
Romain Guy06882f82009-06-10 13:36:04 -07001992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 public void removeWindowLocked(Session session, WindowState win) {
1994
Joe Onorato8a9b2202010-02-26 18:56:32 -08001995 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 TAG, "Remove " + win + " client="
1997 + Integer.toHexString(System.identityHashCode(
1998 win.mClient.asBinder()))
1999 + ", surface=" + win.mSurface);
2000
2001 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002002
Joe Onorato8a9b2202010-02-26 18:56:32 -08002003 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2005 + " mExiting=" + win.mExiting
2006 + " isAnimating=" + win.isAnimating()
2007 + " app-animation="
2008 + (win.mAppToken != null ? win.mAppToken.animation : null)
2009 + " inPendingTransaction="
2010 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2011 + " mDisplayFrozen=" + mDisplayFrozen);
2012 // Visibility of the removed window. Will be used later to update orientation later on.
2013 boolean wasVisible = false;
2014 // First, see if we need to run an animation. If we do, we have
2015 // to hold off on removing the window until the animation is done.
2016 // If the display is frozen, just remove immediately, since the
2017 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002018 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002019 // If we are not currently running the exit animation, we
2020 // need to see about starting one.
2021 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2024 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2025 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2026 }
2027 // Try starting an animation.
2028 if (applyAnimationLocked(win, transit, false)) {
2029 win.mExiting = true;
2030 }
2031 }
2032 if (win.mExiting || win.isAnimating()) {
2033 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002034 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002035 win.mExiting = true;
2036 win.mRemoveOnExit = true;
2037 mLayoutNeeded = true;
2038 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2039 performLayoutAndPlaceSurfacesLocked();
2040 if (win.mAppToken != null) {
2041 win.mAppToken.updateReportedVisibilityLocked();
2042 }
2043 //dump();
2044 Binder.restoreCallingIdentity(origId);
2045 return;
2046 }
2047 }
2048
2049 removeWindowInnerLocked(session, win);
2050 // Removing a visible window will effect the computed orientation
2051 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002052 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002053 != mForcedAppOrientation
2054 && updateOrientationFromAppTokensLocked()) {
2055 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 }
2057 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2058 Binder.restoreCallingIdentity(origId);
2059 }
Romain Guy06882f82009-06-10 13:36:04 -07002060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002061 private void removeWindowInnerLocked(Session session, WindowState win) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002062 mInputMonitor.windowIsBeingRemovedLw(win);
Romain Guy06882f82009-06-10 13:36:04 -07002063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002064 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 if (mInputMethodTarget == win) {
2067 moveInputMethodWindowsIfNeededLocked(false);
2068 }
Romain Guy06882f82009-06-10 13:36:04 -07002069
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002070 if (false) {
2071 RuntimeException e = new RuntimeException("here");
2072 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002073 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002074 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 mPolicy.removeWindowLw(win);
2077 win.removeLocked();
2078
2079 mWindowMap.remove(win.mClient.asBinder());
2080 mWindows.remove(win);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002081 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082
2083 if (mInputMethodWindow == win) {
2084 mInputMethodWindow = null;
2085 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2086 mInputMethodDialogs.remove(win);
2087 }
Romain Guy06882f82009-06-10 13:36:04 -07002088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 final WindowToken token = win.mToken;
2090 final AppWindowToken atoken = win.mAppToken;
2091 token.windows.remove(win);
2092 if (atoken != null) {
2093 atoken.allAppWindows.remove(win);
2094 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002095 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 TAG, "**** Removing window " + win + ": count="
2097 + token.windows.size());
2098 if (token.windows.size() == 0) {
2099 if (!token.explicit) {
2100 mTokenMap.remove(token.token);
2101 mTokenList.remove(token);
2102 } else if (atoken != null) {
2103 atoken.firstWindowDrawn = false;
2104 }
2105 }
2106
2107 if (atoken != null) {
2108 if (atoken.startingWindow == win) {
2109 atoken.startingWindow = null;
2110 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2111 // If this is the last window and we had requested a starting
2112 // transition window, well there is no point now.
2113 atoken.startingData = null;
2114 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2115 // If this is the last window except for a starting transition
2116 // window, we need to get rid of the starting transition.
2117 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002118 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002119 + ": no more real windows");
2120 }
2121 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2122 mH.sendMessage(m);
2123 }
2124 }
Romain Guy06882f82009-06-10 13:36:04 -07002125
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002126 if (win.mAttrs.type == TYPE_WALLPAPER) {
2127 mLastWallpaperTimeoutTime = 0;
2128 adjustWallpaperWindowsLocked();
2129 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002130 adjustWallpaperWindowsLocked();
2131 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 if (!mInLayout) {
2134 assignLayersLocked();
2135 mLayoutNeeded = true;
2136 performLayoutAndPlaceSurfacesLocked();
2137 if (win.mAppToken != null) {
2138 win.mAppToken.updateReportedVisibilityLocked();
2139 }
2140 }
2141 }
2142
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002143 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2144 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2145 + ": " + msg + " / " + w.mAttrs.getTitle();
2146 if (where != null) {
2147 Slog.i(TAG, str, where);
2148 } else {
2149 Slog.i(TAG, str);
2150 }
2151 }
2152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2154 long origId = Binder.clearCallingIdentity();
2155 try {
2156 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002157 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002159 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 Surface.openTransaction();
2161 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002162 if (SHOW_TRANSACTIONS) logSurface(w,
2163 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 w.mSurface.setTransparentRegionHint(region);
2165 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002166 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 Surface.closeTransaction();
2168 }
2169 }
2170 }
2171 } finally {
2172 Binder.restoreCallingIdentity(origId);
2173 }
2174 }
2175
2176 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002177 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 Rect visibleInsets) {
2179 long origId = Binder.clearCallingIdentity();
2180 try {
2181 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002182 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 if (w != null) {
2184 w.mGivenInsetsPending = false;
2185 w.mGivenContentInsets.set(contentInsets);
2186 w.mGivenVisibleInsets.set(visibleInsets);
2187 w.mTouchableInsets = touchableInsets;
2188 mLayoutNeeded = true;
2189 performLayoutAndPlaceSurfacesLocked();
2190 }
2191 }
2192 } finally {
2193 Binder.restoreCallingIdentity(origId);
2194 }
2195 }
Romain Guy06882f82009-06-10 13:36:04 -07002196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 public void getWindowDisplayFrame(Session session, IWindow client,
2198 Rect outDisplayFrame) {
2199 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002200 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 if (win == null) {
2202 outDisplayFrame.setEmpty();
2203 return;
2204 }
2205 outDisplayFrame.set(win.mDisplayFrame);
2206 }
2207 }
2208
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002209 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2210 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002211 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2212 window.mWallpaperX = x;
2213 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002214 window.mWallpaperXStep = xStep;
2215 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002216 if (updateWallpaperOffsetLocked(window, true)) {
2217 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002218 }
2219 }
2220 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002221
Dianne Hackborn75804932009-10-20 20:15:20 -07002222 void wallpaperCommandComplete(IBinder window, Bundle result) {
2223 synchronized (mWindowMap) {
2224 if (mWaitingOnWallpaper != null &&
2225 mWaitingOnWallpaper.mClient.asBinder() == window) {
2226 mWaitingOnWallpaper = null;
2227 mWindowMap.notifyAll();
2228 }
2229 }
2230 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002231
Dianne Hackborn75804932009-10-20 20:15:20 -07002232 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2233 String action, int x, int y, int z, Bundle extras, boolean sync) {
2234 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2235 || window == mUpperWallpaperTarget) {
2236 boolean doWait = sync;
2237 int curTokenIndex = mWallpaperTokens.size();
2238 while (curTokenIndex > 0) {
2239 curTokenIndex--;
2240 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2241 int curWallpaperIndex = token.windows.size();
2242 while (curWallpaperIndex > 0) {
2243 curWallpaperIndex--;
2244 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2245 try {
2246 wallpaper.mClient.dispatchWallpaperCommand(action,
2247 x, y, z, extras, sync);
2248 // We only want to be synchronous with one wallpaper.
2249 sync = false;
2250 } catch (RemoteException e) {
2251 }
2252 }
2253 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002254
Dianne Hackborn75804932009-10-20 20:15:20 -07002255 if (doWait) {
2256 // XXX Need to wait for result.
2257 }
2258 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002259
Dianne Hackborn75804932009-10-20 20:15:20 -07002260 return null;
2261 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 public int relayoutWindow(Session session, IWindow client,
2264 WindowManager.LayoutParams attrs, int requestedWidth,
2265 int requestedHeight, int viewVisibility, boolean insetsPending,
2266 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002267 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 boolean displayed = false;
2269 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002270 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002274 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 if (win == null) {
2276 return 0;
2277 }
2278 win.mRequestedWidth = requestedWidth;
2279 win.mRequestedHeight = requestedHeight;
2280
2281 if (attrs != null) {
2282 mPolicy.adjustWindowParamsLw(attrs);
2283 }
Romain Guy06882f82009-06-10 13:36:04 -07002284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 int attrChanges = 0;
2286 int flagChanges = 0;
2287 if (attrs != null) {
2288 flagChanges = win.mAttrs.flags ^= attrs.flags;
2289 attrChanges = win.mAttrs.copyFrom(attrs);
2290 }
2291
Joe Onorato8a9b2202010-02-26 18:56:32 -08002292 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293
2294 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2295 win.mAlpha = attrs.alpha;
2296 }
2297
2298 final boolean scaledWindow =
2299 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2300
2301 if (scaledWindow) {
2302 // requested{Width|Height} Surface's physical size
2303 // attrs.{width|height} Size on screen
2304 win.mHScale = (attrs.width != requestedWidth) ?
2305 (attrs.width / (float)requestedWidth) : 1.0f;
2306 win.mVScale = (attrs.height != requestedHeight) ?
2307 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002308 } else {
2309 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 }
2311
2312 boolean imMayMove = (flagChanges&(
2313 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2314 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 boolean focusMayChange = win.mViewVisibility != viewVisibility
2317 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2318 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002319
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002320 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2321 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 win.mRelayoutCalled = true;
2324 final int oldVisibility = win.mViewVisibility;
2325 win.mViewVisibility = viewVisibility;
2326 if (viewVisibility == View.VISIBLE &&
2327 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2328 displayed = !win.isVisibleLw();
2329 if (win.mExiting) {
2330 win.mExiting = false;
2331 win.mAnimation = null;
2332 }
2333 if (win.mDestroying) {
2334 win.mDestroying = false;
2335 mDestroySurface.remove(win);
2336 }
2337 if (oldVisibility == View.GONE) {
2338 win.mEnterAnimationPending = true;
2339 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002340 if (displayed) {
2341 if (win.mSurface != null && !win.mDrawPending
2342 && !win.mCommitDrawPending && !mDisplayFrozen
2343 && mPolicy.isScreenOn()) {
2344 applyEnterAnimationLocked(win);
2345 }
2346 if ((win.mAttrs.flags
2347 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2348 if (DEBUG_VISIBILITY) Slog.v(TAG,
2349 "Relayout window turning screen on: " + win);
2350 win.mTurnOnScreen = true;
2351 }
2352 int diff = 0;
2353 if (win.mConfiguration != mCurConfiguration
2354 && (win.mConfiguration == null
2355 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2356 win.mConfiguration = mCurConfiguration;
2357 if (DEBUG_CONFIGURATION) {
2358 Slog.i(TAG, "Window " + win + " visible with new config: "
2359 + win.mConfiguration + " / 0x"
2360 + Integer.toHexString(diff));
2361 }
2362 outConfig.setTo(mCurConfiguration);
2363 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2366 // To change the format, we need to re-build the surface.
2367 win.destroySurfaceLocked();
2368 displayed = true;
2369 }
2370 try {
2371 Surface surface = win.createSurfaceLocked();
2372 if (surface != null) {
2373 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002374 win.mReportDestroySurface = false;
2375 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002376 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002377 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002379 // For some reason there isn't a surface. Clear the
2380 // caller's object so they see the same state.
2381 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 }
2383 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002384 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002385 + client + " (" + win.mAttrs.getTitle() + ")",
2386 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 Binder.restoreCallingIdentity(origId);
2388 return 0;
2389 }
2390 if (displayed) {
2391 focusMayChange = true;
2392 }
2393 if (win.mAttrs.type == TYPE_INPUT_METHOD
2394 && mInputMethodWindow == null) {
2395 mInputMethodWindow = win;
2396 imMayMove = true;
2397 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002398 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2399 && win.mAppToken != null
2400 && win.mAppToken.startingWindow != null) {
2401 // Special handling of starting window over the base
2402 // window of the app: propagate lock screen flags to it,
2403 // to provide the correct semantics while starting.
2404 final int mask =
2405 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002406 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2407 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002408 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2409 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 } else {
2412 win.mEnterAnimationPending = false;
2413 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002414 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002415 + ": mExiting=" + win.mExiting
2416 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 // If we are not currently running the exit animation, we
2418 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002419 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 // Try starting an animation; if there isn't one, we
2421 // can destroy the surface right away.
2422 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2423 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2424 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2425 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002426 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002428 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 win.mExiting = true;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002430 mInputMonitor.windowIsBecomingInvisibleLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 } else if (win.isAnimating()) {
2432 // Currently in a hide animation... turn this into
2433 // an exit.
2434 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002435 } else if (win == mWallpaperTarget) {
2436 // If the wallpaper is currently behind this
2437 // window, we need to change both of them inside
2438 // of a transaction to avoid artifacts.
2439 win.mExiting = true;
2440 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 } else {
2442 if (mInputMethodWindow == win) {
2443 mInputMethodWindow = null;
2444 }
2445 win.destroySurfaceLocked();
2446 }
2447 }
2448 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002449
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002450 if (win.mSurface == null || (win.getAttrs().flags
2451 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2452 || win.mSurfacePendingDestroy) {
2453 // We are being called from a local process, which
2454 // means outSurface holds its current surface. Ensure the
2455 // surface object is cleared, but we don't want it actually
2456 // destroyed at this point.
2457 win.mSurfacePendingDestroy = false;
2458 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002459 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002460 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002461 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002462 "Keeping surface, will report destroy: " + win);
2463 win.mReportDestroySurface = true;
2464 outSurface.copyFrom(win.mSurface);
2465 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 }
2467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 if (focusMayChange) {
2469 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2470 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 imMayMove = false;
2472 }
2473 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2474 }
Romain Guy06882f82009-06-10 13:36:04 -07002475
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002476 // updateFocusedWindowLocked() already assigned layers so we only need to
2477 // reassign them at this point if the IM window state gets shuffled
2478 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002481 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2482 // Little hack here -- we -should- be able to rely on the
2483 // function to return true if the IME has moved and needs
2484 // its layer recomputed. However, if the IME was hidden
2485 // and isn't actually moved in the list, its layer may be
2486 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 assignLayers = true;
2488 }
2489 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002490 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002491 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002492 assignLayers = true;
2493 }
2494 }
Romain Guy06882f82009-06-10 13:36:04 -07002495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 mLayoutNeeded = true;
2497 win.mGivenInsetsPending = insetsPending;
2498 if (assignLayers) {
2499 assignLayersLocked();
2500 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002501 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002503 if (displayed && win.mIsWallpaper) {
2504 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002505 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 if (win.mAppToken != null) {
2508 win.mAppToken.updateReportedVisibilityLocked();
2509 }
2510 outFrame.set(win.mFrame);
2511 outContentInsets.set(win.mContentInsets);
2512 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002513 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002515 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 + ", requestedHeight=" + requestedHeight
2517 + ", viewVisibility=" + viewVisibility
2518 + "\nRelayout returning frame=" + outFrame
2519 + ", surface=" + outSurface);
2520
Joe Onorato8a9b2202010-02-26 18:56:32 -08002521 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2523
2524 inTouchMode = mInTouchMode;
2525 }
2526
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002527 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 sendNewConfiguration();
2529 }
Romain Guy06882f82009-06-10 13:36:04 -07002530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2534 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2535 }
2536
2537 public void finishDrawingWindow(Session session, IWindow client) {
2538 final long origId = Binder.clearCallingIdentity();
2539 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002540 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002542 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2543 adjustWallpaperWindowsLocked();
2544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 mLayoutNeeded = true;
2546 performLayoutAndPlaceSurfacesLocked();
2547 }
2548 }
2549 Binder.restoreCallingIdentity(origId);
2550 }
2551
2552 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002553 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 + (lp != null ? lp.packageName : null)
2555 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2556 if (lp != null && lp.windowAnimations != 0) {
2557 // If this is a system resource, don't try to load it from the
2558 // application resources. It is nice to avoid loading application
2559 // resources if we can.
2560 String packageName = lp.packageName != null ? lp.packageName : "android";
2561 int resId = lp.windowAnimations;
2562 if ((resId&0xFF000000) == 0x01000000) {
2563 packageName = "android";
2564 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002565 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 + packageName);
2567 return AttributeCache.instance().get(packageName, resId,
2568 com.android.internal.R.styleable.WindowAnimation);
2569 }
2570 return null;
2571 }
Romain Guy06882f82009-06-10 13:36:04 -07002572
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002573 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002574 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002575 + packageName + " resId=0x" + Integer.toHexString(resId));
2576 if (packageName != null) {
2577 if ((resId&0xFF000000) == 0x01000000) {
2578 packageName = "android";
2579 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002580 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002581 + packageName);
2582 return AttributeCache.instance().get(packageName, resId,
2583 com.android.internal.R.styleable.WindowAnimation);
2584 }
2585 return null;
2586 }
2587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 private void applyEnterAnimationLocked(WindowState win) {
2589 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2590 if (win.mEnterAnimationPending) {
2591 win.mEnterAnimationPending = false;
2592 transit = WindowManagerPolicy.TRANSIT_ENTER;
2593 }
2594
2595 applyAnimationLocked(win, transit, true);
2596 }
2597
2598 private boolean applyAnimationLocked(WindowState win,
2599 int transit, boolean isEntrance) {
2600 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2601 // If we are trying to apply an animation, but already running
2602 // an animation of the same type, then just leave that one alone.
2603 return true;
2604 }
Romain Guy06882f82009-06-10 13:36:04 -07002605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 // Only apply an animation if the display isn't frozen. If it is
2607 // frozen, there is no reason to animate and it can cause strange
2608 // artifacts when we unfreeze the display if some different animation
2609 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002610 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 int anim = mPolicy.selectAnimationLw(win, transit);
2612 int attr = -1;
2613 Animation a = null;
2614 if (anim != 0) {
2615 a = AnimationUtils.loadAnimation(mContext, anim);
2616 } else {
2617 switch (transit) {
2618 case WindowManagerPolicy.TRANSIT_ENTER:
2619 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2620 break;
2621 case WindowManagerPolicy.TRANSIT_EXIT:
2622 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2623 break;
2624 case WindowManagerPolicy.TRANSIT_SHOW:
2625 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2626 break;
2627 case WindowManagerPolicy.TRANSIT_HIDE:
2628 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2629 break;
2630 }
2631 if (attr >= 0) {
2632 a = loadAnimation(win.mAttrs, attr);
2633 }
2634 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002635 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2637 + " mAnimation=" + win.mAnimation
2638 + " isEntrance=" + isEntrance);
2639 if (a != null) {
2640 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002641 RuntimeException e = null;
2642 if (!HIDE_STACK_CRAWLS) {
2643 e = new RuntimeException();
2644 e.fillInStackTrace();
2645 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002646 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 }
2648 win.setAnimation(a);
2649 win.mAnimationIsEntrance = isEntrance;
2650 }
2651 } else {
2652 win.clearAnimation();
2653 }
2654
2655 return win.mAnimation != null;
2656 }
2657
2658 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2659 int anim = 0;
2660 Context context = mContext;
2661 if (animAttr >= 0) {
2662 AttributeCache.Entry ent = getCachedAnimations(lp);
2663 if (ent != null) {
2664 context = ent.context;
2665 anim = ent.array.getResourceId(animAttr, 0);
2666 }
2667 }
2668 if (anim != 0) {
2669 return AnimationUtils.loadAnimation(context, anim);
2670 }
2671 return null;
2672 }
Romain Guy06882f82009-06-10 13:36:04 -07002673
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002674 private Animation loadAnimation(String packageName, int resId) {
2675 int anim = 0;
2676 Context context = mContext;
2677 if (resId >= 0) {
2678 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2679 if (ent != null) {
2680 context = ent.context;
2681 anim = resId;
2682 }
2683 }
2684 if (anim != 0) {
2685 return AnimationUtils.loadAnimation(context, anim);
2686 }
2687 return null;
2688 }
2689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 private boolean applyAnimationLocked(AppWindowToken wtoken,
2691 WindowManager.LayoutParams lp, int transit, boolean enter) {
2692 // Only apply an animation if the display isn't frozen. If it is
2693 // frozen, there is no reason to animate and it can cause strange
2694 // artifacts when we unfreeze the display if some different animation
2695 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002696 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002697 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002698 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002699 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002700 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002701 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002702 } else if (mNextAppTransitionPackage != null) {
2703 a = loadAnimation(mNextAppTransitionPackage, enter ?
2704 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002705 } else {
2706 int animAttr = 0;
2707 switch (transit) {
2708 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2709 animAttr = enter
2710 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2711 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2712 break;
2713 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2714 animAttr = enter
2715 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2716 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2717 break;
2718 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2719 animAttr = enter
2720 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2721 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2722 break;
2723 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2724 animAttr = enter
2725 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2726 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2727 break;
2728 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2729 animAttr = enter
2730 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2731 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2732 break;
2733 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2734 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002735 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002736 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2737 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002738 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002739 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002740 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2741 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002742 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002743 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002744 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002745 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2746 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2747 break;
2748 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2749 animAttr = enter
2750 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2751 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2752 break;
2753 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2754 animAttr = enter
2755 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2756 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002757 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002758 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002759 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002760 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002761 + " anim=" + a
2762 + " animAttr=0x" + Integer.toHexString(animAttr)
2763 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002764 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 if (a != null) {
2766 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002767 RuntimeException e = null;
2768 if (!HIDE_STACK_CRAWLS) {
2769 e = new RuntimeException();
2770 e.fillInStackTrace();
2771 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002772 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 }
2774 wtoken.setAnimation(a);
2775 }
2776 } else {
2777 wtoken.clearAnimation();
2778 }
2779
2780 return wtoken.animation != null;
2781 }
2782
2783 // -------------------------------------------------------------
2784 // Application Window Tokens
2785 // -------------------------------------------------------------
2786
2787 public void validateAppTokens(List tokens) {
2788 int v = tokens.size()-1;
2789 int m = mAppTokens.size()-1;
2790 while (v >= 0 && m >= 0) {
2791 AppWindowToken wtoken = mAppTokens.get(m);
2792 if (wtoken.removed) {
2793 m--;
2794 continue;
2795 }
2796 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002797 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2799 }
2800 v--;
2801 m--;
2802 }
2803 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002804 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 v--;
2806 }
2807 while (m >= 0) {
2808 AppWindowToken wtoken = mAppTokens.get(m);
2809 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002810 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 }
2812 m--;
2813 }
2814 }
2815
2816 boolean checkCallingPermission(String permission, String func) {
2817 // Quick check: if the calling permission is me, it's all okay.
2818 if (Binder.getCallingPid() == Process.myPid()) {
2819 return true;
2820 }
Romain Guy06882f82009-06-10 13:36:04 -07002821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 if (mContext.checkCallingPermission(permission)
2823 == PackageManager.PERMISSION_GRANTED) {
2824 return true;
2825 }
2826 String msg = "Permission Denial: " + func + " from pid="
2827 + Binder.getCallingPid()
2828 + ", uid=" + Binder.getCallingUid()
2829 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002830 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831 return false;
2832 }
Romain Guy06882f82009-06-10 13:36:04 -07002833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834 AppWindowToken findAppWindowToken(IBinder token) {
2835 WindowToken wtoken = mTokenMap.get(token);
2836 if (wtoken == null) {
2837 return null;
2838 }
2839 return wtoken.appWindowToken;
2840 }
Romain Guy06882f82009-06-10 13:36:04 -07002841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 public void addWindowToken(IBinder token, int type) {
2843 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2844 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002845 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 }
Romain Guy06882f82009-06-10 13:36:04 -07002847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 synchronized(mWindowMap) {
2849 WindowToken wtoken = mTokenMap.get(token);
2850 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002851 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 return;
2853 }
2854 wtoken = new WindowToken(token, type, true);
2855 mTokenMap.put(token, wtoken);
2856 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002857 if (type == TYPE_WALLPAPER) {
2858 mWallpaperTokens.add(wtoken);
2859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 }
2861 }
Romain Guy06882f82009-06-10 13:36:04 -07002862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 public void removeWindowToken(IBinder token) {
2864 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2865 "removeWindowToken()")) {
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 }
2868
2869 final long origId = Binder.clearCallingIdentity();
2870 synchronized(mWindowMap) {
2871 WindowToken wtoken = mTokenMap.remove(token);
2872 mTokenList.remove(wtoken);
2873 if (wtoken != null) {
2874 boolean delayed = false;
2875 if (!wtoken.hidden) {
2876 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 final int N = wtoken.windows.size();
2879 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 for (int i=0; i<N; i++) {
2882 WindowState win = wtoken.windows.get(i);
2883
2884 if (win.isAnimating()) {
2885 delayed = true;
2886 }
Romain Guy06882f82009-06-10 13:36:04 -07002887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 if (win.isVisibleNow()) {
2889 applyAnimationLocked(win,
2890 WindowManagerPolicy.TRANSIT_EXIT, false);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002891 mInputMonitor.windowIsBeingRemovedLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 changed = true;
2893 }
2894 }
2895
2896 if (changed) {
2897 mLayoutNeeded = true;
2898 performLayoutAndPlaceSurfacesLocked();
2899 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2900 }
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 if (delayed) {
2903 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002904 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2905 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 }
2907 }
Romain Guy06882f82009-06-10 13:36:04 -07002908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002910 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 }
2912 }
2913 Binder.restoreCallingIdentity(origId);
2914 }
2915
2916 public void addAppToken(int addPos, IApplicationToken token,
2917 int groupId, int requestedOrientation, boolean fullscreen) {
2918 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2919 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002920 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 }
Jeff Brown349703e2010-06-22 01:27:15 -07002922
2923 // Get the dispatching timeout here while we are not holding any locks so that it
2924 // can be cached by the AppWindowToken. The timeout value is used later by the
2925 // input dispatcher in code that does hold locks. If we did not cache the value
2926 // here we would run the chance of introducing a deadlock between the window manager
2927 // (which holds locks while updating the input dispatcher state) and the activity manager
2928 // (which holds locks while querying the application token).
2929 long inputDispatchingTimeoutNanos;
2930 try {
2931 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2932 } catch (RemoteException ex) {
2933 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2934 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2935 }
Romain Guy06882f82009-06-10 13:36:04 -07002936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 synchronized(mWindowMap) {
2938 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2939 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002940 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 return;
2942 }
2943 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002944 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 wtoken.groupId = groupId;
2946 wtoken.appFullscreen = fullscreen;
2947 wtoken.requestedOrientation = requestedOrientation;
2948 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002949 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950 mTokenMap.put(token.asBinder(), wtoken);
2951 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 // Application tokens start out hidden.
2954 wtoken.hidden = true;
2955 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 //dump();
2958 }
2959 }
Romain Guy06882f82009-06-10 13:36:04 -07002960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 public void setAppGroupId(IBinder token, int groupId) {
2962 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2963 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002964 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 }
2966
2967 synchronized(mWindowMap) {
2968 AppWindowToken wtoken = findAppWindowToken(token);
2969 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002970 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 return;
2972 }
2973 wtoken.groupId = groupId;
2974 }
2975 }
Romain Guy06882f82009-06-10 13:36:04 -07002976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 public int getOrientationFromWindowsLocked() {
2978 int pos = mWindows.size() - 1;
2979 while (pos >= 0) {
2980 WindowState wtoken = (WindowState) mWindows.get(pos);
2981 pos--;
2982 if (wtoken.mAppToken != null) {
2983 // We hit an application window. so the orientation will be determined by the
2984 // app window. No point in continuing further.
2985 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2986 }
Christopher Tateb696aee2010-04-02 19:08:30 -07002987 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 continue;
2989 }
2990 int req = wtoken.mAttrs.screenOrientation;
2991 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
2992 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
2993 continue;
2994 } else {
2995 return req;
2996 }
2997 }
2998 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2999 }
Romain Guy06882f82009-06-10 13:36:04 -07003000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003002 int pos = mAppTokens.size() - 1;
3003 int curGroup = 0;
3004 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3005 boolean findingBehind = false;
3006 boolean haveGroup = false;
3007 boolean lastFullscreen = false;
3008 while (pos >= 0) {
3009 AppWindowToken wtoken = mAppTokens.get(pos);
3010 pos--;
3011 // if we're about to tear down this window and not seek for
3012 // the behind activity, don't use it for orientation
3013 if (!findingBehind
3014 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3015 continue;
3016 }
3017
3018 if (!haveGroup) {
3019 // We ignore any hidden applications on the top.
3020 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003021 continue;
3022 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003023 haveGroup = true;
3024 curGroup = wtoken.groupId;
3025 lastOrientation = wtoken.requestedOrientation;
3026 } else if (curGroup != wtoken.groupId) {
3027 // If we have hit a new application group, and the bottom
3028 // of the previous group didn't explicitly say to use
3029 // the orientation behind it, and the last app was
3030 // full screen, then we'll stick with the
3031 // user's orientation.
3032 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3033 && lastFullscreen) {
3034 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003037 int or = wtoken.requestedOrientation;
3038 // If this application is fullscreen, and didn't explicitly say
3039 // to use the orientation behind it, then just take whatever
3040 // orientation it has and ignores whatever is under it.
3041 lastFullscreen = wtoken.appFullscreen;
3042 if (lastFullscreen
3043 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3044 return or;
3045 }
3046 // If this application has requested an explicit orientation,
3047 // then use it.
3048 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3049 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3050 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3051 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3052 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3053 return or;
3054 }
3055 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3056 }
3057 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
Romain Guy06882f82009-06-10 13:36:04 -07003059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003061 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003062 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3063 "updateOrientationFromAppTokens()")) {
3064 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3065 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003066
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003067 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003069
3070 synchronized(mWindowMap) {
3071 if (updateOrientationFromAppTokensLocked()) {
3072 if (freezeThisOneIfNeeded != null) {
3073 AppWindowToken wtoken = findAppWindowToken(
3074 freezeThisOneIfNeeded);
3075 if (wtoken != null) {
3076 startAppFreezingScreenLocked(wtoken,
3077 ActivityInfo.CONFIG_ORIENTATION);
3078 }
3079 }
3080 config = computeNewConfigurationLocked();
3081
3082 } else if (currentConfig != null) {
3083 // No obvious action we need to take, but if our current
3084 // state mismatches the activity maanager's, update it
3085 mTempConfiguration.setToDefaults();
3086 if (computeNewConfigurationLocked(mTempConfiguration)) {
3087 if (currentConfig.diff(mTempConfiguration) != 0) {
3088 mWaitingForConfig = true;
3089 mLayoutNeeded = true;
3090 startFreezingDisplayLocked();
3091 config = new Configuration(mTempConfiguration);
3092 }
3093 }
3094 }
3095 }
3096
Dianne Hackborncfaef692009-06-15 14:24:44 -07003097 Binder.restoreCallingIdentity(ident);
3098 return config;
3099 }
3100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003102 * Determine the new desired orientation of the display, returning
3103 * a non-null new Configuration if it has changed from the current
3104 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3105 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3106 * SCREEN. This will typically be done for you if you call
3107 * sendNewConfiguration().
3108 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 * The orientation is computed from non-application windows first. If none of
3110 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003111 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3113 * android.os.IBinder)
3114 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003115 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003116 if (mDisplayFrozen) {
3117 // If the display is frozen, some activities may be in the middle
3118 // of restarting, and thus have removed their old window. If the
3119 // window has the flag to hide the lock screen, then the lock screen
3120 // can re-appear and inflict its own orientation on us. Keep the
3121 // orientation stable until this all settles down.
3122 return false;
3123 }
3124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 long ident = Binder.clearCallingIdentity();
3127 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003128 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 mForcedAppOrientation = req;
3132 //send a message to Policy indicating orientation change to take
3133 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003134 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003135 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3136 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3137 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 }
3139 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003140
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003141 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003142 } finally {
3143 Binder.restoreCallingIdentity(ident);
3144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 }
Romain Guy06882f82009-06-10 13:36:04 -07003146
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003147 int computeForcedAppOrientationLocked() {
3148 int req = getOrientationFromWindowsLocked();
3149 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3150 req = getOrientationFromAppTokensLocked();
3151 }
3152 return req;
3153 }
Romain Guy06882f82009-06-10 13:36:04 -07003154
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003155 public void setNewConfiguration(Configuration config) {
3156 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3157 "setNewConfiguration()")) {
3158 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3159 }
3160
3161 synchronized(mWindowMap) {
3162 mCurConfiguration = new Configuration(config);
3163 mWaitingForConfig = false;
3164 performLayoutAndPlaceSurfacesLocked();
3165 }
3166 }
3167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3169 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3170 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003171 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 }
Romain Guy06882f82009-06-10 13:36:04 -07003173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 synchronized(mWindowMap) {
3175 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3176 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003177 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178 return;
3179 }
Romain Guy06882f82009-06-10 13:36:04 -07003180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 wtoken.requestedOrientation = requestedOrientation;
3182 }
3183 }
Romain Guy06882f82009-06-10 13:36:04 -07003184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 public int getAppOrientation(IApplicationToken token) {
3186 synchronized(mWindowMap) {
3187 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3188 if (wtoken == null) {
3189 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3190 }
Romain Guy06882f82009-06-10 13:36:04 -07003191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 return wtoken.requestedOrientation;
3193 }
3194 }
Romain Guy06882f82009-06-10 13:36:04 -07003195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3197 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3198 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003199 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 }
3201
3202 synchronized(mWindowMap) {
3203 boolean changed = false;
3204 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003205 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 changed = mFocusedApp != null;
3207 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003208 if (changed) {
3209 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003210 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 } else {
3212 AppWindowToken newFocus = findAppWindowToken(token);
3213 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003214 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 return;
3216 }
3217 changed = mFocusedApp != newFocus;
3218 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003219 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003220 if (changed) {
3221 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003222 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 }
3224
3225 if (moveFocusNow && changed) {
3226 final long origId = Binder.clearCallingIdentity();
3227 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3228 Binder.restoreCallingIdentity(origId);
3229 }
3230 }
3231 }
3232
3233 public void prepareAppTransition(int transit) {
3234 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3235 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003236 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 }
Romain Guy06882f82009-06-10 13:36:04 -07003238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003240 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003241 TAG, "Prepare app transition: transit=" + transit
3242 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003243 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003244 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3245 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003247 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3248 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3249 // Opening a new task always supersedes a close for the anim.
3250 mNextAppTransition = transit;
3251 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3252 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3253 // Opening a new activity always supersedes a close for the anim.
3254 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 }
3256 mAppTransitionReady = false;
3257 mAppTransitionTimeout = false;
3258 mStartingIconInTransition = false;
3259 mSkipAppTransitionAnimation = false;
3260 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3261 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3262 5000);
3263 }
3264 }
3265 }
3266
3267 public int getPendingAppTransition() {
3268 return mNextAppTransition;
3269 }
Romain Guy06882f82009-06-10 13:36:04 -07003270
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003271 public void overridePendingAppTransition(String packageName,
3272 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003273 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003274 mNextAppTransitionPackage = packageName;
3275 mNextAppTransitionEnter = enterAnim;
3276 mNextAppTransitionExit = exitAnim;
3277 }
3278 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 public void executeAppTransition() {
3281 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3282 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003283 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 }
Romain Guy06882f82009-06-10 13:36:04 -07003285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003287 if (DEBUG_APP_TRANSITIONS) {
3288 RuntimeException e = new RuntimeException("here");
3289 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003290 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003291 + mNextAppTransition, e);
3292 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003293 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 mAppTransitionReady = true;
3295 final long origId = Binder.clearCallingIdentity();
3296 performLayoutAndPlaceSurfacesLocked();
3297 Binder.restoreCallingIdentity(origId);
3298 }
3299 }
3300 }
3301
3302 public void setAppStartingWindow(IBinder token, String pkg,
3303 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3304 IBinder transferFrom, boolean createIfNeeded) {
3305 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3306 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003307 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 }
3309
3310 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003311 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3313 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 AppWindowToken wtoken = findAppWindowToken(token);
3316 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003317 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 return;
3319 }
3320
3321 // If the display is frozen, we won't do anything until the
3322 // actual window is displayed so there is no reason to put in
3323 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003324 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 return;
3326 }
Romain Guy06882f82009-06-10 13:36:04 -07003327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 if (wtoken.startingData != null) {
3329 return;
3330 }
Romain Guy06882f82009-06-10 13:36:04 -07003331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 if (transferFrom != null) {
3333 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3334 if (ttoken != null) {
3335 WindowState startingWindow = ttoken.startingWindow;
3336 if (startingWindow != null) {
3337 if (mStartingIconInTransition) {
3338 // In this case, the starting icon has already
3339 // been displayed, so start letting windows get
3340 // shown immediately without any more transitions.
3341 mSkipAppTransitionAnimation = true;
3342 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003343 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 "Moving existing starting from " + ttoken
3345 + " to " + wtoken);
3346 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 // Transfer the starting window over to the new
3349 // token.
3350 wtoken.startingData = ttoken.startingData;
3351 wtoken.startingView = ttoken.startingView;
3352 wtoken.startingWindow = startingWindow;
3353 ttoken.startingData = null;
3354 ttoken.startingView = null;
3355 ttoken.startingWindow = null;
3356 ttoken.startingMoved = true;
3357 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003358 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003360 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003361 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 mWindows.remove(startingWindow);
3363 ttoken.windows.remove(startingWindow);
3364 ttoken.allAppWindows.remove(startingWindow);
3365 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 // Propagate other interesting state between the
3368 // tokens. If the old token is displayed, we should
3369 // immediately force the new one to be displayed. If
3370 // it is animating, we need to move that animation to
3371 // the new one.
3372 if (ttoken.allDrawn) {
3373 wtoken.allDrawn = true;
3374 }
3375 if (ttoken.firstWindowDrawn) {
3376 wtoken.firstWindowDrawn = true;
3377 }
3378 if (!ttoken.hidden) {
3379 wtoken.hidden = false;
3380 wtoken.hiddenRequested = false;
3381 wtoken.willBeHidden = false;
3382 }
3383 if (wtoken.clientHidden != ttoken.clientHidden) {
3384 wtoken.clientHidden = ttoken.clientHidden;
3385 wtoken.sendAppVisibilityToClients();
3386 }
3387 if (ttoken.animation != null) {
3388 wtoken.animation = ttoken.animation;
3389 wtoken.animating = ttoken.animating;
3390 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3391 ttoken.animation = null;
3392 ttoken.animLayerAdjustment = 0;
3393 wtoken.updateLayers();
3394 ttoken.updateLayers();
3395 }
Romain Guy06882f82009-06-10 13:36:04 -07003396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 mLayoutNeeded = true;
3399 performLayoutAndPlaceSurfacesLocked();
3400 Binder.restoreCallingIdentity(origId);
3401 return;
3402 } else if (ttoken.startingData != null) {
3403 // The previous app was getting ready to show a
3404 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003405 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 "Moving pending starting from " + ttoken
3407 + " to " + wtoken);
3408 wtoken.startingData = ttoken.startingData;
3409 ttoken.startingData = null;
3410 ttoken.startingMoved = true;
3411 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3412 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3413 // want to process the message ASAP, before any other queued
3414 // messages.
3415 mH.sendMessageAtFrontOfQueue(m);
3416 return;
3417 }
3418 }
3419 }
3420
3421 // There is no existing starting window, and the caller doesn't
3422 // want us to create one, so that's it!
3423 if (!createIfNeeded) {
3424 return;
3425 }
Romain Guy06882f82009-06-10 13:36:04 -07003426
Dianne Hackborn284ac932009-08-28 10:34:25 -07003427 // If this is a translucent or wallpaper window, then don't
3428 // show a starting window -- the current effect (a full-screen
3429 // opaque starting window that fades away to the real contents
3430 // when it is ready) does not work for this.
3431 if (theme != 0) {
3432 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3433 com.android.internal.R.styleable.Window);
3434 if (ent.array.getBoolean(
3435 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3436 return;
3437 }
3438 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003439 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3440 return;
3441 }
3442 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003443 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3444 return;
3445 }
3446 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 mStartingIconInTransition = true;
3449 wtoken.startingData = new StartingData(
3450 pkg, theme, nonLocalizedLabel,
3451 labelRes, icon);
3452 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3453 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3454 // want to process the message ASAP, before any other queued
3455 // messages.
3456 mH.sendMessageAtFrontOfQueue(m);
3457 }
3458 }
3459
3460 public void setAppWillBeHidden(IBinder token) {
3461 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3462 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003463 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464 }
3465
3466 AppWindowToken wtoken;
3467
3468 synchronized(mWindowMap) {
3469 wtoken = findAppWindowToken(token);
3470 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003471 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 -08003472 return;
3473 }
3474 wtoken.willBeHidden = true;
3475 }
3476 }
Romain Guy06882f82009-06-10 13:36:04 -07003477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003478 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3479 boolean visible, int transit, boolean performLayout) {
3480 boolean delayed = false;
3481
3482 if (wtoken.clientHidden == visible) {
3483 wtoken.clientHidden = !visible;
3484 wtoken.sendAppVisibilityToClients();
3485 }
Romain Guy06882f82009-06-10 13:36:04 -07003486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 wtoken.willBeHidden = false;
3488 if (wtoken.hidden == visible) {
3489 final int N = wtoken.allAppWindows.size();
3490 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003491 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3493 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003495 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003496
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003497 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 if (wtoken.animation == sDummyAnimation) {
3499 wtoken.animation = null;
3500 }
3501 applyAnimationLocked(wtoken, lp, transit, visible);
3502 changed = true;
3503 if (wtoken.animation != null) {
3504 delayed = runningAppAnimation = true;
3505 }
3506 }
Romain Guy06882f82009-06-10 13:36:04 -07003507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 for (int i=0; i<N; i++) {
3509 WindowState win = wtoken.allAppWindows.get(i);
3510 if (win == wtoken.startingWindow) {
3511 continue;
3512 }
3513
3514 if (win.isAnimating()) {
3515 delayed = true;
3516 }
Romain Guy06882f82009-06-10 13:36:04 -07003517
Joe Onorato8a9b2202010-02-26 18:56:32 -08003518 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 //win.dump(" ");
3520 if (visible) {
3521 if (!win.isVisibleNow()) {
3522 if (!runningAppAnimation) {
3523 applyAnimationLocked(win,
3524 WindowManagerPolicy.TRANSIT_ENTER, true);
3525 }
3526 changed = true;
3527 }
3528 } else if (win.isVisibleNow()) {
3529 if (!runningAppAnimation) {
3530 applyAnimationLocked(win,
3531 WindowManagerPolicy.TRANSIT_EXIT, false);
3532 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003533 mInputMonitor.windowIsBecomingInvisibleLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 changed = true;
3535 }
3536 }
3537
3538 wtoken.hidden = wtoken.hiddenRequested = !visible;
3539 if (!visible) {
3540 unsetAppFreezingScreenLocked(wtoken, true, true);
3541 } else {
3542 // If we are being set visible, and the starting window is
3543 // not yet displayed, then make sure it doesn't get displayed.
3544 WindowState swin = wtoken.startingWindow;
3545 if (swin != null && (swin.mDrawPending
3546 || swin.mCommitDrawPending)) {
3547 swin.mPolicyVisibility = false;
3548 swin.mPolicyVisibilityAfterAnim = false;
3549 }
3550 }
Romain Guy06882f82009-06-10 13:36:04 -07003551
Joe Onorato8a9b2202010-02-26 18:56:32 -08003552 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3554 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003555
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003556 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003558 if (performLayout) {
3559 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3560 performLayoutAndPlaceSurfacesLocked();
3561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562 }
3563 }
3564
3565 if (wtoken.animation != null) {
3566 delayed = true;
3567 }
Romain Guy06882f82009-06-10 13:36:04 -07003568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003569 return delayed;
3570 }
3571
3572 public void setAppVisibility(IBinder token, boolean visible) {
3573 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3574 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003575 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 }
3577
3578 AppWindowToken wtoken;
3579
3580 synchronized(mWindowMap) {
3581 wtoken = findAppWindowToken(token);
3582 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003583 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 return;
3585 }
3586
3587 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003588 RuntimeException e = null;
3589 if (!HIDE_STACK_CRAWLS) {
3590 e = new RuntimeException();
3591 e.fillInStackTrace();
3592 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003593 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003594 + "): mNextAppTransition=" + mNextAppTransition
3595 + " hidden=" + wtoken.hidden
3596 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3597 }
Romain Guy06882f82009-06-10 13:36:04 -07003598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 // If we are preparing an app transition, then delay changing
3600 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003601 if (!mDisplayFrozen && mPolicy.isScreenOn()
3602 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 // Already in requested state, don't do anything more.
3604 if (wtoken.hiddenRequested != visible) {
3605 return;
3606 }
3607 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003608
Joe Onorato8a9b2202010-02-26 18:56:32 -08003609 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 TAG, "Setting dummy animation on: " + wtoken);
3611 wtoken.setDummyAnimation();
3612 mOpeningApps.remove(wtoken);
3613 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003614 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 wtoken.inPendingTransaction = true;
3616 if (visible) {
3617 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 wtoken.startingDisplayed = false;
3619 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003620
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003621 // If the token is currently hidden (should be the
3622 // common case), then we need to set up to wait for
3623 // its windows to be ready.
3624 if (wtoken.hidden) {
3625 wtoken.allDrawn = false;
3626 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003627
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003628 if (wtoken.clientHidden) {
3629 // In the case where we are making an app visible
3630 // but holding off for a transition, we still need
3631 // to tell the client to make its windows visible so
3632 // they get drawn. Otherwise, we will wait on
3633 // performing the transition until all windows have
3634 // been drawn, they never will be, and we are sad.
3635 wtoken.clientHidden = false;
3636 wtoken.sendAppVisibilityToClients();
3637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 }
3639 } else {
3640 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003641
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003642 // If the token is currently visible (should be the
3643 // common case), then set up to wait for it to be hidden.
3644 if (!wtoken.hidden) {
3645 wtoken.waitingToHide = true;
3646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003647 }
3648 return;
3649 }
Romain Guy06882f82009-06-10 13:36:04 -07003650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003652 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 wtoken.updateReportedVisibilityLocked();
3654 Binder.restoreCallingIdentity(origId);
3655 }
3656 }
3657
3658 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3659 boolean unfreezeSurfaceNow, boolean force) {
3660 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003661 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 + " force=" + force);
3663 final int N = wtoken.allAppWindows.size();
3664 boolean unfrozeWindows = false;
3665 for (int i=0; i<N; i++) {
3666 WindowState w = wtoken.allAppWindows.get(i);
3667 if (w.mAppFreezing) {
3668 w.mAppFreezing = false;
3669 if (w.mSurface != null && !w.mOrientationChanging) {
3670 w.mOrientationChanging = true;
3671 }
3672 unfrozeWindows = true;
3673 }
3674 }
3675 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003676 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 wtoken.freezingScreen = false;
3678 mAppsFreezingScreen--;
3679 }
3680 if (unfreezeSurfaceNow) {
3681 if (unfrozeWindows) {
3682 mLayoutNeeded = true;
3683 performLayoutAndPlaceSurfacesLocked();
3684 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003685 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 }
3687 }
3688 }
Romain Guy06882f82009-06-10 13:36:04 -07003689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3691 int configChanges) {
3692 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003693 RuntimeException e = null;
3694 if (!HIDE_STACK_CRAWLS) {
3695 e = new RuntimeException();
3696 e.fillInStackTrace();
3697 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003698 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 + ": hidden=" + wtoken.hidden + " freezing="
3700 + wtoken.freezingScreen, e);
3701 }
3702 if (!wtoken.hiddenRequested) {
3703 if (!wtoken.freezingScreen) {
3704 wtoken.freezingScreen = true;
3705 mAppsFreezingScreen++;
3706 if (mAppsFreezingScreen == 1) {
3707 startFreezingDisplayLocked();
3708 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3709 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3710 5000);
3711 }
3712 }
3713 final int N = wtoken.allAppWindows.size();
3714 for (int i=0; i<N; i++) {
3715 WindowState w = wtoken.allAppWindows.get(i);
3716 w.mAppFreezing = true;
3717 }
3718 }
3719 }
Romain Guy06882f82009-06-10 13:36:04 -07003720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 public void startAppFreezingScreen(IBinder token, int configChanges) {
3722 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3723 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003724 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 }
3726
3727 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003728 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003729 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 return;
3731 }
Romain Guy06882f82009-06-10 13:36:04 -07003732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 AppWindowToken wtoken = findAppWindowToken(token);
3734 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003735 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 return;
3737 }
3738 final long origId = Binder.clearCallingIdentity();
3739 startAppFreezingScreenLocked(wtoken, configChanges);
3740 Binder.restoreCallingIdentity(origId);
3741 }
3742 }
Romain Guy06882f82009-06-10 13:36:04 -07003743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 public void stopAppFreezingScreen(IBinder token, boolean force) {
3745 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3746 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003747 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 }
3749
3750 synchronized(mWindowMap) {
3751 AppWindowToken wtoken = findAppWindowToken(token);
3752 if (wtoken == null || wtoken.appToken == null) {
3753 return;
3754 }
3755 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003756 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003757 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3758 unsetAppFreezingScreenLocked(wtoken, true, force);
3759 Binder.restoreCallingIdentity(origId);
3760 }
3761 }
Romain Guy06882f82009-06-10 13:36:04 -07003762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 public void removeAppToken(IBinder token) {
3764 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3765 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003766 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 }
3768
3769 AppWindowToken wtoken = null;
3770 AppWindowToken startingToken = null;
3771 boolean delayed = false;
3772
3773 final long origId = Binder.clearCallingIdentity();
3774 synchronized(mWindowMap) {
3775 WindowToken basewtoken = mTokenMap.remove(token);
3776 mTokenList.remove(basewtoken);
3777 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003778 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003779 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 wtoken.inPendingTransaction = false;
3781 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003782 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 if (mClosingApps.contains(wtoken)) {
3784 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003785 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003787 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 delayed = true;
3789 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003790 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 TAG, "Removing app " + wtoken + " delayed=" + delayed
3792 + " animation=" + wtoken.animation
3793 + " animating=" + wtoken.animating);
3794 if (delayed) {
3795 // set the token aside because it has an active animation to be finished
3796 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003797 } else {
3798 // Make sure there is no animation running on this token,
3799 // so any windows associated with it will be removed as
3800 // soon as their animations are complete
3801 wtoken.animation = null;
3802 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 }
3804 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003805 if (mLastEnterAnimToken == wtoken) {
3806 mLastEnterAnimToken = null;
3807 mLastEnterAnimParams = null;
3808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 wtoken.removed = true;
3810 if (wtoken.startingData != null) {
3811 startingToken = wtoken;
3812 }
3813 unsetAppFreezingScreenLocked(wtoken, true, true);
3814 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003815 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 mFocusedApp = null;
3817 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003818 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 }
3820 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003821 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 }
Romain Guy06882f82009-06-10 13:36:04 -07003823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 if (!delayed && wtoken != null) {
3825 wtoken.updateReportedVisibilityLocked();
3826 }
3827 }
3828 Binder.restoreCallingIdentity(origId);
3829
3830 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003831 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 + startingToken + ": app token removed");
3833 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3834 mH.sendMessage(m);
3835 }
3836 }
3837
3838 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3839 final int NW = token.windows.size();
3840 for (int i=0; i<NW; i++) {
3841 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003842 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 mWindows.remove(win);
3844 int j = win.mChildWindows.size();
3845 while (j > 0) {
3846 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003847 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003848 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003849 "Tmp removing child window " + cwin);
3850 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 }
3852 }
3853 return NW > 0;
3854 }
3855
3856 void dumpAppTokensLocked() {
3857 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003858 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 }
3860 }
Romain Guy06882f82009-06-10 13:36:04 -07003861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 void dumpWindowsLocked() {
3863 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003864 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 }
3866 }
Romain Guy06882f82009-06-10 13:36:04 -07003867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 private int findWindowOffsetLocked(int tokenPos) {
3869 final int NW = mWindows.size();
3870
3871 if (tokenPos >= mAppTokens.size()) {
3872 int i = NW;
3873 while (i > 0) {
3874 i--;
3875 WindowState win = (WindowState)mWindows.get(i);
3876 if (win.getAppToken() != null) {
3877 return i+1;
3878 }
3879 }
3880 }
3881
3882 while (tokenPos > 0) {
3883 // Find the first app token below the new position that has
3884 // a window displayed.
3885 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003886 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003887 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003888 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003889 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003890 "Skipping token -- currently sending to bottom");
3891 tokenPos--;
3892 continue;
3893 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 int i = wtoken.windows.size();
3895 while (i > 0) {
3896 i--;
3897 WindowState win = wtoken.windows.get(i);
3898 int j = win.mChildWindows.size();
3899 while (j > 0) {
3900 j--;
3901 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003902 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903 for (int pos=NW-1; pos>=0; pos--) {
3904 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003905 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003906 "Found child win @" + (pos+1));
3907 return pos+1;
3908 }
3909 }
3910 }
3911 }
3912 for (int pos=NW-1; pos>=0; pos--) {
3913 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003914 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003915 return pos+1;
3916 }
3917 }
3918 }
3919 tokenPos--;
3920 }
3921
3922 return 0;
3923 }
3924
3925 private final int reAddWindowLocked(int index, WindowState win) {
3926 final int NCW = win.mChildWindows.size();
3927 boolean added = false;
3928 for (int j=0; j<NCW; j++) {
3929 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3930 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003931 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003932 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 mWindows.add(index, win);
3934 index++;
3935 added = true;
3936 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003937 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003938 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 mWindows.add(index, cwin);
3940 index++;
3941 }
3942 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003943 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003944 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003945 mWindows.add(index, win);
3946 index++;
3947 }
3948 return index;
3949 }
Romain Guy06882f82009-06-10 13:36:04 -07003950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003951 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3952 final int NW = token.windows.size();
3953 for (int i=0; i<NW; i++) {
3954 index = reAddWindowLocked(index, token.windows.get(i));
3955 }
3956 return index;
3957 }
3958
3959 public void moveAppToken(int index, IBinder token) {
3960 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3961 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003962 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003963 }
3964
3965 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003966 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 if (DEBUG_REORDER) dumpAppTokensLocked();
3968 final AppWindowToken wtoken = findAppWindowToken(token);
3969 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003970 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 + token + " (" + wtoken + ")");
3972 return;
3973 }
3974 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003975 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003979 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 if (DEBUG_REORDER) dumpWindowsLocked();
3981 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003982 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 if (DEBUG_REORDER) dumpWindowsLocked();
3984 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003985 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 if (DEBUG_REORDER) dumpWindowsLocked();
3987 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 mLayoutNeeded = true;
3989 performLayoutAndPlaceSurfacesLocked();
3990 }
3991 Binder.restoreCallingIdentity(origId);
3992 }
3993 }
3994
3995 private void removeAppTokensLocked(List<IBinder> tokens) {
3996 // XXX This should be done more efficiently!
3997 // (take advantage of the fact that both lists should be
3998 // ordered in the same way.)
3999 int N = tokens.size();
4000 for (int i=0; i<N; i++) {
4001 IBinder token = tokens.get(i);
4002 final AppWindowToken wtoken = findAppWindowToken(token);
4003 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004004 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 + token + " (" + wtoken + ")");
4006 i--;
4007 N--;
4008 }
4009 }
4010 }
4011
Dianne Hackborna8f60182009-09-01 19:01:50 -07004012 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4013 boolean updateFocusAndLayout) {
4014 // First remove all of the windows from the list.
4015 tmpRemoveAppWindowsLocked(wtoken);
4016
4017 // Where to start adding?
4018 int pos = findWindowOffsetLocked(tokenPos);
4019
4020 // And now add them back at the correct place.
4021 pos = reAddAppWindowsLocked(pos, wtoken);
4022
4023 if (updateFocusAndLayout) {
4024 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4025 assignLayersLocked();
4026 }
4027 mLayoutNeeded = true;
4028 performLayoutAndPlaceSurfacesLocked();
4029 }
4030 }
4031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004032 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4033 // First remove all of the windows from the list.
4034 final int N = tokens.size();
4035 int i;
4036 for (i=0; i<N; i++) {
4037 WindowToken token = mTokenMap.get(tokens.get(i));
4038 if (token != null) {
4039 tmpRemoveAppWindowsLocked(token);
4040 }
4041 }
4042
4043 // Where to start adding?
4044 int pos = findWindowOffsetLocked(tokenPos);
4045
4046 // And now add them back at the correct place.
4047 for (i=0; i<N; i++) {
4048 WindowToken token = mTokenMap.get(tokens.get(i));
4049 if (token != null) {
4050 pos = reAddAppWindowsLocked(pos, token);
4051 }
4052 }
4053
Dianne Hackborna8f60182009-09-01 19:01:50 -07004054 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4055 assignLayersLocked();
4056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004057 mLayoutNeeded = true;
4058 performLayoutAndPlaceSurfacesLocked();
4059
4060 //dump();
4061 }
4062
4063 public void moveAppTokensToTop(List<IBinder> tokens) {
4064 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4065 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004066 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 }
4068
4069 final long origId = Binder.clearCallingIdentity();
4070 synchronized(mWindowMap) {
4071 removeAppTokensLocked(tokens);
4072 final int N = tokens.size();
4073 for (int i=0; i<N; i++) {
4074 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4075 if (wt != null) {
4076 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004077 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004078 mToTopApps.remove(wt);
4079 mToBottomApps.remove(wt);
4080 mToTopApps.add(wt);
4081 wt.sendingToBottom = false;
4082 wt.sendingToTop = true;
4083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 }
4085 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004086
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004087 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004088 moveAppWindowsLocked(tokens, mAppTokens.size());
4089 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 }
4091 Binder.restoreCallingIdentity(origId);
4092 }
4093
4094 public void moveAppTokensToBottom(List<IBinder> tokens) {
4095 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4096 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004097 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 }
4099
4100 final long origId = Binder.clearCallingIdentity();
4101 synchronized(mWindowMap) {
4102 removeAppTokensLocked(tokens);
4103 final int N = tokens.size();
4104 int pos = 0;
4105 for (int i=0; i<N; i++) {
4106 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4107 if (wt != null) {
4108 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004109 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004110 mToTopApps.remove(wt);
4111 mToBottomApps.remove(wt);
4112 mToBottomApps.add(i, wt);
4113 wt.sendingToTop = false;
4114 wt.sendingToBottom = true;
4115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 pos++;
4117 }
4118 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004119
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004120 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004121 moveAppWindowsLocked(tokens, 0);
4122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 }
4124 Binder.restoreCallingIdentity(origId);
4125 }
4126
4127 // -------------------------------------------------------------
4128 // Misc IWindowSession methods
4129 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004130
Jim Miller284b62e2010-06-08 14:27:42 -07004131 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004132 {
Jim Miller284b62e2010-06-08 14:27:42 -07004133 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4134 // called before DevicePolicyManagerService has started.
4135 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4136 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4137 Context.DEVICE_POLICY_SERVICE);
4138 if (dpm != null) {
4139 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4140 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4141 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4142 }
Jim Millerd6b57052010-06-07 17:52:42 -07004143 }
Jim Miller284b62e2010-06-08 14:27:42 -07004144 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004145 }
4146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004148 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 != PackageManager.PERMISSION_GRANTED) {
4150 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4151 }
Jim Millerd6b57052010-06-07 17:52:42 -07004152
Jim Miller284b62e2010-06-08 14:27:42 -07004153 synchronized (mKeyguardTokenWatcher) {
4154 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004156 }
4157
4158 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004159 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 != PackageManager.PERMISSION_GRANTED) {
4161 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163
Jim Miller284b62e2010-06-08 14:27:42 -07004164 synchronized (mKeyguardTokenWatcher) {
4165 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004166
Jim Miller284b62e2010-06-08 14:27:42 -07004167 if (!mKeyguardTokenWatcher.isAcquired()) {
4168 // If we are the last one to reenable the keyguard wait until
4169 // we have actually finished reenabling until returning.
4170 // It is possible that reenableKeyguard() can be called before
4171 // the previous disableKeyguard() is handled, in which case
4172 // neither mKeyguardTokenWatcher.acquired() or released() would
4173 // be called. In that case mKeyguardDisabled will be false here
4174 // and we have nothing to wait for.
4175 while (mKeyguardDisabled) {
4176 try {
4177 mKeyguardTokenWatcher.wait();
4178 } catch (InterruptedException e) {
4179 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 }
4181 }
4182 }
4183 }
4184 }
4185
4186 /**
4187 * @see android.app.KeyguardManager#exitKeyguardSecurely
4188 */
4189 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004190 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191 != PackageManager.PERMISSION_GRANTED) {
4192 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4193 }
4194 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4195 public void onKeyguardExitResult(boolean success) {
4196 try {
4197 callback.onKeyguardExitResult(success);
4198 } catch (RemoteException e) {
4199 // Client has died, we don't care.
4200 }
4201 }
4202 });
4203 }
4204
4205 public boolean inKeyguardRestrictedInputMode() {
4206 return mPolicy.inKeyguardRestrictedKeyInputMode();
4207 }
Romain Guy06882f82009-06-10 13:36:04 -07004208
Dianne Hackbornffa42482009-09-23 22:20:11 -07004209 public void closeSystemDialogs(String reason) {
4210 synchronized(mWindowMap) {
4211 for (int i=mWindows.size()-1; i>=0; i--) {
4212 WindowState w = (WindowState)mWindows.get(i);
4213 if (w.mSurface != null) {
4214 try {
4215 w.mClient.closeSystemDialogs(reason);
4216 } catch (RemoteException e) {
4217 }
4218 }
4219 }
4220 }
4221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 static float fixScale(float scale) {
4224 if (scale < 0) scale = 0;
4225 else if (scale > 20) scale = 20;
4226 return Math.abs(scale);
4227 }
Romain Guy06882f82009-06-10 13:36:04 -07004228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 public void setAnimationScale(int which, float scale) {
4230 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4231 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004232 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004233 }
4234
4235 if (scale < 0) scale = 0;
4236 else if (scale > 20) scale = 20;
4237 scale = Math.abs(scale);
4238 switch (which) {
4239 case 0: mWindowAnimationScale = fixScale(scale); break;
4240 case 1: mTransitionAnimationScale = fixScale(scale); break;
4241 }
Romain Guy06882f82009-06-10 13:36:04 -07004242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004243 // Persist setting
4244 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4245 }
Romain Guy06882f82009-06-10 13:36:04 -07004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 public void setAnimationScales(float[] scales) {
4248 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4249 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004250 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 }
4252
4253 if (scales != null) {
4254 if (scales.length >= 1) {
4255 mWindowAnimationScale = fixScale(scales[0]);
4256 }
4257 if (scales.length >= 2) {
4258 mTransitionAnimationScale = fixScale(scales[1]);
4259 }
4260 }
Romain Guy06882f82009-06-10 13:36:04 -07004261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 // Persist setting
4263 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4264 }
Romain Guy06882f82009-06-10 13:36:04 -07004265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 public float getAnimationScale(int which) {
4267 switch (which) {
4268 case 0: return mWindowAnimationScale;
4269 case 1: return mTransitionAnimationScale;
4270 }
4271 return 0;
4272 }
Romain Guy06882f82009-06-10 13:36:04 -07004273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004274 public float[] getAnimationScales() {
4275 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4276 }
Romain Guy06882f82009-06-10 13:36:04 -07004277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 public int getSwitchState(int sw) {
4279 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4280 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004281 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004283 return mInputManager.getSwitchState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 }
Romain Guy06882f82009-06-10 13:36:04 -07004285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 public int getSwitchStateForDevice(int devid, int sw) {
4287 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4288 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004289 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004291 return mInputManager.getSwitchState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 }
Romain Guy06882f82009-06-10 13:36:04 -07004293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 public int getScancodeState(int sw) {
4295 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4296 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004297 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004298 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004299 return mInputManager.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 public int getScancodeStateForDevice(int devid, int sw) {
4303 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4304 "getScancodeStateForDevice()")) {
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.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 }
Romain Guy06882f82009-06-10 13:36:04 -07004309
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004310 public int getTrackballScancodeState(int sw) {
4311 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4312 "getTrackballScancodeState()")) {
4313 throw new SecurityException("Requires READ_INPUT_STATE permission");
4314 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004315 return mInputManager.getTrackballScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004316 }
4317
4318 public int getDPadScancodeState(int sw) {
4319 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4320 "getDPadScancodeState()")) {
4321 throw new SecurityException("Requires READ_INPUT_STATE permission");
4322 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004323 return mInputManager.getDPadScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004324 }
4325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 public int getKeycodeState(int sw) {
4327 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4328 "getKeycodeState()")) {
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.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
Romain Guy06882f82009-06-10 13:36:04 -07004333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 public int getKeycodeStateForDevice(int devid, int sw) {
4335 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4336 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004337 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004338 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004339 return mInputManager.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004340 }
Romain Guy06882f82009-06-10 13:36:04 -07004341
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004342 public int getTrackballKeycodeState(int sw) {
4343 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4344 "getTrackballKeycodeState()")) {
4345 throw new SecurityException("Requires READ_INPUT_STATE permission");
4346 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004347 return mInputManager.getTrackballKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004348 }
4349
4350 public int getDPadKeycodeState(int sw) {
4351 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4352 "getDPadKeycodeState()")) {
4353 throw new SecurityException("Requires READ_INPUT_STATE permission");
4354 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004355 return mInputManager.getDPadKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004356 }
4357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004359 return mInputManager.hasKeys(keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 }
Romain Guy06882f82009-06-10 13:36:04 -07004361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 public void enableScreenAfterBoot() {
4363 synchronized(mWindowMap) {
4364 if (mSystemBooted) {
4365 return;
4366 }
4367 mSystemBooted = true;
4368 }
Romain Guy06882f82009-06-10 13:36:04 -07004369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 performEnableScreen();
4371 }
Romain Guy06882f82009-06-10 13:36:04 -07004372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004373 public void enableScreenIfNeededLocked() {
4374 if (mDisplayEnabled) {
4375 return;
4376 }
4377 if (!mSystemBooted) {
4378 return;
4379 }
4380 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4381 }
Romain Guy06882f82009-06-10 13:36:04 -07004382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 public void performEnableScreen() {
4384 synchronized(mWindowMap) {
4385 if (mDisplayEnabled) {
4386 return;
4387 }
4388 if (!mSystemBooted) {
4389 return;
4390 }
Romain Guy06882f82009-06-10 13:36:04 -07004391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004392 // Don't enable the screen until all existing windows
4393 // have been drawn.
4394 final int N = mWindows.size();
4395 for (int i=0; i<N; i++) {
4396 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004397 if (w.isVisibleLw() && !w.mObscured
4398 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004399 return;
4400 }
4401 }
Romain Guy06882f82009-06-10 13:36:04 -07004402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 mDisplayEnabled = true;
4404 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004405 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 StringWriter sw = new StringWriter();
4407 PrintWriter pw = new PrintWriter(sw);
4408 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004409 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 }
4411 try {
4412 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4413 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004414 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 Parcel data = Parcel.obtain();
4416 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4417 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4418 data, null, 0);
4419 data.recycle();
4420 }
4421 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004422 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 }
4424 }
Romain Guy06882f82009-06-10 13:36:04 -07004425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004429 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4430 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004431 }
Romain Guy06882f82009-06-10 13:36:04 -07004432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 public void setInTouchMode(boolean mode) {
4434 synchronized(mWindowMap) {
4435 mInTouchMode = mode;
4436 }
4437 }
4438
Romain Guy06882f82009-06-10 13:36:04 -07004439 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004440 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004442 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004443 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 }
4445
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004446 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 }
Romain Guy06882f82009-06-10 13:36:04 -07004448
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004449 public void setRotationUnchecked(int rotation,
4450 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004451 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 long origId = Binder.clearCallingIdentity();
4455 boolean changed;
4456 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004457 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 }
Romain Guy06882f82009-06-10 13:36:04 -07004459
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004460 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 sendNewConfiguration();
4462 }
Romain Guy06882f82009-06-10 13:36:04 -07004463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 Binder.restoreCallingIdentity(origId);
4465 }
Romain Guy06882f82009-06-10 13:36:04 -07004466
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004467 /**
4468 * Apply a new rotation to the screen, respecting the requests of
4469 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4470 * re-evaluate the desired rotation.
4471 *
4472 * Returns null if the rotation has been changed. In this case YOU
4473 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4474 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004475 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 boolean changed;
4477 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4478 rotation = mRequestedRotation;
4479 } else {
4480 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004481 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004483 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004484 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004486 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004490 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004491 "Rotation changed to " + rotation
4492 + " from " + mRotation
4493 + " (forceApp=" + mForcedAppOrientation
4494 + ", req=" + mRequestedRotation + ")");
4495 mRotation = rotation;
4496 mWindowsFreezingScreen = true;
4497 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4498 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4499 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004500 mWaitingForConfig = true;
4501 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004503 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004504 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004506 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 }
4508 for (int i=mWindows.size()-1; i>=0; i--) {
4509 WindowState w = (WindowState)mWindows.get(i);
4510 if (w.mSurface != null) {
4511 w.mOrientationChanging = true;
4512 }
4513 }
4514 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4515 try {
4516 mRotationWatchers.get(i).onRotationChanged(rotation);
4517 } catch (RemoteException e) {
4518 }
4519 }
4520 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 return changed;
4523 }
Romain Guy06882f82009-06-10 13:36:04 -07004524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 public int getRotation() {
4526 return mRotation;
4527 }
4528
4529 public int watchRotation(IRotationWatcher watcher) {
4530 final IBinder watcherBinder = watcher.asBinder();
4531 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4532 public void binderDied() {
4533 synchronized (mWindowMap) {
4534 for (int i=0; i<mRotationWatchers.size(); i++) {
4535 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004536 IRotationWatcher removed = mRotationWatchers.remove(i);
4537 if (removed != null) {
4538 removed.asBinder().unlinkToDeath(this, 0);
4539 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 i--;
4541 }
4542 }
4543 }
4544 }
4545 };
Romain Guy06882f82009-06-10 13:36:04 -07004546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 synchronized (mWindowMap) {
4548 try {
4549 watcher.asBinder().linkToDeath(dr, 0);
4550 mRotationWatchers.add(watcher);
4551 } catch (RemoteException e) {
4552 // Client died, no cleanup needed.
4553 }
Romain Guy06882f82009-06-10 13:36:04 -07004554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004555 return mRotation;
4556 }
4557 }
4558
4559 /**
4560 * Starts the view server on the specified port.
4561 *
4562 * @param port The port to listener to.
4563 *
4564 * @return True if the server was successfully started, false otherwise.
4565 *
4566 * @see com.android.server.ViewServer
4567 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4568 */
4569 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004570 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 return false;
4572 }
4573
4574 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4575 return false;
4576 }
4577
4578 if (port < 1024) {
4579 return false;
4580 }
4581
4582 if (mViewServer != null) {
4583 if (!mViewServer.isRunning()) {
4584 try {
4585 return mViewServer.start();
4586 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004587 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 }
4589 }
4590 return false;
4591 }
4592
4593 try {
4594 mViewServer = new ViewServer(this, port);
4595 return mViewServer.start();
4596 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004597 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 }
4599 return false;
4600 }
4601
Romain Guy06882f82009-06-10 13:36:04 -07004602 private boolean isSystemSecure() {
4603 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4604 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4605 }
4606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004607 /**
4608 * Stops the view server if it exists.
4609 *
4610 * @return True if the server stopped, false if it wasn't started or
4611 * couldn't be stopped.
4612 *
4613 * @see com.android.server.ViewServer
4614 */
4615 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004616 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004617 return false;
4618 }
4619
4620 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4621 return false;
4622 }
4623
4624 if (mViewServer != null) {
4625 return mViewServer.stop();
4626 }
4627 return false;
4628 }
4629
4630 /**
4631 * Indicates whether the view server is running.
4632 *
4633 * @return True if the server is running, false otherwise.
4634 *
4635 * @see com.android.server.ViewServer
4636 */
4637 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004638 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 return false;
4640 }
4641
4642 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4643 return false;
4644 }
4645
4646 return mViewServer != null && mViewServer.isRunning();
4647 }
4648
4649 /**
4650 * Lists all availble windows in the system. The listing is written in the
4651 * specified Socket's output stream with the following syntax:
4652 * windowHashCodeInHexadecimal windowName
4653 * Each line of the ouput represents a different window.
4654 *
4655 * @param client The remote client to send the listing to.
4656 * @return False if an error occured, true otherwise.
4657 */
4658 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004659 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 return false;
4661 }
4662
4663 boolean result = true;
4664
4665 Object[] windows;
4666 synchronized (mWindowMap) {
4667 windows = new Object[mWindows.size()];
4668 //noinspection unchecked
4669 windows = mWindows.toArray(windows);
4670 }
4671
4672 BufferedWriter out = null;
4673
4674 // Any uncaught exception will crash the system process
4675 try {
4676 OutputStream clientStream = client.getOutputStream();
4677 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4678
4679 final int count = windows.length;
4680 for (int i = 0; i < count; i++) {
4681 final WindowState w = (WindowState) windows[i];
4682 out.write(Integer.toHexString(System.identityHashCode(w)));
4683 out.write(' ');
4684 out.append(w.mAttrs.getTitle());
4685 out.write('\n');
4686 }
4687
4688 out.write("DONE.\n");
4689 out.flush();
4690 } catch (Exception e) {
4691 result = false;
4692 } finally {
4693 if (out != null) {
4694 try {
4695 out.close();
4696 } catch (IOException e) {
4697 result = false;
4698 }
4699 }
4700 }
4701
4702 return result;
4703 }
4704
4705 /**
4706 * Sends a command to a target window. The result of the command, if any, will be
4707 * written in the output stream of the specified socket.
4708 *
4709 * The parameters must follow this syntax:
4710 * windowHashcode extra
4711 *
4712 * Where XX is the length in characeters of the windowTitle.
4713 *
4714 * The first parameter is the target window. The window with the specified hashcode
4715 * will be the target. If no target can be found, nothing happens. The extra parameters
4716 * will be delivered to the target window and as parameters to the command itself.
4717 *
4718 * @param client The remote client to sent the result, if any, to.
4719 * @param command The command to execute.
4720 * @param parameters The command parameters.
4721 *
4722 * @return True if the command was successfully delivered, false otherwise. This does
4723 * not indicate whether the command itself was successful.
4724 */
4725 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004726 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004727 return false;
4728 }
4729
4730 boolean success = true;
4731 Parcel data = null;
4732 Parcel reply = null;
4733
4734 // Any uncaught exception will crash the system process
4735 try {
4736 // Find the hashcode of the window
4737 int index = parameters.indexOf(' ');
4738 if (index == -1) {
4739 index = parameters.length();
4740 }
4741 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004742 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004743
4744 // Extract the command's parameter after the window description
4745 if (index < parameters.length()) {
4746 parameters = parameters.substring(index + 1);
4747 } else {
4748 parameters = "";
4749 }
4750
4751 final WindowManagerService.WindowState window = findWindow(hashCode);
4752 if (window == null) {
4753 return false;
4754 }
4755
4756 data = Parcel.obtain();
4757 data.writeInterfaceToken("android.view.IWindow");
4758 data.writeString(command);
4759 data.writeString(parameters);
4760 data.writeInt(1);
4761 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4762
4763 reply = Parcel.obtain();
4764
4765 final IBinder binder = window.mClient.asBinder();
4766 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4767 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4768
4769 reply.readException();
4770
4771 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004772 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004773 success = false;
4774 } finally {
4775 if (data != null) {
4776 data.recycle();
4777 }
4778 if (reply != null) {
4779 reply.recycle();
4780 }
4781 }
4782
4783 return success;
4784 }
4785
4786 private WindowState findWindow(int hashCode) {
4787 if (hashCode == -1) {
4788 return getFocusedWindow();
4789 }
4790
4791 synchronized (mWindowMap) {
4792 final ArrayList windows = mWindows;
4793 final int count = windows.size();
4794
4795 for (int i = 0; i < count; i++) {
4796 WindowState w = (WindowState) windows.get(i);
4797 if (System.identityHashCode(w) == hashCode) {
4798 return w;
4799 }
4800 }
4801 }
4802
4803 return null;
4804 }
4805
4806 /*
4807 * Instruct the Activity Manager to fetch the current configuration and broadcast
4808 * that to config-changed listeners if appropriate.
4809 */
4810 void sendNewConfiguration() {
4811 try {
4812 mActivityManager.updateConfiguration(null);
4813 } catch (RemoteException e) {
4814 }
4815 }
Romain Guy06882f82009-06-10 13:36:04 -07004816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004817 public Configuration computeNewConfiguration() {
4818 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004819 return computeNewConfigurationLocked();
4820 }
4821 }
Romain Guy06882f82009-06-10 13:36:04 -07004822
Dianne Hackbornc485a602009-03-24 22:39:49 -07004823 Configuration computeNewConfigurationLocked() {
4824 Configuration config = new Configuration();
4825 if (!computeNewConfigurationLocked(config)) {
4826 return null;
4827 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004828 return config;
4829 }
Romain Guy06882f82009-06-10 13:36:04 -07004830
Dianne Hackbornc485a602009-03-24 22:39:49 -07004831 boolean computeNewConfigurationLocked(Configuration config) {
4832 if (mDisplay == null) {
4833 return false;
4834 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004835
4836 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004837
4838 // Use the effective "visual" dimensions based on current rotation
4839 final boolean rotated = (mRotation == Surface.ROTATION_90
4840 || mRotation == Surface.ROTATION_270);
4841 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4842 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4843
Dianne Hackbornc485a602009-03-24 22:39:49 -07004844 int orientation = Configuration.ORIENTATION_SQUARE;
4845 if (dw < dh) {
4846 orientation = Configuration.ORIENTATION_PORTRAIT;
4847 } else if (dw > dh) {
4848 orientation = Configuration.ORIENTATION_LANDSCAPE;
4849 }
4850 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004851
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004852 DisplayMetrics dm = new DisplayMetrics();
4853 mDisplay.getMetrics(dm);
4854 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4855
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004856 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004857 // Note we only do this once because at this point we don't
4858 // expect the screen to change in this way at runtime, and want
4859 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004860 int longSize = dw;
4861 int shortSize = dh;
4862 if (longSize < shortSize) {
4863 int tmp = longSize;
4864 longSize = shortSize;
4865 shortSize = tmp;
4866 }
4867 longSize = (int)(longSize/dm.density);
4868 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004869
Dianne Hackborn723738c2009-06-25 19:48:04 -07004870 // These semi-magic numbers define our compatibility modes for
4871 // applications with different screens. Don't change unless you
4872 // make sure to test lots and lots of apps!
4873 if (longSize < 470) {
4874 // This is shorter than an HVGA normal density screen (which
4875 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004876 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4877 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004878 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004879 // What size is this screen screen?
4880 if (longSize >= 800 && shortSize >= 600) {
4881 // SVGA or larger screens at medium density are the point
4882 // at which we consider it to be an extra large screen.
4883 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4884 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004885 // VGA or larger screens at medium density are the point
4886 // at which we consider it to be a large screen.
4887 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4888 } else {
4889 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004890
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004891 // If this screen is wider than normal HVGA, or taller
4892 // than FWVGA, then for old apps we want to run in size
4893 // compatibility mode.
4894 if (shortSize > 321 || longSize > 570) {
4895 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4896 }
4897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004898
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004899 // Is this a long screen?
4900 if (((longSize*3)/5) >= (shortSize-1)) {
4901 // Anything wider than WVGA (5:3) is considering to be long.
4902 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4903 } else {
4904 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4905 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004906 }
4907 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004908 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004909
Dianne Hackbornc485a602009-03-24 22:39:49 -07004910 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4911 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4912 mPolicy.adjustConfigurationLw(config);
4913 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004914 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 // -------------------------------------------------------------
4917 // Input Events and Focus Management
4918 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07004919
Jeff Brown349703e2010-06-22 01:27:15 -07004920 InputMonitor mInputMonitor = new InputMonitor();
4921
4922 /* Tracks the progress of input dispatch and ensures that input dispatch state
4923 * is kept in sync with changes in window focus, visibility, registration, and
4924 * other relevant Window Manager state transitions. */
4925 final class InputMonitor {
4926 // Current window with input focus for keys and other non-touch events. May be null.
4927 private WindowState mInputFocus;
4928
4929 // When true, prevents input dispatch from proceeding until set to false again.
4930 private boolean mInputDispatchFrozen;
4931
4932 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
4933 private boolean mInputDispatchEnabled = true;
4934
4935 // Temporary list of windows information to provide to the input dispatcher.
4936 private InputWindowList mTempInputWindows = new InputWindowList();
4937
4938 // Temporary input application object to provide to the input dispatcher.
4939 private InputApplication mTempInputApplication = new InputApplication();
4940
4941 /* Notifies the window manager about a broken input channel.
4942 *
4943 * Called by the InputManager.
4944 */
4945 public void notifyInputChannelBroken(InputChannel inputChannel) {
4946 synchronized (mWindowMap) {
4947 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
4948 if (windowState == null) {
4949 return; // irrelevant
4950 }
4951
4952 Slog.i(TAG, "WINDOW DIED " + windowState);
4953 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07004954 }
4955 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07004956
Jeff Brown349703e2010-06-22 01:27:15 -07004957 /* Notifies the window manager about an input channel that is not responding.
4958 * The method can either cause dispatching to be aborted by returning -2 or
4959 * return a new timeout in nanoseconds.
4960 *
4961 * Called by the InputManager.
4962 */
4963 public long notifyInputChannelANR(InputChannel inputChannel) {
4964 AppWindowToken token;
4965 synchronized (mWindowMap) {
4966 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
4967 if (windowState == null) {
4968 return -2; // irrelevant, abort dispatching (-2)
4969 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004970
Jeff Brown349703e2010-06-22 01:27:15 -07004971 Slog.i(TAG, "Input event dispatching timed out sending to "
4972 + windowState.mAttrs.getTitle());
4973 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07004974 }
4975
Jeff Brown349703e2010-06-22 01:27:15 -07004976 return notifyANRInternal(token);
4977 }
4978
4979 /* Notifies the window manager about an input channel spontaneously recovering from ANR
4980 * by successfully delivering the event that originally timed out.
4981 *
4982 * Called by the InputManager.
4983 */
4984 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
4985 // Nothing to do just now.
4986 // Just wait for the user to dismiss the ANR dialog.
4987 }
4988
4989 /* Notifies the window manager about an application that is not responding
4990 * in general rather than with respect to a particular input channel.
4991 * The method can either cause dispatching to be aborted by returning -2 or
4992 * return a new timeout in nanoseconds.
4993 *
4994 * Called by the InputManager.
4995 */
4996 public long notifyANR(Object token) {
4997 AppWindowToken appWindowToken = (AppWindowToken) token;
4998
4999 Slog.i(TAG, "Input event dispatching timed out sending to application "
5000 + appWindowToken.stringName);
5001 return notifyANRInternal(appWindowToken);
5002 }
5003
5004 private long notifyANRInternal(AppWindowToken token) {
5005 if (token != null && token.appToken != null) {
5006 try {
5007 // Notify the activity manager about the timeout and let it decide whether
5008 // to abort dispatching or keep waiting.
5009 boolean abort = token.appToken.keyDispatchingTimedOut();
5010 if (! abort) {
5011 // The activity manager declined to abort dispatching.
5012 // Wait a bit longer and timeout again later.
5013 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005014 }
Jeff Brown349703e2010-06-22 01:27:15 -07005015 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005016 }
5017 }
Jeff Brown349703e2010-06-22 01:27:15 -07005018 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005019 }
5020
Jeff Brown349703e2010-06-22 01:27:15 -07005021 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5022 synchronized (mWindowMap) {
5023 return getWindowStateForInputChannelLocked(inputChannel);
5024 }
5025 }
5026
5027 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5028 int windowCount = mWindows.size();
5029 for (int i = 0; i < windowCount; i++) {
5030 WindowState windowState = (WindowState) mWindows.get(i);
5031 if (windowState.mInputChannel == inputChannel) {
5032 return windowState;
5033 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005034 }
5035
Jeff Brown349703e2010-06-22 01:27:15 -07005036 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005037 }
5038
Jeff Brown349703e2010-06-22 01:27:15 -07005039 /* Updates the cached window information provided to the input dispatcher. */
5040 public void updateInputWindowsLw() {
5041 // Populate the input window list with information about all of the windows that
5042 // could potentially receive input.
5043 // As an optimization, we could try to prune the list of windows but this turns
5044 // out to be difficult because only the native code knows for sure which window
5045 // currently has touch focus.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005046 final ArrayList windows = mWindows;
5047 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005048 for (int i = N - 1; i >= 0; i--) {
5049 final WindowState child = (WindowState) windows.get(i);
5050 if (child.mInputChannel == null) {
5051 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005052 continue;
5053 }
5054
Jeff Brown349703e2010-06-22 01:27:15 -07005055 final int flags = child.mAttrs.flags;
5056 final int type = child.mAttrs.type;
5057
5058 final boolean hasFocus = (child == mInputFocus);
5059 final boolean isVisible = child.isVisibleLw();
5060 final boolean hasWallpaper = (child == mWallpaperTarget)
5061 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5062
5063 // Add a window to our list of input windows.
5064 final InputWindow inputWindow = mTempInputWindows.add();
5065 inputWindow.inputChannel = child.mInputChannel;
5066 inputWindow.layoutParamsFlags = flags;
5067 inputWindow.layoutParamsType = type;
5068 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5069 inputWindow.visible = isVisible;
5070 inputWindow.hasFocus = hasFocus;
5071 inputWindow.hasWallpaper = hasWallpaper;
5072 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5073 inputWindow.ownerPid = child.mSession.mPid;
5074 inputWindow.ownerUid = child.mSession.mUid;
5075
5076 final Rect frame = child.mFrame;
5077 inputWindow.frameLeft = frame.left;
5078 inputWindow.frameTop = frame.top;
5079
5080 switch (child.mTouchableInsets) {
5081 default:
5082 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5083 inputWindow.touchableAreaLeft = frame.left;
5084 inputWindow.touchableAreaTop = frame.top;
5085 inputWindow.touchableAreaRight = frame.right;
5086 inputWindow.touchableAreaBottom = frame.bottom;
5087 break;
5088
5089 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5090 Rect inset = child.mGivenContentInsets;
5091 inputWindow.touchableAreaLeft = frame.left + inset.left;
5092 inputWindow.touchableAreaTop = frame.top + inset.top;
5093 inputWindow.touchableAreaRight = frame.right - inset.right;
5094 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5095 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005096 }
Jeff Brown349703e2010-06-22 01:27:15 -07005097
5098 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5099 Rect inset = child.mGivenVisibleInsets;
5100 inputWindow.touchableAreaLeft = frame.left + inset.left;
5101 inputWindow.touchableAreaTop = frame.top + inset.top;
5102 inputWindow.touchableAreaRight = frame.right - inset.right;
5103 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005104 break;
5105 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005106 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005107 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005108
Jeff Brown349703e2010-06-22 01:27:15 -07005109 // Send windows to native code.
5110 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005111
Jeff Brown349703e2010-06-22 01:27:15 -07005112 // Clear the list in preparation for the next round.
5113 // Also avoids keeping InputChannel objects referenced unnecessarily.
5114 mTempInputWindows.clear();
5115 }
5116
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005117 /* Provides feedback for a virtual key down. */
5118 public void virtualKeyDownFeedback() {
5119 synchronized (mWindowMap) {
5120 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5121 }
5122 }
5123
Jeff Brown349703e2010-06-22 01:27:15 -07005124 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5125 * This essentially starts a .5 second timeout for the application to process
5126 * subsequent input events while waiting for the app switch to occur. If it takes longer
5127 * than this, the pending events will be dropped.
5128 */
5129 public void notifyAppSwitchComing() {
5130 // TODO Not implemented yet. Should go in the native side.
5131 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005132
5133 /* Notifies that the lid switch changed state. */
5134 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5135 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5136 }
5137
Jeff Brown349703e2010-06-22 01:27:15 -07005138 /* Provides an opportunity for the window manager policy to intercept early key
5139 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005140 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5141 int policyFlags, boolean isScreenOn) {
5142 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5143 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005144 }
5145
5146 /* Provides an opportunity for the window manager policy to process a key before
5147 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005148 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5149 int action, int flags, int keyCode, int metaState, int repeatCount,
5150 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005151 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005152 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5153 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005154 }
5155
5156 /* Called when the current input focus changes.
5157 * Layer assignment is assumed to be complete by the time this is called.
5158 */
5159 public void setInputFocusLw(WindowState newWindow) {
5160 if (DEBUG_INPUT) {
5161 Slog.d(TAG, "Input focus has changed to " + newWindow);
5162 }
5163
5164 if (newWindow != mInputFocus) {
5165 if (newWindow != null && newWindow.canReceiveKeys()) {
5166 // If the new input focus is an error window or appears above the current
5167 // input focus, preempt any pending synchronous dispatch so that we can
5168 // start delivering events to the new input focus as soon as possible.
5169 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5170 if (DEBUG_INPUT) {
5171 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac02010-04-22 18:58:52 -07005172 }
Jeff Brown349703e2010-06-22 01:27:15 -07005173 preemptInputDispatchLw();
5174 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5175 if (DEBUG_INPUT) {
5176 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5177 + "old win layer=" + mInputFocus.mLayer
5178 + ", new win layer=" + newWindow.mLayer);
5179 }
5180 preemptInputDispatchLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005181 }
Jeff Brown349703e2010-06-22 01:27:15 -07005182
5183 // Displaying a window implicitly causes dispatching to be unpaused.
5184 // This is to protect against bugs if someone pauses dispatching but
5185 // forgets to resume.
5186 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005187 }
Jeff Brown349703e2010-06-22 01:27:15 -07005188
5189 mInputFocus = newWindow;
5190 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005191 }
5192 }
5193
Jeff Brown349703e2010-06-22 01:27:15 -07005194 public void windowIsBecomingInvisibleLw(WindowState window) {
5195 // The window is becoming invisible. Preempt input dispatch in progress
5196 // so that the next window below can receive focus.
5197 if (window == mInputFocus) {
5198 mInputFocus = null;
5199 preemptInputDispatchLw();
5200 }
5201
5202 updateInputWindowsLw();
5203 }
5204
5205 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5206 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5207 * can begin.
5208 */
5209 private void preemptInputDispatchLw() {
5210 mInputManager.preemptInputDispatch();
5211 }
5212
5213 public void setFocusedAppLw(AppWindowToken newApp) {
5214 // Focused app has changed.
5215 if (newApp == null) {
5216 mInputManager.setFocusedApplication(null);
5217 } else {
5218 mTempInputApplication.name = newApp.toString();
5219 mTempInputApplication.dispatchingTimeoutNanos =
5220 newApp.inputDispatchingTimeoutNanos;
5221 mTempInputApplication.token = newApp;
5222
5223 mInputManager.setFocusedApplication(mTempInputApplication);
5224 }
5225 }
5226
5227 public void windowIsBeingRemovedLw(WindowState window) {
5228 // Window is being removed.
5229 updateInputWindowsLw();
5230 }
5231
5232 public void pauseDispatchingLw(WindowToken window) {
5233 if (! window.paused) {
5234 if (DEBUG_INPUT) {
5235 Slog.v(TAG, "Pausing WindowToken " + window);
5236 }
5237
5238 window.paused = true;
5239 updateInputWindowsLw();
5240 }
5241 }
5242
5243 public void resumeDispatchingLw(WindowToken window) {
5244 if (window.paused) {
5245 if (DEBUG_INPUT) {
5246 Slog.v(TAG, "Resuming WindowToken " + window);
5247 }
5248
5249 window.paused = false;
5250 updateInputWindowsLw();
5251 }
5252 }
5253
5254 public void freezeInputDispatchingLw() {
5255 if (! mInputDispatchFrozen) {
5256 if (DEBUG_INPUT) {
5257 Slog.v(TAG, "Freezing input dispatching");
5258 }
5259
5260 mInputDispatchFrozen = true;
5261 updateInputDispatchModeLw();
5262 }
5263 }
5264
5265 public void thawInputDispatchingLw() {
5266 if (mInputDispatchFrozen) {
5267 if (DEBUG_INPUT) {
5268 Slog.v(TAG, "Thawing input dispatching");
5269 }
5270
5271 mInputDispatchFrozen = false;
5272 updateInputDispatchModeLw();
5273 }
5274 }
5275
5276 public void setEventDispatchingLw(boolean enabled) {
5277 if (mInputDispatchEnabled != enabled) {
5278 if (DEBUG_INPUT) {
5279 Slog.v(TAG, "Setting event dispatching to " + enabled);
5280 }
5281
5282 mInputDispatchEnabled = enabled;
5283 updateInputDispatchModeLw();
5284 }
5285 }
5286
5287 private void updateInputDispatchModeLw() {
5288 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5289 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005290 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005292 public void pauseKeyDispatching(IBinder _token) {
5293 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5294 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005295 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005296 }
5297
5298 synchronized (mWindowMap) {
5299 WindowToken token = mTokenMap.get(_token);
5300 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005301 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005302 }
5303 }
5304 }
5305
5306 public void resumeKeyDispatching(IBinder _token) {
5307 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5308 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005309 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005310 }
5311
5312 synchronized (mWindowMap) {
5313 WindowToken token = mTokenMap.get(_token);
5314 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005315 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005316 }
5317 }
5318 }
5319
5320 public void setEventDispatching(boolean enabled) {
5321 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5322 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005323 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005324 }
5325
5326 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005327 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005328 }
5329 }
Romain Guy06882f82009-06-10 13:36:04 -07005330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005331 /**
5332 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005333 *
5334 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005335 * {@link SystemClock#uptimeMillis()} as the timebase.)
5336 * @param sync If true, wait for the event to be completed before returning to the caller.
5337 * @return Returns true if event was dispatched, false if it was dropped for any reason
5338 */
5339 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5340 long downTime = ev.getDownTime();
5341 long eventTime = ev.getEventTime();
5342
5343 int action = ev.getAction();
5344 int code = ev.getKeyCode();
5345 int repeatCount = ev.getRepeatCount();
5346 int metaState = ev.getMetaState();
5347 int deviceId = ev.getDeviceId();
5348 int scancode = ev.getScanCode();
5349
5350 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5351 if (downTime == 0) downTime = eventTime;
5352
5353 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005354 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005355
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005356 final int pid = Binder.getCallingPid();
5357 final int uid = Binder.getCallingUid();
5358 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005359
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005360 final int result = mInputManager.injectKeyEvent(newEvent,
5361 InputQueue.INPUT_EVENT_NATURE_KEY, pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005362
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005363 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005364 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005365 }
5366
5367 /**
5368 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005369 *
5370 * @param ev A motion event describing the pointer (touch) action. (As noted in
5371 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005372 * {@link SystemClock#uptimeMillis()} as the timebase.)
5373 * @param sync If true, wait for the event to be completed before returning to the caller.
5374 * @return Returns true if event was dispatched, false if it was dropped for any reason
5375 */
5376 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005377 final int pid = Binder.getCallingPid();
5378 final int uid = Binder.getCallingUid();
5379 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005380
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005381 final int result = mInputManager.injectMotionEvent(ev,
5382 InputQueue.INPUT_EVENT_NATURE_TOUCH, pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005383
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005384 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005385 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005386 }
Romain Guy06882f82009-06-10 13:36:04 -07005387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005388 /**
5389 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005390 *
5391 * @param ev A motion event describing the trackball action. (As noted in
5392 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 * {@link SystemClock#uptimeMillis()} as the timebase.)
5394 * @param sync If true, wait for the event to be completed before returning to the caller.
5395 * @return Returns true if event was dispatched, false if it was dropped for any reason
5396 */
5397 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005398 final int pid = Binder.getCallingPid();
5399 final int uid = Binder.getCallingUid();
5400 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005401
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005402 final int result = mInputManager.injectMotionEvent(ev,
5403 InputQueue.INPUT_EVENT_NATURE_TRACKBALL, pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005404
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005405 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005406 return reportInjectionResult(result);
5407 }
5408
5409 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005410 switch (result) {
5411 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5412 Slog.w(TAG, "Input event injection permission denied.");
5413 throw new SecurityException(
5414 "Injecting to another application requires INJECT_EVENTS permission");
5415 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
5416 Slog.v(TAG, "Input event injection succeeded.");
5417 return true;
5418 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5419 Slog.w(TAG, "Input event injection timed out.");
5420 return false;
5421 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5422 default:
5423 Slog.w(TAG, "Input event injection failed.");
5424 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005425 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005426 }
Romain Guy06882f82009-06-10 13:36:04 -07005427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005428 private WindowState getFocusedWindow() {
5429 synchronized (mWindowMap) {
5430 return getFocusedWindowLocked();
5431 }
5432 }
5433
5434 private WindowState getFocusedWindowLocked() {
5435 return mCurrentFocus;
5436 }
Romain Guy06882f82009-06-10 13:36:04 -07005437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005438 public boolean detectSafeMode() {
5439 mSafeMode = mPolicy.detectSafeMode();
5440 return mSafeMode;
5441 }
Romain Guy06882f82009-06-10 13:36:04 -07005442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005443 public void systemReady() {
5444 mPolicy.systemReady();
5445 }
Romain Guy06882f82009-06-10 13:36:04 -07005446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005447 // -------------------------------------------------------------
5448 // Client Session State
5449 // -------------------------------------------------------------
5450
5451 private final class Session extends IWindowSession.Stub
5452 implements IBinder.DeathRecipient {
5453 final IInputMethodClient mClient;
5454 final IInputContext mInputContext;
5455 final int mUid;
5456 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005457 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005458 SurfaceSession mSurfaceSession;
5459 int mNumWindow = 0;
5460 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005462 public Session(IInputMethodClient client, IInputContext inputContext) {
5463 mClient = client;
5464 mInputContext = inputContext;
5465 mUid = Binder.getCallingUid();
5466 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005467 StringBuilder sb = new StringBuilder();
5468 sb.append("Session{");
5469 sb.append(Integer.toHexString(System.identityHashCode(this)));
5470 sb.append(" uid ");
5471 sb.append(mUid);
5472 sb.append("}");
5473 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005475 synchronized (mWindowMap) {
5476 if (mInputMethodManager == null && mHaveInputMethods) {
5477 IBinder b = ServiceManager.getService(
5478 Context.INPUT_METHOD_SERVICE);
5479 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5480 }
5481 }
5482 long ident = Binder.clearCallingIdentity();
5483 try {
5484 // Note: it is safe to call in to the input method manager
5485 // here because we are not holding our lock.
5486 if (mInputMethodManager != null) {
5487 mInputMethodManager.addClient(client, inputContext,
5488 mUid, mPid);
5489 } else {
5490 client.setUsingInputMethod(false);
5491 }
5492 client.asBinder().linkToDeath(this, 0);
5493 } catch (RemoteException e) {
5494 // The caller has died, so we can just forget about this.
5495 try {
5496 if (mInputMethodManager != null) {
5497 mInputMethodManager.removeClient(client);
5498 }
5499 } catch (RemoteException ee) {
5500 }
5501 } finally {
5502 Binder.restoreCallingIdentity(ident);
5503 }
5504 }
Romain Guy06882f82009-06-10 13:36:04 -07005505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005506 @Override
5507 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5508 throws RemoteException {
5509 try {
5510 return super.onTransact(code, data, reply, flags);
5511 } catch (RuntimeException e) {
5512 // Log all 'real' exceptions thrown to the caller
5513 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005514 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005515 }
5516 throw e;
5517 }
5518 }
5519
5520 public void binderDied() {
5521 // Note: it is safe to call in to the input method manager
5522 // here because we are not holding our lock.
5523 try {
5524 if (mInputMethodManager != null) {
5525 mInputMethodManager.removeClient(mClient);
5526 }
5527 } catch (RemoteException e) {
5528 }
5529 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005530 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005531 mClientDead = true;
5532 killSessionLocked();
5533 }
5534 }
5535
5536 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07005537 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5538 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5539 outInputChannel);
5540 }
5541
5542 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005543 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07005544 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005545 }
Romain Guy06882f82009-06-10 13:36:04 -07005546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005547 public void remove(IWindow window) {
5548 removeWindow(this, window);
5549 }
Romain Guy06882f82009-06-10 13:36:04 -07005550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005551 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5552 int requestedWidth, int requestedHeight, int viewFlags,
5553 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005554 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005555 return relayoutWindow(this, window, attrs,
5556 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005557 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005558 }
Romain Guy06882f82009-06-10 13:36:04 -07005559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005560 public void setTransparentRegion(IWindow window, Region region) {
5561 setTransparentRegionWindow(this, window, region);
5562 }
Romain Guy06882f82009-06-10 13:36:04 -07005563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005564 public void setInsets(IWindow window, int touchableInsets,
5565 Rect contentInsets, Rect visibleInsets) {
5566 setInsetsWindow(this, window, touchableInsets, contentInsets,
5567 visibleInsets);
5568 }
Romain Guy06882f82009-06-10 13:36:04 -07005569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005570 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5571 getWindowDisplayFrame(this, window, outDisplayFrame);
5572 }
Romain Guy06882f82009-06-10 13:36:04 -07005573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005574 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005575 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005576 TAG, "IWindow finishDrawing called for " + window);
5577 finishDrawingWindow(this, window);
5578 }
5579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005580 public void setInTouchMode(boolean mode) {
5581 synchronized(mWindowMap) {
5582 mInTouchMode = mode;
5583 }
5584 }
5585
5586 public boolean getInTouchMode() {
5587 synchronized(mWindowMap) {
5588 return mInTouchMode;
5589 }
5590 }
5591
5592 public boolean performHapticFeedback(IWindow window, int effectId,
5593 boolean always) {
5594 synchronized(mWindowMap) {
5595 long ident = Binder.clearCallingIdentity();
5596 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005597 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005598 windowForClientLocked(this, window, true),
5599 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005600 } finally {
5601 Binder.restoreCallingIdentity(ident);
5602 }
5603 }
5604 }
Romain Guy06882f82009-06-10 13:36:04 -07005605
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005606 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005607 synchronized(mWindowMap) {
5608 long ident = Binder.clearCallingIdentity();
5609 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005610 setWindowWallpaperPositionLocked(
5611 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005612 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005613 } finally {
5614 Binder.restoreCallingIdentity(ident);
5615 }
5616 }
5617 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005618
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005619 public void wallpaperOffsetsComplete(IBinder window) {
5620 WindowManagerService.this.wallpaperOffsetsComplete(window);
5621 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005622
Dianne Hackborn75804932009-10-20 20:15:20 -07005623 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5624 int z, Bundle extras, boolean sync) {
5625 synchronized(mWindowMap) {
5626 long ident = Binder.clearCallingIdentity();
5627 try {
5628 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005629 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005630 action, x, y, z, extras, sync);
5631 } finally {
5632 Binder.restoreCallingIdentity(ident);
5633 }
5634 }
5635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005636
Dianne Hackborn75804932009-10-20 20:15:20 -07005637 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5638 WindowManagerService.this.wallpaperCommandComplete(window, result);
5639 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005641 void windowAddedLocked() {
5642 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005643 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005644 TAG, "First window added to " + this + ", creating SurfaceSession");
5645 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005646 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005647 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005648 mSessions.add(this);
5649 }
5650 mNumWindow++;
5651 }
5652
5653 void windowRemovedLocked() {
5654 mNumWindow--;
5655 killSessionLocked();
5656 }
Romain Guy06882f82009-06-10 13:36:04 -07005657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005658 void killSessionLocked() {
5659 if (mNumWindow <= 0 && mClientDead) {
5660 mSessions.remove(this);
5661 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005662 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005663 TAG, "Last window removed from " + this
5664 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005665 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005666 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005667 try {
5668 mSurfaceSession.kill();
5669 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005670 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005671 + mSurfaceSession + " in session " + this
5672 + ": " + e.toString());
5673 }
5674 mSurfaceSession = null;
5675 }
5676 }
5677 }
Romain Guy06882f82009-06-10 13:36:04 -07005678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005679 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005680 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5681 pw.print(" mClientDead="); pw.print(mClientDead);
5682 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005683 }
5684
5685 @Override
5686 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005687 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005688 }
5689 }
5690
5691 // -------------------------------------------------------------
5692 // Client Window State
5693 // -------------------------------------------------------------
5694
5695 private final class WindowState implements WindowManagerPolicy.WindowState {
5696 final Session mSession;
5697 final IWindow mClient;
5698 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005699 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005700 AppWindowToken mAppToken;
5701 AppWindowToken mTargetAppToken;
5702 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5703 final DeathRecipient mDeathRecipient;
5704 final WindowState mAttachedWindow;
5705 final ArrayList mChildWindows = new ArrayList();
5706 final int mBaseLayer;
5707 final int mSubLayer;
5708 final boolean mLayoutAttached;
5709 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005710 final boolean mIsWallpaper;
5711 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005712 int mViewVisibility;
5713 boolean mPolicyVisibility = true;
5714 boolean mPolicyVisibilityAfterAnim = true;
5715 boolean mAppFreezing;
5716 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005717 boolean mReportDestroySurface;
5718 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005719 boolean mAttachedHidden; // is our parent window hidden?
5720 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005721 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005722 int mRequestedWidth;
5723 int mRequestedHeight;
5724 int mLastRequestedWidth;
5725 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005726 int mLayer;
5727 int mAnimLayer;
5728 int mLastLayer;
5729 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005730 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005731 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005732
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005733 int mLayoutSeq = -1;
5734
5735 Configuration mConfiguration = null;
5736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005737 // Actual frame shown on-screen (may be modified by animation)
5738 final Rect mShownFrame = new Rect();
5739 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005741 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005742 * Set when we have changed the size of the surface, to know that
5743 * we must tell them application to resize (and thus redraw itself).
5744 */
5745 boolean mSurfaceResized;
5746
5747 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005748 * Insets that determine the actually visible area
5749 */
5750 final Rect mVisibleInsets = new Rect();
5751 final Rect mLastVisibleInsets = new Rect();
5752 boolean mVisibleInsetsChanged;
5753
5754 /**
5755 * Insets that are covered by system windows
5756 */
5757 final Rect mContentInsets = new Rect();
5758 final Rect mLastContentInsets = new Rect();
5759 boolean mContentInsetsChanged;
5760
5761 /**
5762 * Set to true if we are waiting for this window to receive its
5763 * given internal insets before laying out other windows based on it.
5764 */
5765 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005767 /**
5768 * These are the content insets that were given during layout for
5769 * this window, to be applied to windows behind it.
5770 */
5771 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005773 /**
5774 * These are the visible insets that were given during layout for
5775 * this window, to be applied to windows behind it.
5776 */
5777 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005779 /**
5780 * Flag indicating whether the touchable region should be adjusted by
5781 * the visible insets; if false the area outside the visible insets is
5782 * NOT touchable, so we must use those to adjust the frame during hit
5783 * tests.
5784 */
5785 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 // Current transformation being applied.
5788 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5789 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5790 float mHScale=1, mVScale=1;
5791 float mLastHScale=1, mLastVScale=1;
5792 final Matrix mTmpMatrix = new Matrix();
5793
5794 // "Real" frame that the application sees.
5795 final Rect mFrame = new Rect();
5796 final Rect mLastFrame = new Rect();
5797
5798 final Rect mContainingFrame = new Rect();
5799 final Rect mDisplayFrame = new Rect();
5800 final Rect mContentFrame = new Rect();
5801 final Rect mVisibleFrame = new Rect();
5802
5803 float mShownAlpha = 1;
5804 float mAlpha = 1;
5805 float mLastAlpha = 1;
5806
5807 // Set to true if, when the window gets displayed, it should perform
5808 // an enter animation.
5809 boolean mEnterAnimationPending;
5810
5811 // Currently running animation.
5812 boolean mAnimating;
5813 boolean mLocalAnimating;
5814 Animation mAnimation;
5815 boolean mAnimationIsEntrance;
5816 boolean mHasTransformation;
5817 boolean mHasLocalTransformation;
5818 final Transformation mTransformation = new Transformation();
5819
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005820 // If a window showing a wallpaper: the requested offset for the
5821 // wallpaper; if a wallpaper window: the currently applied offset.
5822 float mWallpaperX = -1;
5823 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005824
5825 // If a window showing a wallpaper: what fraction of the offset
5826 // range corresponds to a full virtual screen.
5827 float mWallpaperXStep = -1;
5828 float mWallpaperYStep = -1;
5829
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005830 // Wallpaper windows: pixels offset based on above variables.
5831 int mXOffset;
5832 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 // This is set after IWindowSession.relayout() has been called at
5835 // least once for the window. It allows us to detect the situation
5836 // where we don't yet have a surface, but should have one soon, so
5837 // we can give the window focus before waiting for the relayout.
5838 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 // This is set after the Surface has been created but before the
5841 // window has been drawn. During this time the surface is hidden.
5842 boolean mDrawPending;
5843
5844 // This is set after the window has finished drawing for the first
5845 // time but before its surface is shown. The surface will be
5846 // displayed when the next layout is run.
5847 boolean mCommitDrawPending;
5848
5849 // This is set during the time after the window's drawing has been
5850 // committed, and before its surface is actually shown. It is used
5851 // to delay showing the surface until all windows in a token are ready
5852 // to be shown.
5853 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005855 // Set when the window has been shown in the screen the first time.
5856 boolean mHasDrawn;
5857
5858 // Currently running an exit animation?
5859 boolean mExiting;
5860
5861 // Currently on the mDestroySurface list?
5862 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005864 // Completely remove from window manager after exit animation?
5865 boolean mRemoveOnExit;
5866
5867 // Set when the orientation is changing and this window has not yet
5868 // been updated for the new orientation.
5869 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005871 // Is this window now (or just being) removed?
5872 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005873
Dianne Hackborn16064f92010-03-25 00:47:24 -07005874 // For debugging, this is the last information given to the surface flinger.
5875 boolean mSurfaceShown;
5876 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
5877 int mSurfaceLayer;
5878 float mSurfaceAlpha;
5879
Jeff Brown46b9ac02010-04-22 18:58:52 -07005880 // Input channel
5881 InputChannel mInputChannel;
5882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883 WindowState(Session s, IWindow c, WindowToken token,
5884 WindowState attachedWindow, WindowManager.LayoutParams a,
5885 int viewVisibility) {
5886 mSession = s;
5887 mClient = c;
5888 mToken = token;
5889 mAttrs.copyFrom(a);
5890 mViewVisibility = viewVisibility;
5891 DeathRecipient deathRecipient = new DeathRecipient();
5892 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005893 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005894 TAG, "Window " + this + " client=" + c.asBinder()
5895 + " token=" + token + " (" + mAttrs.token + ")");
5896 try {
5897 c.asBinder().linkToDeath(deathRecipient, 0);
5898 } catch (RemoteException e) {
5899 mDeathRecipient = null;
5900 mAttachedWindow = null;
5901 mLayoutAttached = false;
5902 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005903 mIsWallpaper = false;
5904 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005905 mBaseLayer = 0;
5906 mSubLayer = 0;
5907 return;
5908 }
5909 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07005910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
5912 mAttrs.type <= LAST_SUB_WINDOW)) {
5913 // The multiplier here is to reserve space for multiple
5914 // windows in the same type layer.
5915 mBaseLayer = mPolicy.windowTypeToLayerLw(
5916 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
5917 + TYPE_LAYER_OFFSET;
5918 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
5919 mAttachedWindow = attachedWindow;
5920 mAttachedWindow.mChildWindows.add(this);
5921 mLayoutAttached = mAttrs.type !=
5922 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
5923 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
5924 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005925 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
5926 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 } else {
5928 // The multiplier here is to reserve space for multiple
5929 // windows in the same type layer.
5930 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
5931 * TYPE_LAYER_MULTIPLIER
5932 + TYPE_LAYER_OFFSET;
5933 mSubLayer = 0;
5934 mAttachedWindow = null;
5935 mLayoutAttached = false;
5936 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
5937 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005938 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
5939 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005940 }
5941
5942 WindowState appWin = this;
5943 while (appWin.mAttachedWindow != null) {
5944 appWin = mAttachedWindow;
5945 }
5946 WindowToken appToken = appWin.mToken;
5947 while (appToken.appWindowToken == null) {
5948 WindowToken parent = mTokenMap.get(appToken.token);
5949 if (parent == null || appToken == parent) {
5950 break;
5951 }
5952 appToken = parent;
5953 }
The Android Open Source Project10592532009-03-18 17:39:46 -07005954 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005955 mAppToken = appToken.appWindowToken;
5956
5957 mSurface = null;
5958 mRequestedWidth = 0;
5959 mRequestedHeight = 0;
5960 mLastRequestedWidth = 0;
5961 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005962 mXOffset = 0;
5963 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005964 mLayer = 0;
5965 mAnimLayer = 0;
5966 mLastLayer = 0;
5967 }
5968
5969 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005970 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 TAG, "Attaching " + this + " token=" + mToken
5972 + ", list=" + mToken.windows);
5973 mSession.windowAddedLocked();
5974 }
5975
5976 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
5977 mHaveFrame = true;
5978
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005979 final Rect container = mContainingFrame;
5980 container.set(pf);
5981
5982 final Rect display = mDisplayFrame;
5983 display.set(df);
5984
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07005985 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005986 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07005987 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
5988 display.intersect(mCompatibleScreenFrame);
5989 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005990 }
5991
5992 final int pw = container.right - container.left;
5993 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005994
5995 int w,h;
5996 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
5997 w = mAttrs.width < 0 ? pw : mAttrs.width;
5998 h = mAttrs.height< 0 ? ph : mAttrs.height;
5999 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006000 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6001 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006002 }
Romain Guy06882f82009-06-10 13:36:04 -07006003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006004 final Rect content = mContentFrame;
6005 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006007 final Rect visible = mVisibleFrame;
6008 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006010 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006011 final int fw = frame.width();
6012 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006014 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6015 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6016
6017 Gravity.apply(mAttrs.gravity, w, h, container,
6018 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6019 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6020
6021 //System.out.println("Out: " + mFrame);
6022
6023 // Now make sure the window fits in the overall display.
6024 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006026 // Make sure the content and visible frames are inside of the
6027 // final window frame.
6028 if (content.left < frame.left) content.left = frame.left;
6029 if (content.top < frame.top) content.top = frame.top;
6030 if (content.right > frame.right) content.right = frame.right;
6031 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6032 if (visible.left < frame.left) visible.left = frame.left;
6033 if (visible.top < frame.top) visible.top = frame.top;
6034 if (visible.right > frame.right) visible.right = frame.right;
6035 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006037 final Rect contentInsets = mContentInsets;
6038 contentInsets.left = content.left-frame.left;
6039 contentInsets.top = content.top-frame.top;
6040 contentInsets.right = frame.right-content.right;
6041 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006043 final Rect visibleInsets = mVisibleInsets;
6044 visibleInsets.left = visible.left-frame.left;
6045 visibleInsets.top = visible.top-frame.top;
6046 visibleInsets.right = frame.right-visible.right;
6047 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006048
Dianne Hackborn284ac932009-08-28 10:34:25 -07006049 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6050 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006051 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006052 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006054 if (localLOGV) {
6055 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6056 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006057 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006058 + mRequestedWidth + ", mRequestedheight="
6059 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6060 + "): frame=" + mFrame.toShortString()
6061 + " ci=" + contentInsets.toShortString()
6062 + " vi=" + visibleInsets.toShortString());
6063 //}
6064 }
6065 }
Romain Guy06882f82009-06-10 13:36:04 -07006066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006067 public Rect getFrameLw() {
6068 return mFrame;
6069 }
6070
6071 public Rect getShownFrameLw() {
6072 return mShownFrame;
6073 }
6074
6075 public Rect getDisplayFrameLw() {
6076 return mDisplayFrame;
6077 }
6078
6079 public Rect getContentFrameLw() {
6080 return mContentFrame;
6081 }
6082
6083 public Rect getVisibleFrameLw() {
6084 return mVisibleFrame;
6085 }
6086
6087 public boolean getGivenInsetsPendingLw() {
6088 return mGivenInsetsPending;
6089 }
6090
6091 public Rect getGivenContentInsetsLw() {
6092 return mGivenContentInsets;
6093 }
Romain Guy06882f82009-06-10 13:36:04 -07006094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006095 public Rect getGivenVisibleInsetsLw() {
6096 return mGivenVisibleInsets;
6097 }
Romain Guy06882f82009-06-10 13:36:04 -07006098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006099 public WindowManager.LayoutParams getAttrs() {
6100 return mAttrs;
6101 }
6102
6103 public int getSurfaceLayer() {
6104 return mLayer;
6105 }
Romain Guy06882f82009-06-10 13:36:04 -07006106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006107 public IApplicationToken getAppToken() {
6108 return mAppToken != null ? mAppToken.appToken : null;
6109 }
Jeff Brown349703e2010-06-22 01:27:15 -07006110
6111 public long getInputDispatchingTimeoutNanos() {
6112 return mAppToken != null
6113 ? mAppToken.inputDispatchingTimeoutNanos
6114 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116
6117 public boolean hasAppShownWindows() {
6118 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6119 }
6120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006121 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006122 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123 TAG, "Setting animation in " + this + ": " + anim);
6124 mAnimating = false;
6125 mLocalAnimating = false;
6126 mAnimation = anim;
6127 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6128 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6129 }
6130
6131 public void clearAnimation() {
6132 if (mAnimation != null) {
6133 mAnimating = true;
6134 mLocalAnimating = false;
6135 mAnimation = null;
6136 }
6137 }
Romain Guy06882f82009-06-10 13:36:04 -07006138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006139 Surface createSurfaceLocked() {
6140 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006141 mReportDestroySurface = false;
6142 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 mDrawPending = true;
6144 mCommitDrawPending = false;
6145 mReadyToShow = false;
6146 if (mAppToken != null) {
6147 mAppToken.allDrawn = false;
6148 }
6149
6150 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006151 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006152 flags |= Surface.PUSH_BUFFERS;
6153 }
6154
6155 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6156 flags |= Surface.SECURE;
6157 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006158 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006159 TAG, "Creating surface in session "
6160 + mSession.mSurfaceSession + " window " + this
6161 + " w=" + mFrame.width()
6162 + " h=" + mFrame.height() + " format="
6163 + mAttrs.format + " flags=" + flags);
6164
6165 int w = mFrame.width();
6166 int h = mFrame.height();
6167 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6168 // for a scaled surface, we always want the requested
6169 // size.
6170 w = mRequestedWidth;
6171 h = mRequestedHeight;
6172 }
6173
Romain Guy9825ec62009-10-01 00:58:09 -07006174 // Something is wrong and SurfaceFlinger will not like this,
6175 // try to revert to sane values
6176 if (w <= 0) w = 1;
6177 if (h <= 0) h = 1;
6178
Dianne Hackborn16064f92010-03-25 00:47:24 -07006179 mSurfaceShown = false;
6180 mSurfaceLayer = 0;
6181 mSurfaceAlpha = 1;
6182 mSurfaceX = 0;
6183 mSurfaceY = 0;
6184 mSurfaceW = w;
6185 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 try {
6187 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006188 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006189 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006190 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006191 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006192 + mSurface + " IN SESSION "
6193 + mSession.mSurfaceSession
6194 + ": pid=" + mSession.mPid + " format="
6195 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006196 + Integer.toHexString(flags)
6197 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006198 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006199 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 reclaimSomeSurfaceMemoryLocked(this, "create");
6201 return null;
6202 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006203 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006204 return null;
6205 }
Romain Guy06882f82009-06-10 13:36:04 -07006206
Joe Onorato8a9b2202010-02-26 18:56:32 -08006207 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006208 TAG, "Got surface: " + mSurface
6209 + ", set left=" + mFrame.left + " top=" + mFrame.top
6210 + ", animLayer=" + mAnimLayer);
6211 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006212 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006213 if (SHOW_TRANSACTIONS) logSurface(this,
6214 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6215 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6216 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006217 }
6218 Surface.openTransaction();
6219 try {
6220 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006221 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006222 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006223 mSurface.setPosition(mSurfaceX, mSurfaceY);
6224 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006225 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006226 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006227 mSurface.hide();
6228 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006229 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006230 mSurface.setFlags(Surface.SURFACE_DITHER,
6231 Surface.SURFACE_DITHER);
6232 }
6233 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006234 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006235 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6236 }
6237 mLastHidden = true;
6238 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006239 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006240 Surface.closeTransaction();
6241 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006242 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006243 TAG, "Created surface " + this);
6244 }
6245 return mSurface;
6246 }
Romain Guy06882f82009-06-10 13:36:04 -07006247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006248 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006249 if (mAppToken != null && this == mAppToken.startingWindow) {
6250 mAppToken.startingDisplayed = false;
6251 }
Romain Guy06882f82009-06-10 13:36:04 -07006252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006253 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006254 mDrawPending = false;
6255 mCommitDrawPending = false;
6256 mReadyToShow = false;
6257
6258 int i = mChildWindows.size();
6259 while (i > 0) {
6260 i--;
6261 WindowState c = (WindowState)mChildWindows.get(i);
6262 c.mAttachedHidden = true;
Jeff Brown349703e2010-06-22 01:27:15 -07006263
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006264 mInputMonitor.windowIsBecomingInvisibleLw(c);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006266
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006267 if (mReportDestroySurface) {
6268 mReportDestroySurface = false;
6269 mSurfacePendingDestroy = true;
6270 try {
6271 mClient.dispatchGetNewSurface();
6272 // We'll really destroy on the next time around.
6273 return;
6274 } catch (RemoteException e) {
6275 }
6276 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006279 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006280 RuntimeException e = null;
6281 if (!HIDE_STACK_CRAWLS) {
6282 e = new RuntimeException();
6283 e.fillInStackTrace();
6284 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006285 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006286 + mSurface + ", session " + mSession, e);
6287 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006288 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006289 RuntimeException e = null;
6290 if (!HIDE_STACK_CRAWLS) {
6291 e = new RuntimeException();
6292 e.fillInStackTrace();
6293 }
6294 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006296 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006298 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006299 + " surface " + mSurface + " session " + mSession
6300 + ": " + e.toString());
6301 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006302
Dianne Hackborn16064f92010-03-25 00:47:24 -07006303 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006304 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305 }
6306 }
6307
6308 boolean finishDrawingLocked() {
6309 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006310 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006311 TAG, "finishDrawingLocked: " + mSurface);
6312 mCommitDrawPending = true;
6313 mDrawPending = false;
6314 return true;
6315 }
6316 return false;
6317 }
6318
6319 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006320 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006321 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006322 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006323 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 }
6325 mCommitDrawPending = false;
6326 mReadyToShow = true;
6327 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6328 final AppWindowToken atoken = mAppToken;
6329 if (atoken == null || atoken.allDrawn || starting) {
6330 performShowLocked();
6331 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006332 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006333 }
6334
6335 // This must be called while inside a transaction.
6336 boolean performShowLocked() {
6337 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006338 RuntimeException e = null;
6339 if (!HIDE_STACK_CRAWLS) {
6340 e = new RuntimeException();
6341 e.fillInStackTrace();
6342 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006343 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006344 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6345 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6346 }
6347 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006348 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6349 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006350 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006351 + " during animation: policyVis=" + mPolicyVisibility
6352 + " attHidden=" + mAttachedHidden
6353 + " tok.hiddenRequested="
6354 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006355 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006356 + (mAppToken != null ? mAppToken.hidden : false)
6357 + " animating=" + mAnimating
6358 + " tok animating="
6359 + (mAppToken != null ? mAppToken.animating : false));
6360 if (!showSurfaceRobustlyLocked(this)) {
6361 return false;
6362 }
6363 mLastAlpha = -1;
6364 mHasDrawn = true;
6365 mLastHidden = false;
6366 mReadyToShow = false;
6367 enableScreenIfNeededLocked();
6368
6369 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006371 int i = mChildWindows.size();
6372 while (i > 0) {
6373 i--;
6374 WindowState c = (WindowState)mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006375 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006377 if (c.mSurface != null) {
6378 c.performShowLocked();
6379 // It hadn't been shown, which means layout not
6380 // performed on it, so now we want to make sure to
6381 // do a layout. If called from within the transaction
6382 // loop, this will cause it to restart with a new
6383 // layout.
6384 mLayoutNeeded = true;
6385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 }
6387 }
Romain Guy06882f82009-06-10 13:36:04 -07006388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 if (mAttrs.type != TYPE_APPLICATION_STARTING
6390 && mAppToken != null) {
6391 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006392
Dianne Hackborn248b1882009-09-16 16:46:44 -07006393 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006394 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006395 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006397 // If this initial window is animating, stop it -- we
6398 // will do an animation to reveal it from behind the
6399 // starting window, so there is no need for it to also
6400 // be doing its own stuff.
6401 if (mAnimation != null) {
6402 mAnimation = null;
6403 // Make sure we clean up the animation.
6404 mAnimating = true;
6405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006406 mFinishedStarting.add(mAppToken);
6407 mH.sendEmptyMessage(H.FINISHED_STARTING);
6408 }
6409 mAppToken.updateReportedVisibilityLocked();
6410 }
6411 }
6412 return true;
6413 }
Romain Guy06882f82009-06-10 13:36:04 -07006414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 // This must be called while inside a transaction. Returns true if
6416 // there is more animation to run.
6417 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006418 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6422 mHasTransformation = true;
6423 mHasLocalTransformation = true;
6424 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006425 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006426 TAG, "Starting animation in " + this +
6427 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6428 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6429 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6430 mAnimation.setStartTime(currentTime);
6431 mLocalAnimating = true;
6432 mAnimating = true;
6433 }
6434 mTransformation.clear();
6435 final boolean more = mAnimation.getTransformation(
6436 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006437 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 TAG, "Stepped animation in " + this +
6439 ": more=" + more + ", xform=" + mTransformation);
6440 if (more) {
6441 // we're not done!
6442 return true;
6443 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006444 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006445 TAG, "Finished animation in " + this +
6446 " @ " + currentTime);
6447 mAnimation = null;
6448 //WindowManagerService.this.dump();
6449 }
6450 mHasLocalTransformation = false;
6451 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006452 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 // When our app token is animating, we kind-of pretend like
6454 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6455 // part of this check means that we will only do this if
6456 // our window is not currently exiting, or it is not
6457 // locally animating itself. The idea being that one that
6458 // is exiting and doing a local animation should be removed
6459 // once that animation is done.
6460 mAnimating = true;
6461 mHasTransformation = true;
6462 mTransformation.clear();
6463 return false;
6464 } else if (mHasTransformation) {
6465 // Little trick to get through the path below to act like
6466 // we have finished an animation.
6467 mAnimating = true;
6468 } else if (isAnimating()) {
6469 mAnimating = true;
6470 }
6471 } else if (mAnimation != null) {
6472 // If the display is frozen, and there is a pending animation,
6473 // clear it and make sure we run the cleanup code.
6474 mAnimating = true;
6475 mLocalAnimating = true;
6476 mAnimation = null;
6477 }
Romain Guy06882f82009-06-10 13:36:04 -07006478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006479 if (!mAnimating && !mLocalAnimating) {
6480 return false;
6481 }
6482
Joe Onorato8a9b2202010-02-26 18:56:32 -08006483 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006484 TAG, "Animation done in " + this + ": exiting=" + mExiting
6485 + ", reportedVisible="
6486 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 mAnimating = false;
6489 mLocalAnimating = false;
6490 mAnimation = null;
6491 mAnimLayer = mLayer;
6492 if (mIsImWindow) {
6493 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006494 } else if (mIsWallpaper) {
6495 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006497 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 + " anim layer: " + mAnimLayer);
6499 mHasTransformation = false;
6500 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006501 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6502 if (DEBUG_VISIBILITY) {
6503 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6504 + mPolicyVisibilityAfterAnim);
6505 }
6506 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6507 if (!mPolicyVisibility) {
6508 if (mCurrentFocus == this) {
6509 mFocusMayChange = true;
6510 }
6511 // Window is no longer visible -- make sure if we were waiting
6512 // for it to be displayed before enabling the display, that
6513 // we allow the display to be enabled now.
6514 enableScreenIfNeededLocked();
6515 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006516 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006517 mTransformation.clear();
6518 if (mHasDrawn
6519 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6520 && mAppToken != null
6521 && mAppToken.firstWindowDrawn
6522 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006523 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006524 + mToken + ": first real window done animating");
6525 mFinishedStarting.add(mAppToken);
6526 mH.sendEmptyMessage(H.FINISHED_STARTING);
6527 }
Romain Guy06882f82009-06-10 13:36:04 -07006528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006529 finishExit();
6530
6531 if (mAppToken != null) {
6532 mAppToken.updateReportedVisibilityLocked();
6533 }
6534
6535 return false;
6536 }
6537
6538 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006539 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006540 TAG, "finishExit in " + this
6541 + ": exiting=" + mExiting
6542 + " remove=" + mRemoveOnExit
6543 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006545 final int N = mChildWindows.size();
6546 for (int i=0; i<N; i++) {
6547 ((WindowState)mChildWindows.get(i)).finishExit();
6548 }
Romain Guy06882f82009-06-10 13:36:04 -07006549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006550 if (!mExiting) {
6551 return;
6552 }
Romain Guy06882f82009-06-10 13:36:04 -07006553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006554 if (isWindowAnimating()) {
6555 return;
6556 }
6557
Joe Onorato8a9b2202010-02-26 18:56:32 -08006558 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006559 TAG, "Exit animation finished in " + this
6560 + ": remove=" + mRemoveOnExit);
6561 if (mSurface != null) {
6562 mDestroySurface.add(this);
6563 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006564 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006565 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006566 try {
6567 mSurface.hide();
6568 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006569 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 }
6571 mLastHidden = true;
Jeff Brown349703e2010-06-22 01:27:15 -07006572
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006573 for (int i=0; i<N; i++) {
6574 mInputMonitor.windowIsBecomingInvisibleLw((WindowState)mChildWindows.get(i));
Jeff Brown349703e2010-06-22 01:27:15 -07006575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006576 }
6577 mExiting = false;
6578 if (mRemoveOnExit) {
6579 mPendingRemove.add(this);
6580 mRemoveOnExit = false;
6581 }
6582 }
Romain Guy06882f82009-06-10 13:36:04 -07006583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006584 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6585 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6586 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6587 if (dtdx < -.000001f || dtdx > .000001f) return false;
6588 if (dsdy < -.000001f || dsdy > .000001f) return false;
6589 return true;
6590 }
Romain Guy06882f82009-06-10 13:36:04 -07006591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006592 void computeShownFrameLocked() {
6593 final boolean selfTransformation = mHasLocalTransformation;
6594 Transformation attachedTransformation =
6595 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6596 ? mAttachedWindow.mTransformation : null;
6597 Transformation appTransformation =
6598 (mAppToken != null && mAppToken.hasTransformation)
6599 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006600
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006601 // Wallpapers are animated based on the "real" window they
6602 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006603 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006604 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006605 if (mWallpaperTarget.mHasLocalTransformation &&
6606 mWallpaperTarget.mAnimation != null &&
6607 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006608 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006609 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006610 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006611 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006612 }
6613 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006614 mWallpaperTarget.mAppToken.hasTransformation &&
6615 mWallpaperTarget.mAppToken.animation != null &&
6616 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006617 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006618 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006619 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006620 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006621 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006622 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006624 if (selfTransformation || attachedTransformation != null
6625 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006626 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006627 final Rect frame = mFrame;
6628 final float tmpFloats[] = mTmpFloats;
6629 final Matrix tmpMatrix = mTmpMatrix;
6630
6631 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006632 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006633 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006634 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006636 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006637 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006638 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006639 }
6640 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006641 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642 }
6643
6644 // "convert" it into SurfaceFlinger's format
6645 // (a 2x2 matrix + an offset)
6646 // Here we must not transform the position of the surface
6647 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006648 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006650 tmpMatrix.getValues(tmpFloats);
6651 mDsDx = tmpFloats[Matrix.MSCALE_X];
6652 mDtDx = tmpFloats[Matrix.MSKEW_X];
6653 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6654 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006655 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6656 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006657 int w = frame.width();
6658 int h = frame.height();
6659 mShownFrame.set(x, y, x+w, y+h);
6660
6661 // Now set the alpha... but because our current hardware
6662 // can't do alpha transformation on a non-opaque surface,
6663 // turn it off if we are running an animation that is also
6664 // transforming since it is more important to have that
6665 // animation be smooth.
6666 mShownAlpha = mAlpha;
6667 if (!mLimitedAlphaCompositing
6668 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6669 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6670 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006671 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006672 if (selfTransformation) {
6673 mShownAlpha *= mTransformation.getAlpha();
6674 }
6675 if (attachedTransformation != null) {
6676 mShownAlpha *= attachedTransformation.getAlpha();
6677 }
6678 if (appTransformation != null) {
6679 mShownAlpha *= appTransformation.getAlpha();
6680 }
6681 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006682 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 }
Romain Guy06882f82009-06-10 13:36:04 -07006684
Joe Onorato8a9b2202010-02-26 18:56:32 -08006685 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 TAG, "Continuing animation in " + this +
6687 ": " + mShownFrame +
6688 ", alpha=" + mTransformation.getAlpha());
6689 return;
6690 }
Romain Guy06882f82009-06-10 13:36:04 -07006691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006692 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006693 if (mXOffset != 0 || mYOffset != 0) {
6694 mShownFrame.offset(mXOffset, mYOffset);
6695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006696 mShownAlpha = mAlpha;
6697 mDsDx = 1;
6698 mDtDx = 0;
6699 mDsDy = 0;
6700 mDtDy = 1;
6701 }
Romain Guy06882f82009-06-10 13:36:04 -07006702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 /**
6704 * Is this window visible? It is not visible if there is no
6705 * surface, or we are in the process of running an exit animation
6706 * that will remove the surface, or its app token has been hidden.
6707 */
6708 public boolean isVisibleLw() {
6709 final AppWindowToken atoken = mAppToken;
6710 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6711 && (atoken == null || !atoken.hiddenRequested)
6712 && !mExiting && !mDestroying;
6713 }
6714
6715 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006716 * Like {@link #isVisibleLw}, but also counts a window that is currently
6717 * "hidden" behind the keyguard as visible. This allows us to apply
6718 * things like window flags that impact the keyguard.
6719 * XXX I am starting to think we need to have ANOTHER visibility flag
6720 * for this "hidden behind keyguard" state rather than overloading
6721 * mPolicyVisibility. Ungh.
6722 */
6723 public boolean isVisibleOrBehindKeyguardLw() {
6724 final AppWindowToken atoken = mAppToken;
6725 return mSurface != null && !mAttachedHidden
6726 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006727 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006728 && !mExiting && !mDestroying;
6729 }
6730
6731 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 * Is this window visible, ignoring its app token? It is not visible
6733 * if there is no surface, or we are in the process of running an exit animation
6734 * that will remove the surface.
6735 */
6736 public boolean isWinVisibleLw() {
6737 final AppWindowToken atoken = mAppToken;
6738 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6739 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6740 && !mExiting && !mDestroying;
6741 }
6742
6743 /**
6744 * The same as isVisible(), but follows the current hidden state of
6745 * the associated app token, not the pending requested hidden state.
6746 */
6747 boolean isVisibleNow() {
6748 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006749 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 }
6751
6752 /**
6753 * Same as isVisible(), but we also count it as visible between the
6754 * call to IWindowSession.add() and the first relayout().
6755 */
6756 boolean isVisibleOrAdding() {
6757 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006758 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006759 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6760 && mPolicyVisibility && !mAttachedHidden
6761 && (atoken == null || !atoken.hiddenRequested)
6762 && !mExiting && !mDestroying;
6763 }
6764
6765 /**
6766 * Is this window currently on-screen? It is on-screen either if it
6767 * is visible or it is currently running an animation before no longer
6768 * being visible.
6769 */
6770 boolean isOnScreen() {
6771 final AppWindowToken atoken = mAppToken;
6772 if (atoken != null) {
6773 return mSurface != null && mPolicyVisibility && !mDestroying
6774 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006775 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 } else {
6777 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006778 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006779 }
6780 }
Romain Guy06882f82009-06-10 13:36:04 -07006781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006782 /**
6783 * Like isOnScreen(), but we don't return true if the window is part
6784 * of a transition that has not yet been started.
6785 */
6786 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006787 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006788 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006789 return false;
6790 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006792 final boolean animating = atoken != null
6793 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006794 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006795 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6796 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006797 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 }
6799
6800 /** Is the window or its container currently animating? */
6801 boolean isAnimating() {
6802 final WindowState attached = mAttachedWindow;
6803 final AppWindowToken atoken = mAppToken;
6804 return mAnimation != null
6805 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006806 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 (atoken.animation != null
6808 || atoken.inPendingTransaction));
6809 }
6810
6811 /** Is this window currently animating? */
6812 boolean isWindowAnimating() {
6813 return mAnimation != null;
6814 }
6815
6816 /**
6817 * Like isOnScreen, but returns false if the surface hasn't yet
6818 * been drawn.
6819 */
6820 public boolean isDisplayedLw() {
6821 final AppWindowToken atoken = mAppToken;
6822 return mSurface != null && mPolicyVisibility && !mDestroying
6823 && !mDrawPending && !mCommitDrawPending
6824 && ((!mAttachedHidden &&
6825 (atoken == null || !atoken.hiddenRequested))
6826 || mAnimating);
6827 }
6828
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006829 /**
6830 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006831 * complete UI in to. Note that this returns true if the orientation
6832 * is changing even if the window hasn't redrawn because we don't want
6833 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006834 */
6835 public boolean isDrawnLw() {
6836 final AppWindowToken atoken = mAppToken;
6837 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006838 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006839 }
6840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6842 boolean shownFrame, boolean onlyOpaque) {
6843 if (mSurface == null) {
6844 return false;
6845 }
6846 if (mAppToken != null && !mAppToken.appFullscreen) {
6847 return false;
6848 }
6849 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6850 return false;
6851 }
6852 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006853
6854 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6855 return frame.left <= mCompatibleScreenFrame.left &&
6856 frame.top <= mCompatibleScreenFrame.top &&
6857 frame.right >= mCompatibleScreenFrame.right &&
6858 frame.bottom >= mCompatibleScreenFrame.bottom;
6859 } else {
6860 return frame.left <= 0 && frame.top <= 0
6861 && frame.right >= screenWidth
6862 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006863 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 }
Romain Guy06882f82009-06-10 13:36:04 -07006865
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006866 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006867 * Return true if the window is opaque and fully drawn. This indicates
6868 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006869 */
6870 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006871 return (mAttrs.format == PixelFormat.OPAQUE
6872 || mAttrs.type == TYPE_WALLPAPER)
6873 && mSurface != null && mAnimation == null
6874 && (mAppToken == null || mAppToken.animation == null)
6875 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006876 }
6877
6878 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6879 return
6880 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006881 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6882 // only if it's visible
6883 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006884 // and only if the application fills the compatible screen
6885 mFrame.left <= mCompatibleScreenFrame.left &&
6886 mFrame.top <= mCompatibleScreenFrame.top &&
6887 mFrame.right >= mCompatibleScreenFrame.right &&
6888 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006889 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006890 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006891 }
6892
6893 boolean isFullscreen(int screenWidth, int screenHeight) {
6894 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006895 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006896 }
6897
6898 void removeLocked() {
6899 if (mAttachedWindow != null) {
6900 mAttachedWindow.mChildWindows.remove(this);
6901 }
6902 destroySurfaceLocked();
6903 mSession.windowRemovedLocked();
6904 try {
6905 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
6906 } catch (RuntimeException e) {
6907 // Ignore if it has already been removed (usually because
6908 // we are doing this as part of processing a death note.)
6909 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07006910
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006911 if (mInputChannel != null) {
6912 mInputManager.unregisterInputChannel(mInputChannel);
6913
6914 mInputChannel.dispose();
6915 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006916 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006917 }
6918
6919 private class DeathRecipient implements IBinder.DeathRecipient {
6920 public void binderDied() {
6921 try {
6922 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006923 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006924 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006925 if (win != null) {
6926 removeWindowLocked(mSession, win);
6927 }
6928 }
6929 } catch (IllegalArgumentException ex) {
6930 // This will happen if the window has already been
6931 // removed.
6932 }
6933 }
6934 }
6935
6936 /** Returns true if this window desires key events. */
6937 public final boolean canReceiveKeys() {
6938 return isVisibleOrAdding()
6939 && (mViewVisibility == View.VISIBLE)
6940 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
6941 }
6942
6943 public boolean hasDrawnLw() {
6944 return mHasDrawn;
6945 }
6946
6947 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006948 return showLw(doAnimation, true);
6949 }
6950
6951 boolean showLw(boolean doAnimation, boolean requestAnim) {
6952 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
6953 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006954 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006955 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006956 if (doAnimation) {
6957 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
6958 + mPolicyVisibility + " mAnimation=" + mAnimation);
6959 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
6960 doAnimation = false;
6961 } else if (mPolicyVisibility && mAnimation == null) {
6962 // Check for the case where we are currently visible and
6963 // not animating; we do not want to do animation at such a
6964 // point to become visible when we already are.
6965 doAnimation = false;
6966 }
6967 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006968 mPolicyVisibility = true;
6969 mPolicyVisibilityAfterAnim = true;
6970 if (doAnimation) {
6971 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
6972 }
6973 if (requestAnim) {
6974 requestAnimationLocked(0);
6975 }
6976 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 }
6978
6979 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006980 return hideLw(doAnimation, true);
6981 }
6982
6983 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006984 if (doAnimation) {
6985 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
6986 doAnimation = false;
6987 }
6988 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006989 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
6990 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006991 if (!current) {
6992 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006993 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006994 if (doAnimation) {
6995 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
6996 if (mAnimation == null) {
6997 doAnimation = false;
6998 }
6999 }
7000 if (doAnimation) {
7001 mPolicyVisibilityAfterAnim = false;
7002 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007003 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007004 mPolicyVisibilityAfterAnim = false;
7005 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007006 // Window is no longer visible -- make sure if we were waiting
7007 // for it to be displayed before enabling the display, that
7008 // we allow the display to be enabled now.
7009 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007010 if (mCurrentFocus == this) {
7011 mFocusMayChange = true;
7012 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007013 }
7014 if (requestAnim) {
7015 requestAnimationLocked(0);
7016 }
7017 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 }
7019
7020 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007021 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7022 pw.print(" mClient="); pw.println(mClient.asBinder());
7023 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7024 if (mAttachedWindow != null || mLayoutAttached) {
7025 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7026 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7027 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007028 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7029 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7030 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007031 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7032 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007033 }
7034 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7035 pw.print(" mSubLayer="); pw.print(mSubLayer);
7036 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7037 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7038 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7039 pw.print("="); pw.print(mAnimLayer);
7040 pw.print(" mLastLayer="); pw.println(mLastLayer);
7041 if (mSurface != null) {
7042 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007043 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7044 pw.print(" layer="); pw.print(mSurfaceLayer);
7045 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7046 pw.print(" rect=("); pw.print(mSurfaceX);
7047 pw.print(","); pw.print(mSurfaceY);
7048 pw.print(") "); pw.print(mSurfaceW);
7049 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007050 }
7051 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7052 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7053 if (mAppToken != null) {
7054 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7055 }
7056 if (mTargetAppToken != null) {
7057 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7058 }
7059 pw.print(prefix); pw.print("mViewVisibility=0x");
7060 pw.print(Integer.toHexString(mViewVisibility));
7061 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007062 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7063 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007064 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7065 pw.print(prefix); pw.print("mPolicyVisibility=");
7066 pw.print(mPolicyVisibility);
7067 pw.print(" mPolicyVisibilityAfterAnim=");
7068 pw.print(mPolicyVisibilityAfterAnim);
7069 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7070 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007071 if (!mRelayoutCalled) {
7072 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7073 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007074 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007075 pw.print(" h="); pw.print(mRequestedHeight);
7076 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007077 if (mXOffset != 0 || mYOffset != 0) {
7078 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7079 pw.print(" y="); pw.println(mYOffset);
7080 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007081 pw.print(prefix); pw.print("mGivenContentInsets=");
7082 mGivenContentInsets.printShortString(pw);
7083 pw.print(" mGivenVisibleInsets=");
7084 mGivenVisibleInsets.printShortString(pw);
7085 pw.println();
7086 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7087 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7088 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7089 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007090 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007091 pw.print(prefix); pw.print("mShownFrame=");
7092 mShownFrame.printShortString(pw);
7093 pw.print(" last="); mLastShownFrame.printShortString(pw);
7094 pw.println();
7095 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7096 pw.print(" last="); mLastFrame.printShortString(pw);
7097 pw.println();
7098 pw.print(prefix); pw.print("mContainingFrame=");
7099 mContainingFrame.printShortString(pw);
7100 pw.print(" mDisplayFrame=");
7101 mDisplayFrame.printShortString(pw);
7102 pw.println();
7103 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7104 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7105 pw.println();
7106 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7107 pw.print(" last="); mLastContentInsets.printShortString(pw);
7108 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7109 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7110 pw.println();
7111 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7112 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7113 pw.print(" mAlpha="); pw.print(mAlpha);
7114 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7115 }
7116 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7117 || mAnimation != null) {
7118 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7119 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7120 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7121 pw.print(" mAnimation="); pw.println(mAnimation);
7122 }
7123 if (mHasTransformation || mHasLocalTransformation) {
7124 pw.print(prefix); pw.print("XForm: has=");
7125 pw.print(mHasTransformation);
7126 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7127 pw.print(" "); mTransformation.printShortString(pw);
7128 pw.println();
7129 }
7130 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7131 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7132 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7133 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7134 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7135 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7136 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7137 pw.print(" mDestroying="); pw.print(mDestroying);
7138 pw.print(" mRemoved="); pw.println(mRemoved);
7139 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007140 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007141 pw.print(prefix); pw.print("mOrientationChanging=");
7142 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007143 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7144 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007145 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007146 if (mHScale != 1 || mVScale != 1) {
7147 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7148 pw.print(" mVScale="); pw.println(mVScale);
7149 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007150 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007151 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7152 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7153 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007154 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7155 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7156 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007158 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007159
7160 String makeInputChannelName() {
7161 return Integer.toHexString(System.identityHashCode(this))
7162 + " " + mAttrs.getTitle();
7163 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007164
7165 @Override
7166 public String toString() {
7167 return "Window{"
7168 + Integer.toHexString(System.identityHashCode(this))
7169 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7170 }
7171 }
Romain Guy06882f82009-06-10 13:36:04 -07007172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007173 // -------------------------------------------------------------
7174 // Window Token State
7175 // -------------------------------------------------------------
7176
7177 class WindowToken {
7178 // The actual token.
7179 final IBinder token;
7180
7181 // The type of window this token is for, as per WindowManager.LayoutParams.
7182 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007184 // Set if this token was explicitly added by a client, so should
7185 // not be removed when all windows are removed.
7186 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007187
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007188 // For printing.
7189 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007191 // If this is an AppWindowToken, this is non-null.
7192 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 // All of the windows associated with this token.
7195 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7196
7197 // Is key dispatching paused for this token?
7198 boolean paused = false;
7199
7200 // Should this token's windows be hidden?
7201 boolean hidden;
7202
7203 // Temporary for finding which tokens no longer have visible windows.
7204 boolean hasVisible;
7205
Dianne Hackborna8f60182009-09-01 19:01:50 -07007206 // Set to true when this token is in a pending transaction where it
7207 // will be shown.
7208 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007209
Dianne Hackborna8f60182009-09-01 19:01:50 -07007210 // Set to true when this token is in a pending transaction where it
7211 // will be hidden.
7212 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007213
Dianne Hackborna8f60182009-09-01 19:01:50 -07007214 // Set to true when this token is in a pending transaction where its
7215 // windows will be put to the bottom of the list.
7216 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007217
Dianne Hackborna8f60182009-09-01 19:01:50 -07007218 // Set to true when this token is in a pending transaction where its
7219 // windows will be put to the top of the list.
7220 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007222 WindowToken(IBinder _token, int type, boolean _explicit) {
7223 token = _token;
7224 windowType = type;
7225 explicit = _explicit;
7226 }
7227
7228 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007229 pw.print(prefix); pw.print("token="); pw.println(token);
7230 pw.print(prefix); pw.print("windows="); pw.println(windows);
7231 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7232 pw.print(" hidden="); pw.print(hidden);
7233 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007234 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7235 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7236 pw.print(" waitingToHide="); pw.print(waitingToHide);
7237 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7238 pw.print(" sendingToTop="); pw.println(sendingToTop);
7239 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007240 }
7241
7242 @Override
7243 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007244 if (stringName == null) {
7245 StringBuilder sb = new StringBuilder();
7246 sb.append("WindowToken{");
7247 sb.append(Integer.toHexString(System.identityHashCode(this)));
7248 sb.append(" token="); sb.append(token); sb.append('}');
7249 stringName = sb.toString();
7250 }
7251 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 }
7253 };
7254
7255 class AppWindowToken extends WindowToken {
7256 // Non-null only for application tokens.
7257 final IApplicationToken appToken;
7258
7259 // All of the windows and child windows that are included in this
7260 // application token. Note this list is NOT sorted!
7261 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7262
7263 int groupId = -1;
7264 boolean appFullscreen;
7265 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007266
7267 // The input dispatching timeout for this application token in nanoseconds.
7268 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007270 // These are used for determining when all windows associated with
7271 // an activity have been drawn, so they can be made visible together
7272 // at the same time.
7273 int lastTransactionSequence = mTransactionSequence-1;
7274 int numInterestingWindows;
7275 int numDrawnWindows;
7276 boolean inPendingTransaction;
7277 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 // Is this token going to be hidden in a little while? If so, it
7280 // won't be taken into account for setting the screen orientation.
7281 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 // Is this window's surface needed? This is almost like hidden, except
7284 // it will sometimes be true a little earlier: when the token has
7285 // been shown, but is still waiting for its app transition to execute
7286 // before making its windows shown.
7287 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 // Have we told the window clients to hide themselves?
7290 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007292 // Last visibility state we reported to the app token.
7293 boolean reportedVisible;
7294
7295 // Set to true when the token has been removed from the window mgr.
7296 boolean removed;
7297
7298 // Have we been asked to have this token keep the screen frozen?
7299 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301 boolean animating;
7302 Animation animation;
7303 boolean hasTransformation;
7304 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007306 // Offset to the window of all layers in the token, for use by
7307 // AppWindowToken animations.
7308 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 // Information about an application starting window if displayed.
7311 StartingData startingData;
7312 WindowState startingWindow;
7313 View startingView;
7314 boolean startingDisplayed;
7315 boolean startingMoved;
7316 boolean firstWindowDrawn;
7317
7318 AppWindowToken(IApplicationToken _token) {
7319 super(_token.asBinder(),
7320 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7321 appWindowToken = this;
7322 appToken = _token;
7323 }
Romain Guy06882f82009-06-10 13:36:04 -07007324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007326 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007327 TAG, "Setting animation in " + this + ": " + anim);
7328 animation = anim;
7329 animating = false;
7330 anim.restrictDuration(MAX_ANIMATION_DURATION);
7331 anim.scaleCurrentDuration(mTransitionAnimationScale);
7332 int zorder = anim.getZAdjustment();
7333 int adj = 0;
7334 if (zorder == Animation.ZORDER_TOP) {
7335 adj = TYPE_LAYER_OFFSET;
7336 } else if (zorder == Animation.ZORDER_BOTTOM) {
7337 adj = -TYPE_LAYER_OFFSET;
7338 }
Romain Guy06882f82009-06-10 13:36:04 -07007339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 if (animLayerAdjustment != adj) {
7341 animLayerAdjustment = adj;
7342 updateLayers();
7343 }
7344 }
Romain Guy06882f82009-06-10 13:36:04 -07007345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 public void setDummyAnimation() {
7347 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007348 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007349 TAG, "Setting dummy animation in " + this);
7350 animation = sDummyAnimation;
7351 }
7352 }
7353
7354 public void clearAnimation() {
7355 if (animation != null) {
7356 animation = null;
7357 animating = true;
7358 }
7359 }
Romain Guy06882f82009-06-10 13:36:04 -07007360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007361 void updateLayers() {
7362 final int N = allAppWindows.size();
7363 final int adj = animLayerAdjustment;
7364 for (int i=0; i<N; i++) {
7365 WindowState w = allAppWindows.get(i);
7366 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007367 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 + w.mAnimLayer);
7369 if (w == mInputMethodTarget) {
7370 setInputMethodAnimLayerAdjustment(adj);
7371 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007372 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007373 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007375 }
7376 }
Romain Guy06882f82009-06-10 13:36:04 -07007377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 void sendAppVisibilityToClients() {
7379 final int N = allAppWindows.size();
7380 for (int i=0; i<N; i++) {
7381 WindowState win = allAppWindows.get(i);
7382 if (win == startingWindow && clientHidden) {
7383 // Don't hide the starting window.
7384 continue;
7385 }
7386 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007387 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007388 "Setting visibility of " + win + ": " + (!clientHidden));
7389 win.mClient.dispatchAppVisibility(!clientHidden);
7390 } catch (RemoteException e) {
7391 }
7392 }
7393 }
Romain Guy06882f82009-06-10 13:36:04 -07007394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007395 void showAllWindowsLocked() {
7396 final int NW = allAppWindows.size();
7397 for (int i=0; i<NW; i++) {
7398 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007399 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007400 "performing show on: " + w);
7401 w.performShowLocked();
7402 }
7403 }
Romain Guy06882f82009-06-10 13:36:04 -07007404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 // This must be called while inside a transaction.
7406 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007407 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 if (animation == sDummyAnimation) {
7411 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007412 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 // when it is really time to animate, this will be set to
7414 // a real animation and the next call will execute normally.
7415 return false;
7416 }
Romain Guy06882f82009-06-10 13:36:04 -07007417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7419 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007420 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 TAG, "Starting animation in " + this +
7422 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7423 + " scale=" + mTransitionAnimationScale
7424 + " allDrawn=" + allDrawn + " animating=" + animating);
7425 animation.initialize(dw, dh, dw, dh);
7426 animation.setStartTime(currentTime);
7427 animating = true;
7428 }
7429 transformation.clear();
7430 final boolean more = animation.getTransformation(
7431 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007432 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 TAG, "Stepped animation in " + this +
7434 ": more=" + more + ", xform=" + transformation);
7435 if (more) {
7436 // we're done!
7437 hasTransformation = true;
7438 return true;
7439 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007440 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 TAG, "Finished animation in " + this +
7442 " @ " + currentTime);
7443 animation = null;
7444 }
7445 } else if (animation != null) {
7446 // If the display is frozen, and there is a pending animation,
7447 // clear it and make sure we run the cleanup code.
7448 animating = true;
7449 animation = null;
7450 }
7451
7452 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 if (!animating) {
7455 return false;
7456 }
7457
7458 clearAnimation();
7459 animating = false;
7460 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7461 moveInputMethodWindowsIfNeededLocked(true);
7462 }
Romain Guy06882f82009-06-10 13:36:04 -07007463
Joe Onorato8a9b2202010-02-26 18:56:32 -08007464 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007465 TAG, "Animation done in " + this
7466 + ": reportedVisible=" + reportedVisible);
7467
7468 transformation.clear();
7469 if (animLayerAdjustment != 0) {
7470 animLayerAdjustment = 0;
7471 updateLayers();
7472 }
Romain Guy06882f82009-06-10 13:36:04 -07007473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 final int N = windows.size();
7475 for (int i=0; i<N; i++) {
7476 ((WindowState)windows.get(i)).finishExit();
7477 }
7478 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 return false;
7481 }
7482
7483 void updateReportedVisibilityLocked() {
7484 if (appToken == null) {
7485 return;
7486 }
Romain Guy06882f82009-06-10 13:36:04 -07007487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007488 int numInteresting = 0;
7489 int numVisible = 0;
7490 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007491
Joe Onorato8a9b2202010-02-26 18:56:32 -08007492 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 final int N = allAppWindows.size();
7494 for (int i=0; i<N; i++) {
7495 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007496 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007497 || win.mViewVisibility != View.VISIBLE
7498 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 continue;
7500 }
7501 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007502 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007503 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007504 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007505 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007506 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 + " pv=" + win.mPolicyVisibility
7508 + " dp=" + win.mDrawPending
7509 + " cdp=" + win.mCommitDrawPending
7510 + " ah=" + win.mAttachedHidden
7511 + " th="
7512 + (win.mAppToken != null
7513 ? win.mAppToken.hiddenRequested : false)
7514 + " a=" + win.mAnimating);
7515 }
7516 }
7517 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007518 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007519 if (!win.isAnimating()) {
7520 numVisible++;
7521 }
7522 nowGone = false;
7523 } else if (win.isAnimating()) {
7524 nowGone = false;
7525 }
7526 }
Romain Guy06882f82009-06-10 13:36:04 -07007527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007528 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007529 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 + numInteresting + " visible=" + numVisible);
7531 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007532 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007533 TAG, "Visibility changed in " + this
7534 + ": vis=" + nowVisible);
7535 reportedVisible = nowVisible;
7536 Message m = mH.obtainMessage(
7537 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7538 nowVisible ? 1 : 0,
7539 nowGone ? 1 : 0,
7540 this);
7541 mH.sendMessage(m);
7542 }
7543 }
Romain Guy06882f82009-06-10 13:36:04 -07007544
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007545 WindowState findMainWindow() {
7546 int j = windows.size();
7547 while (j > 0) {
7548 j--;
7549 WindowState win = windows.get(j);
7550 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7551 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7552 return win;
7553 }
7554 }
7555 return null;
7556 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 void dump(PrintWriter pw, String prefix) {
7559 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007560 if (appToken != null) {
7561 pw.print(prefix); pw.println("app=true");
7562 }
7563 if (allAppWindows.size() > 0) {
7564 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7565 }
7566 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007567 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007568 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7569 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7570 pw.print(" clientHidden="); pw.print(clientHidden);
7571 pw.print(" willBeHidden="); pw.print(willBeHidden);
7572 pw.print(" reportedVisible="); pw.println(reportedVisible);
7573 if (paused || freezingScreen) {
7574 pw.print(prefix); pw.print("paused="); pw.print(paused);
7575 pw.print(" freezingScreen="); pw.println(freezingScreen);
7576 }
7577 if (numInterestingWindows != 0 || numDrawnWindows != 0
7578 || inPendingTransaction || allDrawn) {
7579 pw.print(prefix); pw.print("numInterestingWindows=");
7580 pw.print(numInterestingWindows);
7581 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7582 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7583 pw.print(" allDrawn="); pw.println(allDrawn);
7584 }
7585 if (animating || animation != null) {
7586 pw.print(prefix); pw.print("animating="); pw.print(animating);
7587 pw.print(" animation="); pw.println(animation);
7588 }
7589 if (animLayerAdjustment != 0) {
7590 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7591 }
7592 if (hasTransformation) {
7593 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7594 pw.print(" transformation="); transformation.printShortString(pw);
7595 pw.println();
7596 }
7597 if (startingData != null || removed || firstWindowDrawn) {
7598 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7599 pw.print(" removed="); pw.print(removed);
7600 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7601 }
7602 if (startingWindow != null || startingView != null
7603 || startingDisplayed || startingMoved) {
7604 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7605 pw.print(" startingView="); pw.print(startingView);
7606 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7607 pw.print(" startingMoved"); pw.println(startingMoved);
7608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 }
7610
7611 @Override
7612 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007613 if (stringName == null) {
7614 StringBuilder sb = new StringBuilder();
7615 sb.append("AppWindowToken{");
7616 sb.append(Integer.toHexString(System.identityHashCode(this)));
7617 sb.append(" token="); sb.append(token); sb.append('}');
7618 stringName = sb.toString();
7619 }
7620 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 }
7622 }
Romain Guy06882f82009-06-10 13:36:04 -07007623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007624 // -------------------------------------------------------------
7625 // DummyAnimation
7626 // -------------------------------------------------------------
7627
7628 // This is an animation that does nothing: it just immediately finishes
7629 // itself every time it is called. It is used as a stub animation in cases
7630 // where we want to synchronize multiple things that may be animating.
7631 static final class DummyAnimation extends Animation {
7632 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7633 return false;
7634 }
7635 }
7636 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 // -------------------------------------------------------------
7639 // Async Handler
7640 // -------------------------------------------------------------
7641
7642 static final class StartingData {
7643 final String pkg;
7644 final int theme;
7645 final CharSequence nonLocalizedLabel;
7646 final int labelRes;
7647 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007649 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7650 int _labelRes, int _icon) {
7651 pkg = _pkg;
7652 theme = _theme;
7653 nonLocalizedLabel = _nonLocalizedLabel;
7654 labelRes = _labelRes;
7655 icon = _icon;
7656 }
7657 }
7658
7659 private final class H extends Handler {
7660 public static final int REPORT_FOCUS_CHANGE = 2;
7661 public static final int REPORT_LOSING_FOCUS = 3;
7662 public static final int ANIMATE = 4;
7663 public static final int ADD_STARTING = 5;
7664 public static final int REMOVE_STARTING = 6;
7665 public static final int FINISHED_STARTING = 7;
7666 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007667 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7668 public static final int HOLD_SCREEN_CHANGED = 12;
7669 public static final int APP_TRANSITION_TIMEOUT = 13;
7670 public static final int PERSIST_ANIMATION_SCALE = 14;
7671 public static final int FORCE_GC = 15;
7672 public static final int ENABLE_SCREEN = 16;
7673 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007674 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07007675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007676 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 public H() {
7679 }
Romain Guy06882f82009-06-10 13:36:04 -07007680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007681 @Override
7682 public void handleMessage(Message msg) {
7683 switch (msg.what) {
7684 case REPORT_FOCUS_CHANGE: {
7685 WindowState lastFocus;
7686 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007688 synchronized(mWindowMap) {
7689 lastFocus = mLastFocus;
7690 newFocus = mCurrentFocus;
7691 if (lastFocus == newFocus) {
7692 // Focus is not changing, so nothing to do.
7693 return;
7694 }
7695 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007696 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007697 // + " to " + newFocus);
7698 if (newFocus != null && lastFocus != null
7699 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007700 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007701 mLosingFocus.add(lastFocus);
7702 lastFocus = null;
7703 }
7704 }
7705
7706 if (lastFocus != newFocus) {
7707 //System.out.println("Changing focus from " + lastFocus
7708 // + " to " + newFocus);
7709 if (newFocus != null) {
7710 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007711 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007712 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7713 } catch (RemoteException e) {
7714 // Ignore if process has died.
7715 }
7716 }
7717
7718 if (lastFocus != null) {
7719 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007720 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007721 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7722 } catch (RemoteException e) {
7723 // Ignore if process has died.
7724 }
7725 }
7726 }
7727 } break;
7728
7729 case REPORT_LOSING_FOCUS: {
7730 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007732 synchronized(mWindowMap) {
7733 losers = mLosingFocus;
7734 mLosingFocus = new ArrayList<WindowState>();
7735 }
7736
7737 final int N = losers.size();
7738 for (int i=0; i<N; i++) {
7739 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007740 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007741 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7742 } catch (RemoteException e) {
7743 // Ignore if process has died.
7744 }
7745 }
7746 } break;
7747
7748 case ANIMATE: {
7749 synchronized(mWindowMap) {
7750 mAnimationPending = false;
7751 performLayoutAndPlaceSurfacesLocked();
7752 }
7753 } break;
7754
7755 case ADD_STARTING: {
7756 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7757 final StartingData sd = wtoken.startingData;
7758
7759 if (sd == null) {
7760 // Animation has been canceled... do nothing.
7761 return;
7762 }
Romain Guy06882f82009-06-10 13:36:04 -07007763
Joe Onorato8a9b2202010-02-26 18:56:32 -08007764 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 View view = null;
7768 try {
7769 view = mPolicy.addStartingWindow(
7770 wtoken.token, sd.pkg,
7771 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7772 sd.icon);
7773 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007774 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 }
7776
7777 if (view != null) {
7778 boolean abort = false;
7779
7780 synchronized(mWindowMap) {
7781 if (wtoken.removed || wtoken.startingData == null) {
7782 // If the window was successfully added, then
7783 // we need to remove it.
7784 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007785 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007786 "Aborted starting " + wtoken
7787 + ": removed=" + wtoken.removed
7788 + " startingData=" + wtoken.startingData);
7789 wtoken.startingWindow = null;
7790 wtoken.startingData = null;
7791 abort = true;
7792 }
7793 } else {
7794 wtoken.startingView = view;
7795 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007796 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007797 "Added starting " + wtoken
7798 + ": startingWindow="
7799 + wtoken.startingWindow + " startingView="
7800 + wtoken.startingView);
7801 }
7802
7803 if (abort) {
7804 try {
7805 mPolicy.removeStartingWindow(wtoken.token, view);
7806 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007807 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007808 }
7809 }
7810 }
7811 } break;
7812
7813 case REMOVE_STARTING: {
7814 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7815 IBinder token = null;
7816 View view = null;
7817 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007818 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007819 + wtoken + ": startingWindow="
7820 + wtoken.startingWindow + " startingView="
7821 + wtoken.startingView);
7822 if (wtoken.startingWindow != null) {
7823 view = wtoken.startingView;
7824 token = wtoken.token;
7825 wtoken.startingData = null;
7826 wtoken.startingView = null;
7827 wtoken.startingWindow = null;
7828 }
7829 }
7830 if (view != null) {
7831 try {
7832 mPolicy.removeStartingWindow(token, view);
7833 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007834 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007835 }
7836 }
7837 } break;
7838
7839 case FINISHED_STARTING: {
7840 IBinder token = null;
7841 View view = null;
7842 while (true) {
7843 synchronized (mWindowMap) {
7844 final int N = mFinishedStarting.size();
7845 if (N <= 0) {
7846 break;
7847 }
7848 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7849
Joe Onorato8a9b2202010-02-26 18:56:32 -08007850 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007851 "Finished starting " + wtoken
7852 + ": startingWindow=" + wtoken.startingWindow
7853 + " startingView=" + wtoken.startingView);
7854
7855 if (wtoken.startingWindow == null) {
7856 continue;
7857 }
7858
7859 view = wtoken.startingView;
7860 token = wtoken.token;
7861 wtoken.startingData = null;
7862 wtoken.startingView = null;
7863 wtoken.startingWindow = null;
7864 }
7865
7866 try {
7867 mPolicy.removeStartingWindow(token, view);
7868 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007869 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 }
7871 }
7872 } break;
7873
7874 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7875 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7876
7877 boolean nowVisible = msg.arg1 != 0;
7878 boolean nowGone = msg.arg2 != 0;
7879
7880 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007881 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007882 TAG, "Reporting visible in " + wtoken
7883 + " visible=" + nowVisible
7884 + " gone=" + nowGone);
7885 if (nowVisible) {
7886 wtoken.appToken.windowsVisible();
7887 } else {
7888 wtoken.appToken.windowsGone();
7889 }
7890 } catch (RemoteException ex) {
7891 }
7892 } break;
Romain Guy06882f82009-06-10 13:36:04 -07007893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 case WINDOW_FREEZE_TIMEOUT: {
7895 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007896 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007897 int i = mWindows.size();
7898 while (i > 0) {
7899 i--;
7900 WindowState w = (WindowState)mWindows.get(i);
7901 if (w.mOrientationChanging) {
7902 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007903 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007904 }
7905 }
7906 performLayoutAndPlaceSurfacesLocked();
7907 }
7908 break;
7909 }
Romain Guy06882f82009-06-10 13:36:04 -07007910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007911 case HOLD_SCREEN_CHANGED: {
7912 Session oldHold;
7913 Session newHold;
7914 synchronized (mWindowMap) {
7915 oldHold = mLastReportedHold;
7916 newHold = (Session)msg.obj;
7917 mLastReportedHold = newHold;
7918 }
Romain Guy06882f82009-06-10 13:36:04 -07007919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007920 if (oldHold != newHold) {
7921 try {
7922 if (oldHold != null) {
7923 mBatteryStats.noteStopWakelock(oldHold.mUid,
7924 "window",
7925 BatteryStats.WAKE_TYPE_WINDOW);
7926 }
7927 if (newHold != null) {
7928 mBatteryStats.noteStartWakelock(newHold.mUid,
7929 "window",
7930 BatteryStats.WAKE_TYPE_WINDOW);
7931 }
7932 } catch (RemoteException e) {
7933 }
7934 }
7935 break;
7936 }
Romain Guy06882f82009-06-10 13:36:04 -07007937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007938 case APP_TRANSITION_TIMEOUT: {
7939 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007940 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007941 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007942 "*** APP TRANSITION TIMEOUT");
7943 mAppTransitionReady = true;
7944 mAppTransitionTimeout = true;
7945 performLayoutAndPlaceSurfacesLocked();
7946 }
7947 }
7948 break;
7949 }
Romain Guy06882f82009-06-10 13:36:04 -07007950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007951 case PERSIST_ANIMATION_SCALE: {
7952 Settings.System.putFloat(mContext.getContentResolver(),
7953 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
7954 Settings.System.putFloat(mContext.getContentResolver(),
7955 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
7956 break;
7957 }
Romain Guy06882f82009-06-10 13:36:04 -07007958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007959 case FORCE_GC: {
7960 synchronized(mWindowMap) {
7961 if (mAnimationPending) {
7962 // If we are animating, don't do the gc now but
7963 // delay a bit so we don't interrupt the animation.
7964 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
7965 2000);
7966 return;
7967 }
7968 // If we are currently rotating the display, it will
7969 // schedule a new message when done.
7970 if (mDisplayFrozen) {
7971 return;
7972 }
7973 mFreezeGcPending = 0;
7974 }
7975 Runtime.getRuntime().gc();
7976 break;
7977 }
Romain Guy06882f82009-06-10 13:36:04 -07007978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 case ENABLE_SCREEN: {
7980 performEnableScreen();
7981 break;
7982 }
Romain Guy06882f82009-06-10 13:36:04 -07007983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007984 case APP_FREEZE_TIMEOUT: {
7985 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007986 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007987 int i = mAppTokens.size();
7988 while (i > 0) {
7989 i--;
7990 AppWindowToken tok = mAppTokens.get(i);
7991 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007992 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007993 unsetAppFreezingScreenLocked(tok, true, true);
7994 }
7995 }
7996 }
7997 break;
7998 }
Romain Guy06882f82009-06-10 13:36:04 -07007999
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008000 case SEND_NEW_CONFIGURATION: {
8001 removeMessages(SEND_NEW_CONFIGURATION);
8002 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008003 break;
8004 }
Romain Guy06882f82009-06-10 13:36:04 -07008005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008006 }
8007 }
8008 }
8009
8010 // -------------------------------------------------------------
8011 // IWindowManager API
8012 // -------------------------------------------------------------
8013
8014 public IWindowSession openSession(IInputMethodClient client,
8015 IInputContext inputContext) {
8016 if (client == null) throw new IllegalArgumentException("null client");
8017 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008018 Session session = new Session(client, inputContext);
8019 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008020 }
8021
8022 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8023 synchronized (mWindowMap) {
8024 // The focus for the client is the window immediately below
8025 // where we would place the input method window.
8026 int idx = findDesiredInputMethodWindowIndexLocked(false);
8027 WindowState imFocus;
8028 if (idx > 0) {
8029 imFocus = (WindowState)mWindows.get(idx-1);
8030 if (imFocus != null) {
8031 if (imFocus.mSession.mClient != null &&
8032 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8033 return true;
8034 }
8035 }
8036 }
8037 }
8038 return false;
8039 }
Romain Guy06882f82009-06-10 13:36:04 -07008040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008041 // -------------------------------------------------------------
8042 // Internals
8043 // -------------------------------------------------------------
8044
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008045 final WindowState windowForClientLocked(Session session, IWindow client,
8046 boolean throwOnError) {
8047 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 }
Romain Guy06882f82009-06-10 13:36:04 -07008049
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008050 final WindowState windowForClientLocked(Session session, IBinder client,
8051 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008052 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008053 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008054 TAG, "Looking up client " + client + ": " + win);
8055 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008056 RuntimeException ex = new IllegalArgumentException(
8057 "Requested window " + client + " does not exist");
8058 if (throwOnError) {
8059 throw ex;
8060 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008061 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 return null;
8063 }
8064 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008065 RuntimeException ex = new IllegalArgumentException(
8066 "Requested window " + client + " is in session " +
8067 win.mSession + ", not " + session);
8068 if (throwOnError) {
8069 throw ex;
8070 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008071 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008072 return null;
8073 }
8074
8075 return win;
8076 }
8077
Dianne Hackborna8f60182009-09-01 19:01:50 -07008078 final void rebuildAppWindowListLocked() {
8079 int NW = mWindows.size();
8080 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008081 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008082 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008083
Dianne Hackborna8f60182009-09-01 19:01:50 -07008084 // First remove all existing app windows.
8085 i=0;
8086 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008087 WindowState w = (WindowState)mWindows.get(i);
8088 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008089 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008090 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008091 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008092 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008093 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008094 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008095 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8096 && lastWallpaper == i-1) {
8097 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008098 }
8099 i++;
8100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008101
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008102 // The wallpaper window(s) typically live at the bottom of the stack,
8103 // so skip them before adding app tokens.
8104 lastWallpaper++;
8105 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008106
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008107 // First add all of the exiting app tokens... these are no longer
8108 // in the main app list, but still have windows shown. We put them
8109 // in the back because now that the animation is over we no longer
8110 // will care about them.
8111 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008112 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008113 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8114 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008115
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008116 // And add in the still active app tokens in Z order.
8117 NT = mAppTokens.size();
8118 for (int j=0; j<NT; j++) {
8119 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008120 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008121
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008122 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008123 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008124 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008125 + " windows but added " + i);
8126 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008127 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008129 private final void assignLayersLocked() {
8130 int N = mWindows.size();
8131 int curBaseLayer = 0;
8132 int curLayer = 0;
8133 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008135 for (i=0; i<N; i++) {
8136 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008137 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8138 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008139 curLayer += WINDOW_LAYER_MULTIPLIER;
8140 w.mLayer = curLayer;
8141 } else {
8142 curBaseLayer = curLayer = w.mBaseLayer;
8143 w.mLayer = curLayer;
8144 }
8145 if (w.mTargetAppToken != null) {
8146 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8147 } else if (w.mAppToken != null) {
8148 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8149 } else {
8150 w.mAnimLayer = w.mLayer;
8151 }
8152 if (w.mIsImWindow) {
8153 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008154 } else if (w.mIsWallpaper) {
8155 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008156 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008157 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008158 + w.mAnimLayer);
8159 //System.out.println(
8160 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8161 }
8162 }
8163
8164 private boolean mInLayout = false;
8165 private final void performLayoutAndPlaceSurfacesLocked() {
8166 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008167 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008168 throw new RuntimeException("Recursive call!");
8169 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008170 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008171 return;
8172 }
8173
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008174 if (mWaitingForConfig) {
8175 // Our configuration has changed (most likely rotation), but we
8176 // don't yet have the complete configuration to report to
8177 // applications. Don't do any window layout until we have it.
8178 return;
8179 }
8180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008181 boolean recoveringMemory = false;
8182 if (mForceRemoves != null) {
8183 recoveringMemory = true;
8184 // Wait a little it for things to settle down, and off we go.
8185 for (int i=0; i<mForceRemoves.size(); i++) {
8186 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008187 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008188 removeWindowInnerLocked(ws.mSession, ws);
8189 }
8190 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008191 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 Object tmp = new Object();
8193 synchronized (tmp) {
8194 try {
8195 tmp.wait(250);
8196 } catch (InterruptedException e) {
8197 }
8198 }
8199 }
Romain Guy06882f82009-06-10 13:36:04 -07008200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008201 mInLayout = true;
8202 try {
8203 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 int i = mPendingRemove.size()-1;
8206 if (i >= 0) {
8207 while (i >= 0) {
8208 WindowState w = mPendingRemove.get(i);
8209 removeWindowInnerLocked(w.mSession, w);
8210 i--;
8211 }
8212 mPendingRemove.clear();
8213
8214 mInLayout = false;
8215 assignLayersLocked();
8216 mLayoutNeeded = true;
8217 performLayoutAndPlaceSurfacesLocked();
8218
8219 } else {
8220 mInLayout = false;
8221 if (mLayoutNeeded) {
8222 requestAnimationLocked(0);
8223 }
8224 }
8225 } catch (RuntimeException e) {
8226 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008227 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008228 }
8229 }
8230
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008231 private final int performLayoutLockedInner() {
8232 if (!mLayoutNeeded) {
8233 return 0;
8234 }
8235
8236 mLayoutNeeded = false;
8237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 final int dw = mDisplay.getWidth();
8239 final int dh = mDisplay.getHeight();
8240
8241 final int N = mWindows.size();
8242 int i;
8243
Joe Onorato8a9b2202010-02-26 18:56:32 -08008244 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008245 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8246
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008247 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008248
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008249 int seq = mLayoutSeq+1;
8250 if (seq < 0) seq = 0;
8251 mLayoutSeq = seq;
8252
8253 // First perform layout of any root windows (not attached
8254 // to another window).
8255 int topAttached = -1;
8256 for (i = N-1; i >= 0; i--) {
8257 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008258
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008259 // Don't do layout of a window if it is not visible, or
8260 // soon won't be visible, to avoid wasting time and funky
8261 // changes while a window is animating away.
8262 final AppWindowToken atoken = win.mAppToken;
8263 final boolean gone = win.mViewVisibility == View.GONE
8264 || !win.mRelayoutCalled
8265 || win.mRootToken.hidden
8266 || (atoken != null && atoken.hiddenRequested)
8267 || win.mAttachedHidden
8268 || win.mExiting || win.mDestroying;
8269
8270 if (!win.mLayoutAttached) {
8271 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8272 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8273 + " mLayoutAttached=" + win.mLayoutAttached);
8274 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8275 + win.mViewVisibility + " mRelayoutCalled="
8276 + win.mRelayoutCalled + " hidden="
8277 + win.mRootToken.hidden + " hiddenRequested="
8278 + (atoken != null && atoken.hiddenRequested)
8279 + " mAttachedHidden=" + win.mAttachedHidden);
8280 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008281
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008282 // If this view is GONE, then skip it -- keep the current
8283 // frame, and let the caller know so they can ignore it
8284 // if they want. (We do the normal layout for INVISIBLE
8285 // windows, since that means "perform layout as normal,
8286 // just don't display").
8287 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008288 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008289 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8290 win.mLayoutSeq = seq;
8291 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8292 + win.mFrame + " mContainingFrame="
8293 + win.mContainingFrame + " mDisplayFrame="
8294 + win.mDisplayFrame);
8295 } else {
8296 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008297 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008299 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008300
8301 // Now perform layout of attached windows, which usually
8302 // depend on the position of the window they are attached to.
8303 // XXX does not deal with windows that are attached to windows
8304 // that are themselves attached.
8305 for (i = topAttached; i >= 0; i--) {
8306 WindowState win = (WindowState) mWindows.get(i);
8307
8308 // If this view is GONE, then skip it -- keep the current
8309 // frame, and let the caller know so they can ignore it
8310 // if they want. (We do the normal layout for INVISIBLE
8311 // windows, since that means "perform layout as normal,
8312 // just don't display").
8313 if (win.mLayoutAttached) {
8314 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8315 + " mHaveFrame=" + win.mHaveFrame
8316 + " mViewVisibility=" + win.mViewVisibility
8317 + " mRelayoutCalled=" + win.mRelayoutCalled);
8318 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8319 || !win.mHaveFrame) {
8320 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8321 win.mLayoutSeq = seq;
8322 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8323 + win.mFrame + " mContainingFrame="
8324 + win.mContainingFrame + " mDisplayFrame="
8325 + win.mDisplayFrame);
8326 }
8327 }
8328 }
Jeff Brown349703e2010-06-22 01:27:15 -07008329
8330 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008331 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008332
8333 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008334 }
Romain Guy06882f82009-06-10 13:36:04 -07008335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336 private final void performLayoutAndPlaceSurfacesLockedInner(
8337 boolean recoveringMemory) {
8338 final long currentTime = SystemClock.uptimeMillis();
8339 final int dw = mDisplay.getWidth();
8340 final int dh = mDisplay.getHeight();
8341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008342 int i;
8343
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008344 if (mFocusMayChange) {
8345 mFocusMayChange = false;
8346 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8347 }
8348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008349 if (mFxSession == null) {
8350 mFxSession = new SurfaceSession();
8351 }
Romain Guy06882f82009-06-10 13:36:04 -07008352
Joe Onorato8a9b2202010-02-26 18:56:32 -08008353 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354
8355 // Initialize state of exiting tokens.
8356 for (i=mExitingTokens.size()-1; i>=0; i--) {
8357 mExitingTokens.get(i).hasVisible = false;
8358 }
8359
8360 // Initialize state of exiting applications.
8361 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8362 mExitingAppTokens.get(i).hasVisible = false;
8363 }
8364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008365 boolean orientationChangeComplete = true;
8366 Session holdScreen = null;
8367 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008368 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008369 boolean focusDisplayed = false;
8370 boolean animating = false;
8371
8372 Surface.openTransaction();
8373 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008374 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008375 int repeats = 0;
8376 int changes = 0;
8377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008378 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008379 repeats++;
8380 if (repeats > 6) {
8381 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8382 mLayoutNeeded = false;
8383 break;
8384 }
8385
8386 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8387 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8388 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8389 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8390 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8391 assignLayersLocked();
8392 mLayoutNeeded = true;
8393 }
8394 }
8395 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8396 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8397 if (updateOrientationFromAppTokensLocked()) {
8398 mLayoutNeeded = true;
8399 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8400 }
8401 }
8402 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8403 mLayoutNeeded = true;
8404 }
8405 }
8406
8407 // FIRST LOOP: Perform a layout, if needed.
8408 if (repeats < 4) {
8409 changes = performLayoutLockedInner();
8410 if (changes != 0) {
8411 continue;
8412 }
8413 } else {
8414 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8415 changes = 0;
8416 }
8417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418 final int transactionSequence = ++mTransactionSequence;
8419
8420 // Update animations of all applications, including those
8421 // associated with exiting/removed apps
8422 boolean tokensAnimating = false;
8423 final int NAT = mAppTokens.size();
8424 for (i=0; i<NAT; i++) {
8425 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8426 tokensAnimating = true;
8427 }
8428 }
8429 final int NEAT = mExitingAppTokens.size();
8430 for (i=0; i<NEAT; i++) {
8431 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8432 tokensAnimating = true;
8433 }
8434 }
8435
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008436 // SECOND LOOP: Execute animations and update visibility of windows.
8437
Joe Onorato8a9b2202010-02-26 18:56:32 -08008438 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008439 + transactionSequence + " tokensAnimating="
8440 + tokensAnimating);
8441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008442 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008443
8444 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008445 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008446 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447
8448 mPolicy.beginAnimationLw(dw, dh);
8449
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008450 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 for (i=N-1; i>=0; i--) {
8453 WindowState w = (WindowState)mWindows.get(i);
8454
8455 final WindowManager.LayoutParams attrs = w.mAttrs;
8456
8457 if (w.mSurface != null) {
8458 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008459 if (w.commitFinishDrawingLocked(currentTime)) {
8460 if ((w.mAttrs.flags
8461 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008462 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008463 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008464 wallpaperMayChange = true;
8465 }
8466 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008467
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008468 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8470 animating = true;
8471 //w.dump(" ");
8472 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008473 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8474 wallpaperMayChange = true;
8475 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008476
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008477 if (mPolicy.doesForceHide(w, attrs)) {
8478 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008479 if (DEBUG_VISIBILITY) Slog.v(TAG,
8480 "Animation done that could impact force hide: "
8481 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008482 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008483 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008484 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8485 forceHiding = true;
8486 }
8487 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8488 boolean changed;
8489 if (forceHiding) {
8490 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008491 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8492 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008493 } else {
8494 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008495 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8496 "Now policy shown: " + w);
8497 if (changed) {
8498 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008499 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008500 // Assume we will need to animate. If
8501 // we don't (because the wallpaper will
8502 // stay with the lock screen), then we will
8503 // clean up later.
8504 Animation a = mPolicy.createForceHideEnterAnimation();
8505 if (a != null) {
8506 w.setAnimation(a);
8507 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008508 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008509 if (mCurrentFocus == null ||
8510 mCurrentFocus.mLayer < w.mLayer) {
8511 // We are showing on to of the current
8512 // focus, so re-evaluate focus to make
8513 // sure it is correct.
8514 mFocusMayChange = true;
8515 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008516 }
8517 }
8518 if (changed && (attrs.flags
8519 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8520 wallpaperMayChange = true;
8521 }
8522 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008524 mPolicy.animatingWindowLw(w, attrs);
8525 }
8526
8527 final AppWindowToken atoken = w.mAppToken;
8528 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8529 if (atoken.lastTransactionSequence != transactionSequence) {
8530 atoken.lastTransactionSequence = transactionSequence;
8531 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8532 atoken.startingDisplayed = false;
8533 }
8534 if ((w.isOnScreen() || w.mAttrs.type
8535 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8536 && !w.mExiting && !w.mDestroying) {
8537 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008538 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008539 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008541 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008542 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008543 + " pv=" + w.mPolicyVisibility
8544 + " dp=" + w.mDrawPending
8545 + " cdp=" + w.mCommitDrawPending
8546 + " ah=" + w.mAttachedHidden
8547 + " th=" + atoken.hiddenRequested
8548 + " a=" + w.mAnimating);
8549 }
8550 }
8551 if (w != atoken.startingWindow) {
8552 if (!atoken.freezingScreen || !w.mAppFreezing) {
8553 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008554 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008555 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008556 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008557 "tokenMayBeDrawn: " + atoken
8558 + " freezingScreen=" + atoken.freezingScreen
8559 + " mAppFreezing=" + w.mAppFreezing);
8560 tokenMayBeDrawn = true;
8561 }
8562 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008563 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008564 atoken.startingDisplayed = true;
8565 }
8566 }
8567 } else if (w.mReadyToShow) {
8568 w.performShowLocked();
8569 }
8570 }
8571
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008572 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573
8574 if (tokenMayBeDrawn) {
8575 // See if any windows have been drawn, so they (and others
8576 // associated with them) can now be shown.
8577 final int NT = mTokenList.size();
8578 for (i=0; i<NT; i++) {
8579 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8580 if (wtoken == null) {
8581 continue;
8582 }
8583 if (wtoken.freezingScreen) {
8584 int numInteresting = wtoken.numInterestingWindows;
8585 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008586 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 "allDrawn: " + wtoken
8588 + " interesting=" + numInteresting
8589 + " drawn=" + wtoken.numDrawnWindows);
8590 wtoken.showAllWindowsLocked();
8591 unsetAppFreezingScreenLocked(wtoken, false, true);
8592 orientationChangeComplete = true;
8593 }
8594 } else if (!wtoken.allDrawn) {
8595 int numInteresting = wtoken.numInterestingWindows;
8596 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008597 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008598 "allDrawn: " + wtoken
8599 + " interesting=" + numInteresting
8600 + " drawn=" + wtoken.numDrawnWindows);
8601 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008602 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008603
8604 // We can now show all of the drawn windows!
8605 if (!mOpeningApps.contains(wtoken)) {
8606 wtoken.showAllWindowsLocked();
8607 }
8608 }
8609 }
8610 }
8611 }
8612
8613 // If we are ready to perform an app transition, check through
8614 // all of the app tokens to be shown and see if they are ready
8615 // to go.
8616 if (mAppTransitionReady) {
8617 int NN = mOpeningApps.size();
8618 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008619 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 "Checking " + NN + " opening apps (frozen="
8621 + mDisplayFrozen + " timeout="
8622 + mAppTransitionTimeout + ")...");
8623 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8624 // If the display isn't frozen, wait to do anything until
8625 // all of the apps are ready. Otherwise just go because
8626 // we'll unfreeze the display when everyone is ready.
8627 for (i=0; i<NN && goodToGo; i++) {
8628 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008629 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 "Check opening app" + wtoken + ": allDrawn="
8631 + wtoken.allDrawn + " startingDisplayed="
8632 + wtoken.startingDisplayed);
8633 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8634 && !wtoken.startingMoved) {
8635 goodToGo = false;
8636 }
8637 }
8638 }
8639 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008640 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 int transit = mNextAppTransition;
8642 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008643 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008645 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008646 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008647 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 mAppTransitionTimeout = false;
8649 mStartingIconInTransition = false;
8650 mSkipAppTransitionAnimation = false;
8651
8652 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8653
Dianne Hackborna8f60182009-09-01 19:01:50 -07008654 // If there are applications waiting to come to the
8655 // top of the stack, now is the time to move their windows.
8656 // (Note that we don't do apps going to the bottom
8657 // here -- we want to keep their windows in the old
8658 // Z-order until the animation completes.)
8659 if (mToTopApps.size() > 0) {
8660 NN = mAppTokens.size();
8661 for (i=0; i<NN; i++) {
8662 AppWindowToken wtoken = mAppTokens.get(i);
8663 if (wtoken.sendingToTop) {
8664 wtoken.sendingToTop = false;
8665 moveAppWindowsLocked(wtoken, NN, false);
8666 }
8667 }
8668 mToTopApps.clear();
8669 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008670
Dianne Hackborn25994b42009-09-04 14:21:19 -07008671 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008672
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008673 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008674 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008675
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008676 // The top-most window will supply the layout params,
8677 // and we will determine it below.
8678 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008679 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008680 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008681
Joe Onorato8a9b2202010-02-26 18:56:32 -08008682 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008683 "New wallpaper target=" + mWallpaperTarget
8684 + ", lower target=" + mLowerWallpaperTarget
8685 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008686 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008687 // Do a first pass through the tokens for two
8688 // things:
8689 // (1) Determine if both the closing and opening
8690 // app token sets are wallpaper targets, in which
8691 // case special animations are needed
8692 // (since the wallpaper needs to stay static
8693 // behind them).
8694 // (2) Find the layout params of the top-most
8695 // application window in the tokens, which is
8696 // what will control the animation theme.
8697 final int NC = mClosingApps.size();
8698 NN = NC + mOpeningApps.size();
8699 for (i=0; i<NN; i++) {
8700 AppWindowToken wtoken;
8701 int mode;
8702 if (i < NC) {
8703 wtoken = mClosingApps.get(i);
8704 mode = 1;
8705 } else {
8706 wtoken = mOpeningApps.get(i-NC);
8707 mode = 2;
8708 }
8709 if (mLowerWallpaperTarget != null) {
8710 if (mLowerWallpaperTarget.mAppToken == wtoken
8711 || mUpperWallpaperTarget.mAppToken == wtoken) {
8712 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008713 }
8714 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008715 if (wtoken.appFullscreen) {
8716 WindowState ws = wtoken.findMainWindow();
8717 if (ws != null) {
8718 // If this is a compatibility mode
8719 // window, we will always use its anim.
8720 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8721 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008722 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008723 bestAnimLayer = Integer.MAX_VALUE;
8724 } else if (ws.mLayer > bestAnimLayer) {
8725 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008726 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008727 bestAnimLayer = ws.mLayer;
8728 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008729 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008730 }
8731 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008732
Dianne Hackborn25994b42009-09-04 14:21:19 -07008733 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008734 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008735 "Wallpaper animation!");
8736 switch (transit) {
8737 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8738 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8739 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8740 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8741 break;
8742 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8743 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8744 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8745 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8746 break;
8747 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008748 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008749 "New transit: " + transit);
8750 } else if (oldWallpaper != null) {
8751 // We are transitioning from an activity with
8752 // a wallpaper to one without.
8753 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008754 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008755 "New transit away from wallpaper: " + transit);
8756 } else if (mWallpaperTarget != null) {
8757 // We are transitioning from an activity without
8758 // a wallpaper to now showing the wallpaper
8759 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008760 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008761 "New transit into wallpaper: " + transit);
8762 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008763
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008764 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8765 mLastEnterAnimToken = animToken;
8766 mLastEnterAnimParams = animLp;
8767 } else if (mLastEnterAnimParams != null) {
8768 animLp = mLastEnterAnimParams;
8769 mLastEnterAnimToken = null;
8770 mLastEnterAnimParams = null;
8771 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008772
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008773 // If all closing windows are obscured, then there is
8774 // no need to do an animation. This is the case, for
8775 // example, when this transition is being done behind
8776 // the lock screen.
8777 if (!mPolicy.allowAppAnimationsLw()) {
8778 animLp = null;
8779 }
8780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008781 NN = mOpeningApps.size();
8782 for (i=0; i<NN; i++) {
8783 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008784 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008785 "Now opening app" + wtoken);
8786 wtoken.reportedVisible = false;
8787 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008788 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008789 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008790 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008791 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 wtoken.showAllWindowsLocked();
8793 }
8794 NN = mClosingApps.size();
8795 for (i=0; i<NN; i++) {
8796 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008797 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008798 "Now closing app" + wtoken);
8799 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008800 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008801 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008802 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008803 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 // Force the allDrawn flag, because we want to start
8805 // this guy's animations regardless of whether it's
8806 // gotten drawn.
8807 wtoken.allDrawn = true;
8808 }
8809
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008810 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008812 mOpeningApps.clear();
8813 mClosingApps.clear();
8814
8815 // This has changed the visibility of windows, so perform
8816 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008817 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008818 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008819 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8820 assignLayersLocked();
8821 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008822 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008823 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008824 }
8825 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008826
Dianne Hackborn16064f92010-03-25 00:47:24 -07008827 int adjResult = 0;
8828
Dianne Hackborna8f60182009-09-01 19:01:50 -07008829 if (!animating && mAppTransitionRunning) {
8830 // We have finished the animation of an app transition. To do
8831 // this, we have delayed a lot of operations like showing and
8832 // hiding apps, moving apps in Z-order, etc. The app token list
8833 // reflects the correct Z-order, but the window list may now
8834 // be out of sync with it. So here we will just rebuild the
8835 // entire app window list. Fun!
8836 mAppTransitionRunning = false;
8837 // Clear information about apps that were moving.
8838 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008839
Dianne Hackborna8f60182009-09-01 19:01:50 -07008840 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008841 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008842 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008843 moveInputMethodWindowsIfNeededLocked(false);
8844 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008845 // Since the window list has been rebuilt, focus might
8846 // have to be recomputed since the actual order of windows
8847 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008848 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008849 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008850
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008851 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008852 // At this point, there was a window with a wallpaper that
8853 // was force hiding other windows behind it, but now it
8854 // is going away. This may be simple -- just animate
8855 // away the wallpaper and its window -- or it may be
8856 // hard -- the wallpaper now needs to be shown behind
8857 // something that was hidden.
8858 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008859 if (mLowerWallpaperTarget != null
8860 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008861 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008862 "wallpaperForceHiding changed with lower="
8863 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008864 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008865 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
8866 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
8867 if (mLowerWallpaperTarget.mAppToken.hidden) {
8868 // The lower target has become hidden before we
8869 // actually started the animation... let's completely
8870 // re-evaluate everything.
8871 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008872 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008873 }
8874 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07008875 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008876 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008877 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008878 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008879 + " NEW: " + mWallpaperTarget
8880 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008881 if (mLowerWallpaperTarget == null) {
8882 // Whoops, we don't need a special wallpaper animation.
8883 // Clear them out.
8884 forceHiding = false;
8885 for (i=N-1; i>=0; i--) {
8886 WindowState w = (WindowState)mWindows.get(i);
8887 if (w.mSurface != null) {
8888 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07008889 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008890 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008891 forceHiding = true;
8892 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8893 if (!w.mAnimating) {
8894 // We set the animation above so it
8895 // is not yet running.
8896 w.clearAnimation();
8897 }
8898 }
8899 }
8900 }
8901 }
8902 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008903
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008904 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008905 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008906 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07008907 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008909
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008910 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008911 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008912 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008913 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008914 assignLayersLocked();
8915 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008916 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008917 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008918 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008920
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008921 if (mFocusMayChange) {
8922 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008923 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008924 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008925 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008926 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008927 }
8928
8929 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008930 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008931 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008932
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008933 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
8934 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008935
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008936 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008937
8938 // THIRD LOOP: Update the surfaces of all windows.
8939
8940 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
8941
8942 boolean obscured = false;
8943 boolean blurring = false;
8944 boolean dimming = false;
8945 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07008946 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008947 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008948
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008949 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008951 for (i=N-1; i>=0; i--) {
8952 WindowState w = (WindowState)mWindows.get(i);
8953
8954 boolean displayed = false;
8955 final WindowManager.LayoutParams attrs = w.mAttrs;
8956 final int attrFlags = attrs.flags;
8957
8958 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08008959 // XXX NOTE: The logic here could be improved. We have
8960 // the decision about whether to resize a window separated
8961 // from whether to hide the surface. This can cause us to
8962 // resize a surface even if we are going to hide it. You
8963 // can see this by (1) holding device in landscape mode on
8964 // home screen; (2) tapping browser icon (device will rotate
8965 // to landscape; (3) tap home. The wallpaper will be resized
8966 // in step 2 but then immediately hidden, causing us to
8967 // have to resize and then redraw it again in step 3. It
8968 // would be nice to figure out how to avoid this, but it is
8969 // difficult because we do need to resize surfaces in some
8970 // cases while they are hidden such as when first showing a
8971 // window.
8972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08008974 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008975 TAG, "Placing surface #" + i + " " + w.mSurface
8976 + ": new=" + w.mShownFrame + ", old="
8977 + w.mLastShownFrame);
8978
8979 boolean resize;
8980 int width, height;
8981 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
8982 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
8983 w.mLastRequestedHeight != w.mRequestedHeight;
8984 // for a scaled surface, we just want to use
8985 // the requested size.
8986 width = w.mRequestedWidth;
8987 height = w.mRequestedHeight;
8988 w.mLastRequestedWidth = width;
8989 w.mLastRequestedHeight = height;
8990 w.mLastShownFrame.set(w.mShownFrame);
8991 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008992 if (SHOW_TRANSACTIONS) logSurface(w,
8993 "POS " + w.mShownFrame.left
8994 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008995 w.mSurfaceX = w.mShownFrame.left;
8996 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
8998 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008999 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009000 if (!recoveringMemory) {
9001 reclaimSomeSurfaceMemoryLocked(w, "position");
9002 }
9003 }
9004 } else {
9005 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9006 width = w.mShownFrame.width();
9007 height = w.mShownFrame.height();
9008 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009009 }
9010
9011 if (resize) {
9012 if (width < 1) width = 1;
9013 if (height < 1) height = 1;
9014 if (w.mSurface != null) {
9015 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009016 if (SHOW_TRANSACTIONS) logSurface(w,
9017 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009018 + w.mShownFrame.top + " SIZE "
9019 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009020 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009021 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009022 w.mSurfaceW = width;
9023 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009024 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009025 w.mSurfaceX = w.mShownFrame.left;
9026 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009027 w.mSurface.setPosition(w.mShownFrame.left,
9028 w.mShownFrame.top);
9029 } catch (RuntimeException e) {
9030 // If something goes wrong with the surface (such
9031 // as running out of memory), don't take down the
9032 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009033 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009034 + "size=(" + width + "x" + height
9035 + "), pos=(" + w.mShownFrame.left
9036 + "," + w.mShownFrame.top + ")", e);
9037 if (!recoveringMemory) {
9038 reclaimSomeSurfaceMemoryLocked(w, "size");
9039 }
9040 }
9041 }
9042 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009043 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009044 w.mContentInsetsChanged =
9045 !w.mLastContentInsets.equals(w.mContentInsets);
9046 w.mVisibleInsetsChanged =
9047 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009048 boolean configChanged =
9049 w.mConfiguration != mCurConfiguration
9050 && (w.mConfiguration == null
9051 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009052 if (DEBUG_CONFIGURATION && configChanged) {
9053 Slog.v(TAG, "Win " + w + " config changed: "
9054 + mCurConfiguration);
9055 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009056 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009057 + ": configChanged=" + configChanged
9058 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009059 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009060 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009061 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009062 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009063 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009064 w.mLastFrame.set(w.mFrame);
9065 w.mLastContentInsets.set(w.mContentInsets);
9066 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009067 // If the screen is currently frozen, then keep
9068 // it frozen until this window draws at its new
9069 // orientation.
9070 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009071 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009072 "Resizing while display frozen: " + w);
9073 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009074 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009075 mWindowsFreezingScreen = true;
9076 // XXX should probably keep timeout from
9077 // when we first froze the display.
9078 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9079 mH.sendMessageDelayed(mH.obtainMessage(
9080 H.WINDOW_FREEZE_TIMEOUT), 2000);
9081 }
9082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009083 // If the orientation is changing, then we need to
9084 // hold off on unfreezing the display until this
9085 // window has been redrawn; to do that, we need
9086 // to go through the process of getting informed
9087 // by the application when it has finished drawing.
9088 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009089 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009090 "Orientation start waiting for draw in "
9091 + w + ", surface " + w.mSurface);
9092 w.mDrawPending = true;
9093 w.mCommitDrawPending = false;
9094 w.mReadyToShow = false;
9095 if (w.mAppToken != null) {
9096 w.mAppToken.allDrawn = false;
9097 }
9098 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009099 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009100 "Resizing window " + w + " to " + w.mFrame);
9101 mResizingWindows.add(w);
9102 } else if (w.mOrientationChanging) {
9103 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009104 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009105 "Orientation not waiting for draw in "
9106 + w + ", surface " + w.mSurface);
9107 w.mOrientationChanging = false;
9108 }
9109 }
9110 }
9111
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009112 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009113 if (!w.mLastHidden) {
9114 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009115 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9116 + w.mRootToken.waitingToShow + " polvis="
9117 + w.mPolicyVisibility + " atthid="
9118 + w.mAttachedHidden + " tokhid="
9119 + w.mRootToken.hidden + " vis="
9120 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009121 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009122 if (SHOW_TRANSACTIONS) logSurface(w,
9123 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009124 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009125 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009126 try {
9127 w.mSurface.hide();
9128 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009129 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009130 }
9131 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009132 mInputMonitor.windowIsBecomingInvisibleLw(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009133 }
9134 // If we are waiting for this window to handle an
9135 // orientation change, well, it is hidden, so
9136 // doesn't really matter. Note that this does
9137 // introduce a potential glitch if the window
9138 // becomes unhidden before it has drawn for the
9139 // new orientation.
9140 if (w.mOrientationChanging) {
9141 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009142 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 "Orientation change skips hidden " + w);
9144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 } else if (w.mLastLayer != w.mAnimLayer
9146 || w.mLastAlpha != w.mShownAlpha
9147 || w.mLastDsDx != w.mDsDx
9148 || w.mLastDtDx != w.mDtDx
9149 || w.mLastDsDy != w.mDsDy
9150 || w.mLastDtDy != w.mDtDy
9151 || w.mLastHScale != w.mHScale
9152 || w.mLastVScale != w.mVScale
9153 || w.mLastHidden) {
9154 displayed = true;
9155 w.mLastAlpha = w.mShownAlpha;
9156 w.mLastLayer = w.mAnimLayer;
9157 w.mLastDsDx = w.mDsDx;
9158 w.mLastDtDx = w.mDtDx;
9159 w.mLastDsDy = w.mDsDy;
9160 w.mLastDtDy = w.mDtDy;
9161 w.mLastHScale = w.mHScale;
9162 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009163 if (SHOW_TRANSACTIONS) logSurface(w,
9164 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009165 + " matrix=[" + (w.mDsDx*w.mHScale)
9166 + "," + (w.mDtDx*w.mVScale)
9167 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009168 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009169 if (w.mSurface != null) {
9170 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009171 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009172 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009173 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 w.mSurface.setLayer(w.mAnimLayer);
9175 w.mSurface.setMatrix(
9176 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9177 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9178 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009179 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009180 if (!recoveringMemory) {
9181 reclaimSomeSurfaceMemoryLocked(w, "update");
9182 }
9183 }
9184 }
9185
9186 if (w.mLastHidden && !w.mDrawPending
9187 && !w.mCommitDrawPending
9188 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009189 if (SHOW_TRANSACTIONS) logSurface(w,
9190 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009191 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009192 + " during relayout");
9193 if (showSurfaceRobustlyLocked(w)) {
9194 w.mHasDrawn = true;
9195 w.mLastHidden = false;
9196 } else {
9197 w.mOrientationChanging = false;
9198 }
9199 }
9200 if (w.mSurface != null) {
9201 w.mToken.hasVisible = true;
9202 }
9203 } else {
9204 displayed = true;
9205 }
9206
9207 if (displayed) {
9208 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009209 if (attrs.width == LayoutParams.MATCH_PARENT
9210 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 covered = true;
9212 }
9213 }
9214 if (w.mOrientationChanging) {
9215 if (w.mDrawPending || w.mCommitDrawPending) {
9216 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009217 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 "Orientation continue waiting for draw in " + w);
9219 } else {
9220 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009221 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 "Orientation change complete in " + w);
9223 }
9224 }
9225 w.mToken.hasVisible = true;
9226 }
9227 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009228 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009229 "Orientation change skips hidden " + w);
9230 w.mOrientationChanging = false;
9231 }
9232
9233 final boolean canBeSeen = w.isDisplayedLw();
9234
9235 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9236 focusDisplayed = true;
9237 }
9238
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009239 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009241 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009242 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009243 if (w.mSurface != null) {
9244 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9245 holdScreen = w.mSession;
9246 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009247 if (!syswin && w.mAttrs.screenBrightness >= 0
9248 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 screenBrightness = w.mAttrs.screenBrightness;
9250 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009251 if (!syswin && w.mAttrs.buttonBrightness >= 0
9252 && buttonBrightness < 0) {
9253 buttonBrightness = w.mAttrs.buttonBrightness;
9254 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009255 if (canBeSeen
9256 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9257 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9258 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009259 syswin = true;
9260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009261 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009262
Dianne Hackborn25994b42009-09-04 14:21:19 -07009263 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9264 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009265 // This window completely covers everything behind it,
9266 // so we want to leave all of them as unblurred (for
9267 // performance reasons).
9268 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009269 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009270 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009271 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009272 obscured = true;
9273 if (mBackgroundFillerSurface == null) {
9274 try {
9275 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009276 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009277 0, dw, dh,
9278 PixelFormat.OPAQUE,
9279 Surface.FX_SURFACE_NORMAL);
9280 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009281 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009282 }
9283 }
9284 try {
9285 mBackgroundFillerSurface.setPosition(0, 0);
9286 mBackgroundFillerSurface.setSize(dw, dh);
9287 // Using the same layer as Dim because they will never be shown at the
9288 // same time.
9289 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9290 mBackgroundFillerSurface.show();
9291 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009292 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009293 }
9294 backgroundFillerShown = true;
9295 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009296 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009297 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009298 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009299 + ": blurring=" + blurring
9300 + " obscured=" + obscured
9301 + " displayed=" + displayed);
9302 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9303 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009304 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009305 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009306 if (mDimAnimator == null) {
9307 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009308 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009309 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009310 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 }
9313 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9314 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009315 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009316 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009317 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009318 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009319 + mBlurSurface + ": CREATE");
9320 try {
Romain Guy06882f82009-06-10 13:36:04 -07009321 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009322 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323 -1, 16, 16,
9324 PixelFormat.OPAQUE,
9325 Surface.FX_SURFACE_BLUR);
9326 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009327 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009328 }
9329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009330 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009331 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9332 + mBlurSurface + ": pos=(0,0) (" +
9333 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009334 mBlurSurface.setPosition(0, 0);
9335 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009336 mBlurSurface.setLayer(w.mAnimLayer-2);
9337 if (!mBlurShown) {
9338 try {
9339 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9340 + mBlurSurface + ": SHOW");
9341 mBlurSurface.show();
9342 } catch (RuntimeException e) {
9343 Slog.w(TAG, "Failure showing blur surface", e);
9344 }
9345 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009346 }
9347 }
9348 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009349 }
9350 }
9351 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009352
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009353 if (obscuredChanged && mWallpaperTarget == w) {
9354 // This is the wallpaper target and its obscured state
9355 // changed... make sure the current wallaper's visibility
9356 // has been updated accordingly.
9357 updateWallpaperVisibilityLocked();
9358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009359 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009360
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009361 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9362 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009363 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009364 try {
9365 mBackgroundFillerSurface.hide();
9366 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009367 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009368 }
9369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009370
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009371 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009372 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9373 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009374 }
Romain Guy06882f82009-06-10 13:36:04 -07009375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009376 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009377 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009378 + ": HIDE");
9379 try {
9380 mBlurSurface.hide();
9381 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009382 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 }
9384 mBlurShown = false;
9385 }
9386
Joe Onorato8a9b2202010-02-26 18:56:32 -08009387 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009388 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009389 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009390 }
9391
9392 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009393
Joe Onorato8a9b2202010-02-26 18:56:32 -08009394 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009395 "With display frozen, orientationChangeComplete="
9396 + orientationChangeComplete);
9397 if (orientationChangeComplete) {
9398 if (mWindowsFreezingScreen) {
9399 mWindowsFreezingScreen = false;
9400 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9401 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009402 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009403 }
Romain Guy06882f82009-06-10 13:36:04 -07009404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009405 i = mResizingWindows.size();
9406 if (i > 0) {
9407 do {
9408 i--;
9409 WindowState win = mResizingWindows.get(i);
9410 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009411 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9412 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009413 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009414 boolean configChanged =
9415 win.mConfiguration != mCurConfiguration
9416 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009417 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9418 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9419 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009420 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009421 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009422 + " / " + mCurConfiguration + " / 0x"
9423 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009424 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009425 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 win.mClient.resized(win.mFrame.width(),
9427 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009428 win.mLastVisibleInsets, win.mDrawPending,
9429 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009430 win.mContentInsetsChanged = false;
9431 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009432 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009433 } catch (RemoteException e) {
9434 win.mOrientationChanging = false;
9435 }
9436 } while (i > 0);
9437 mResizingWindows.clear();
9438 }
Romain Guy06882f82009-06-10 13:36:04 -07009439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009440 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009441 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442 i = mDestroySurface.size();
9443 if (i > 0) {
9444 do {
9445 i--;
9446 WindowState win = mDestroySurface.get(i);
9447 win.mDestroying = false;
9448 if (mInputMethodWindow == win) {
9449 mInputMethodWindow = null;
9450 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009451 if (win == mWallpaperTarget) {
9452 wallpaperDestroyed = true;
9453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009454 win.destroySurfaceLocked();
9455 } while (i > 0);
9456 mDestroySurface.clear();
9457 }
9458
9459 // Time to remove any exiting tokens?
9460 for (i=mExitingTokens.size()-1; i>=0; i--) {
9461 WindowToken token = mExitingTokens.get(i);
9462 if (!token.hasVisible) {
9463 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009464 if (token.windowType == TYPE_WALLPAPER) {
9465 mWallpaperTokens.remove(token);
9466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009467 }
9468 }
9469
9470 // Time to remove any exiting applications?
9471 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9472 AppWindowToken token = mExitingAppTokens.get(i);
9473 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009474 // Make sure there is no animation running on this token,
9475 // so any windows associated with it will be removed as
9476 // soon as their animations are complete
9477 token.animation = null;
9478 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009479 mAppTokens.remove(token);
9480 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009481 if (mLastEnterAnimToken == token) {
9482 mLastEnterAnimToken = null;
9483 mLastEnterAnimParams = null;
9484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 }
9486 }
9487
Dianne Hackborna8f60182009-09-01 19:01:50 -07009488 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009489
Dianne Hackborna8f60182009-09-01 19:01:50 -07009490 if (!animating && mAppTransitionRunning) {
9491 // We have finished the animation of an app transition. To do
9492 // this, we have delayed a lot of operations like showing and
9493 // hiding apps, moving apps in Z-order, etc. The app token list
9494 // reflects the correct Z-order, but the window list may now
9495 // be out of sync with it. So here we will just rebuild the
9496 // entire app window list. Fun!
9497 mAppTransitionRunning = false;
9498 needRelayout = true;
9499 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009500 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009501 // Clear information about apps that were moving.
9502 mToBottomApps.clear();
9503 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 if (focusDisplayed) {
9506 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9507 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009508 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009509 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009510 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009511 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009512 requestAnimationLocked(0);
9513 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9515 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009516
9517 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9518 + " holdScreen=" + holdScreen);
9519 if (!mDisplayFrozen) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07009520 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009521 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9522 mPowerManager.setScreenBrightnessOverride(-1);
9523 } else {
9524 mPowerManager.setScreenBrightnessOverride((int)
9525 (screenBrightness * Power.BRIGHTNESS_ON));
9526 }
9527 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9528 mPowerManager.setButtonBrightnessOverride(-1);
9529 } else {
9530 mPowerManager.setButtonBrightnessOverride((int)
9531 (buttonBrightness * Power.BRIGHTNESS_ON));
9532 }
9533 if (holdScreen != mHoldingScreenOn) {
9534 mHoldingScreenOn = holdScreen;
9535 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9536 mH.sendMessage(m);
9537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009538 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009539
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009540 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009541 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009542 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9543 LocalPowerManager.BUTTON_EVENT, true);
9544 mTurnOnScreen = false;
9545 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009546
9547 // Check to see if we are now in a state where the screen should
9548 // be enabled, because the window obscured flags have changed.
9549 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009550 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07009551
9552 /**
9553 * Must be called with the main window manager lock held.
9554 */
9555 void setHoldScreenLocked(boolean holding) {
9556 boolean state = mHoldingScreenWakeLock.isHeld();
9557 if (holding != state) {
9558 if (holding) {
9559 mHoldingScreenWakeLock.acquire();
9560 } else {
9561 mPolicy.screenOnStoppedLw();
9562 mHoldingScreenWakeLock.release();
9563 }
9564 }
9565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009566
9567 void requestAnimationLocked(long delay) {
9568 if (!mAnimationPending) {
9569 mAnimationPending = true;
9570 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9571 }
9572 }
Romain Guy06882f82009-06-10 13:36:04 -07009573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009574 /**
9575 * Have the surface flinger show a surface, robustly dealing with
9576 * error conditions. In particular, if there is not enough memory
9577 * to show the surface, then we will try to get rid of other surfaces
9578 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009579 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009580 * @return Returns true if the surface was successfully shown.
9581 */
9582 boolean showSurfaceRobustlyLocked(WindowState win) {
9583 try {
9584 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009585 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009587 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009588 if (DEBUG_VISIBILITY) Slog.v(TAG,
9589 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009590 win.mTurnOnScreen = false;
9591 mTurnOnScreen = true;
9592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 }
9594 return true;
9595 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009596 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009597 }
Romain Guy06882f82009-06-10 13:36:04 -07009598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009599 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009601 return false;
9602 }
Romain Guy06882f82009-06-10 13:36:04 -07009603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009604 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9605 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009606
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009607 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009608 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009610 if (mForceRemoves == null) {
9611 mForceRemoves = new ArrayList<WindowState>();
9612 }
Romain Guy06882f82009-06-10 13:36:04 -07009613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009614 long callingIdentity = Binder.clearCallingIdentity();
9615 try {
9616 // There was some problem... first, do a sanity check of the
9617 // window list to make sure we haven't left any dangling surfaces
9618 // around.
9619 int N = mWindows.size();
9620 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009621 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009622 for (int i=0; i<N; i++) {
9623 WindowState ws = (WindowState)mWindows.get(i);
9624 if (ws.mSurface != null) {
9625 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009626 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009627 + ws + " surface=" + ws.mSurface
9628 + " token=" + win.mToken
9629 + " pid=" + ws.mSession.mPid
9630 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009631 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009632 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633 ws.mSurface = null;
9634 mForceRemoves.add(ws);
9635 i--;
9636 N--;
9637 leakedSurface = true;
9638 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009639 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009640 + ws + " surface=" + ws.mSurface
9641 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009642 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009643 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009644 ws.mSurface = null;
9645 leakedSurface = true;
9646 }
9647 }
9648 }
Romain Guy06882f82009-06-10 13:36:04 -07009649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009650 boolean killedApps = false;
9651 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009652 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009653 SparseIntArray pidCandidates = new SparseIntArray();
9654 for (int i=0; i<N; i++) {
9655 WindowState ws = (WindowState)mWindows.get(i);
9656 if (ws.mSurface != null) {
9657 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9658 }
9659 }
9660 if (pidCandidates.size() > 0) {
9661 int[] pids = new int[pidCandidates.size()];
9662 for (int i=0; i<pids.length; i++) {
9663 pids[i] = pidCandidates.keyAt(i);
9664 }
9665 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009666 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009667 killedApps = true;
9668 }
9669 } catch (RemoteException e) {
9670 }
9671 }
9672 }
Romain Guy06882f82009-06-10 13:36:04 -07009673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009674 if (leakedSurface || killedApps) {
9675 // We managed to reclaim some memory, so get rid of the trouble
9676 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009677 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009678 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009679 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009680 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009681 win.mSurface = null;
9682 }
Romain Guy06882f82009-06-10 13:36:04 -07009683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009684 try {
9685 win.mClient.dispatchGetNewSurface();
9686 } catch (RemoteException e) {
9687 }
9688 }
9689 } finally {
9690 Binder.restoreCallingIdentity(callingIdentity);
9691 }
9692 }
Romain Guy06882f82009-06-10 13:36:04 -07009693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009694 private boolean updateFocusedWindowLocked(int mode) {
9695 WindowState newFocus = computeFocusedWindowLocked();
9696 if (mCurrentFocus != newFocus) {
9697 // This check makes sure that we don't already have the focus
9698 // change message pending.
9699 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9700 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009701 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009702 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9703 final WindowState oldFocus = mCurrentFocus;
9704 mCurrentFocus = newFocus;
9705 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009707 final WindowState imWindow = mInputMethodWindow;
9708 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009709 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009711 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9712 mLayoutNeeded = true;
9713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009714 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9715 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009716 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9717 // Client will do the layout, but we need to assign layers
9718 // for handleNewWindowLocked() below.
9719 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009720 }
9721 }
Jeff Brown349703e2010-06-22 01:27:15 -07009722
9723 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9724 // If we defer assigning layers, then the caller is responsible for
9725 // doing this part.
9726 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009727 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 return true;
9729 }
9730 return false;
9731 }
Jeff Brown349703e2010-06-22 01:27:15 -07009732
9733 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009734 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009735 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009736
9737 private WindowState computeFocusedWindowLocked() {
9738 WindowState result = null;
9739 WindowState win;
9740
9741 int i = mWindows.size() - 1;
9742 int nextAppIndex = mAppTokens.size()-1;
9743 WindowToken nextApp = nextAppIndex >= 0
9744 ? mAppTokens.get(nextAppIndex) : null;
9745
9746 while (i >= 0) {
9747 win = (WindowState)mWindows.get(i);
9748
Joe Onorato8a9b2202010-02-26 18:56:32 -08009749 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009750 TAG, "Looking for focus: " + i
9751 + " = " + win
9752 + ", flags=" + win.mAttrs.flags
9753 + ", canReceive=" + win.canReceiveKeys());
9754
9755 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009757 // If this window's application has been removed, just skip it.
9758 if (thisApp != null && thisApp.removed) {
9759 i--;
9760 continue;
9761 }
Romain Guy06882f82009-06-10 13:36:04 -07009762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009763 // If there is a focused app, don't allow focus to go to any
9764 // windows below it. If this is an application window, step
9765 // through the app tokens until we find its app.
9766 if (thisApp != null && nextApp != null && thisApp != nextApp
9767 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9768 int origAppIndex = nextAppIndex;
9769 while (nextAppIndex > 0) {
9770 if (nextApp == mFocusedApp) {
9771 // Whoops, we are below the focused app... no focus
9772 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009773 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009774 TAG, "Reached focused app: " + mFocusedApp);
9775 return null;
9776 }
9777 nextAppIndex--;
9778 nextApp = mAppTokens.get(nextAppIndex);
9779 if (nextApp == thisApp) {
9780 break;
9781 }
9782 }
9783 if (thisApp != nextApp) {
9784 // Uh oh, the app token doesn't exist! This shouldn't
9785 // happen, but if it does we can get totally hosed...
9786 // so restart at the original app.
9787 nextAppIndex = origAppIndex;
9788 nextApp = mAppTokens.get(nextAppIndex);
9789 }
9790 }
9791
9792 // Dispatch to this window if it is wants key events.
9793 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009794 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 TAG, "Found focus @ " + i + " = " + win);
9796 result = win;
9797 break;
9798 }
9799
9800 i--;
9801 }
9802
9803 return result;
9804 }
9805
9806 private void startFreezingDisplayLocked() {
9807 if (mDisplayFrozen) {
9808 return;
9809 }
Romain Guy06882f82009-06-10 13:36:04 -07009810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009811 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009814 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009815 if (mFreezeGcPending != 0) {
9816 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009817 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 mH.removeMessages(H.FORCE_GC);
9819 Runtime.getRuntime().gc();
9820 mFreezeGcPending = now;
9821 }
9822 } else {
9823 mFreezeGcPending = now;
9824 }
Romain Guy06882f82009-06-10 13:36:04 -07009825
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009826 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
9827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009828 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009829
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009830 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009831
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009832 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9833 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009834 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009835 mAppTransitionReady = true;
9836 }
Romain Guy06882f82009-06-10 13:36:04 -07009837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009838 if (PROFILE_ORIENTATION) {
9839 File file = new File("/data/system/frozen");
9840 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9841 }
9842 Surface.freezeDisplay(0);
9843 }
Romain Guy06882f82009-06-10 13:36:04 -07009844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009845 private void stopFreezingDisplayLocked() {
9846 if (!mDisplayFrozen) {
9847 return;
9848 }
Romain Guy06882f82009-06-10 13:36:04 -07009849
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009850 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9851 return;
9852 }
9853
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009854 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
9855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009856 mDisplayFrozen = false;
9857 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9858 if (PROFILE_ORIENTATION) {
9859 Debug.stopMethodTracing();
9860 }
9861 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009862
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009863 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009864
Christopher Tateb696aee2010-04-02 19:08:30 -07009865 // While the display is frozen we don't re-compute the orientation
9866 // to avoid inconsistent states. However, something interesting
9867 // could have actually changed during that time so re-evaluate it
9868 // now to catch that.
9869 if (updateOrientationFromAppTokensLocked()) {
9870 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9871 }
9872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009873 // A little kludge: a lot could have happened while the
9874 // display was frozen, so now that we are coming back we
9875 // do a gc so that any remote references the system
9876 // processes holds on others can be released if they are
9877 // no longer needed.
9878 mH.removeMessages(H.FORCE_GC);
9879 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9880 2000);
Romain Guy06882f82009-06-10 13:36:04 -07009881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 mScreenFrozenLock.release();
9883 }
Romain Guy06882f82009-06-10 13:36:04 -07009884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 @Override
9886 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
9887 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
9888 != PackageManager.PERMISSION_GRANTED) {
9889 pw.println("Permission Denial: can't dump WindowManager from from pid="
9890 + Binder.getCallingPid()
9891 + ", uid=" + Binder.getCallingUid());
9892 return;
9893 }
Romain Guy06882f82009-06-10 13:36:04 -07009894
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009895 pw.println("Input Dispatcher State:");
9896 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -08009897 pw.println(" ");
9898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 synchronized(mWindowMap) {
9900 pw.println("Current Window Manager state:");
9901 for (int i=mWindows.size()-1; i>=0; i--) {
9902 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009903 pw.print(" Window #"); pw.print(i); pw.print(' ');
9904 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 w.dump(pw, " ");
9906 }
9907 if (mInputMethodDialogs.size() > 0) {
9908 pw.println(" ");
9909 pw.println(" Input method dialogs:");
9910 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
9911 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009912 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009913 }
9914 }
9915 if (mPendingRemove.size() > 0) {
9916 pw.println(" ");
9917 pw.println(" Remove pending for:");
9918 for (int i=mPendingRemove.size()-1; i>=0; i--) {
9919 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009920 pw.print(" Remove #"); pw.print(i); pw.print(' ');
9921 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 w.dump(pw, " ");
9923 }
9924 }
9925 if (mForceRemoves != null && mForceRemoves.size() > 0) {
9926 pw.println(" ");
9927 pw.println(" Windows force removing:");
9928 for (int i=mForceRemoves.size()-1; i>=0; i--) {
9929 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009930 pw.print(" Removing #"); pw.print(i); pw.print(' ');
9931 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009932 w.dump(pw, " ");
9933 }
9934 }
9935 if (mDestroySurface.size() > 0) {
9936 pw.println(" ");
9937 pw.println(" Windows waiting to destroy their surface:");
9938 for (int i=mDestroySurface.size()-1; i>=0; i--) {
9939 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009940 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
9941 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009942 w.dump(pw, " ");
9943 }
9944 }
9945 if (mLosingFocus.size() > 0) {
9946 pw.println(" ");
9947 pw.println(" Windows losing focus:");
9948 for (int i=mLosingFocus.size()-1; i>=0; i--) {
9949 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009950 pw.print(" Losing #"); pw.print(i); pw.print(' ');
9951 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009952 w.dump(pw, " ");
9953 }
9954 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009955 if (mResizingWindows.size() > 0) {
9956 pw.println(" ");
9957 pw.println(" Windows waiting to resize:");
9958 for (int i=mResizingWindows.size()-1; i>=0; i--) {
9959 WindowState w = mResizingWindows.get(i);
9960 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
9961 pw.print(w); pw.println(":");
9962 w.dump(pw, " ");
9963 }
9964 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009965 if (mSessions.size() > 0) {
9966 pw.println(" ");
9967 pw.println(" All active sessions:");
9968 Iterator<Session> it = mSessions.iterator();
9969 while (it.hasNext()) {
9970 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009971 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009972 s.dump(pw, " ");
9973 }
9974 }
9975 if (mTokenMap.size() > 0) {
9976 pw.println(" ");
9977 pw.println(" All tokens:");
9978 Iterator<WindowToken> it = mTokenMap.values().iterator();
9979 while (it.hasNext()) {
9980 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009981 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009982 token.dump(pw, " ");
9983 }
9984 }
9985 if (mTokenList.size() > 0) {
9986 pw.println(" ");
9987 pw.println(" Window token list:");
9988 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009989 pw.print(" #"); pw.print(i); pw.print(": ");
9990 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009991 }
9992 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009993 if (mWallpaperTokens.size() > 0) {
9994 pw.println(" ");
9995 pw.println(" Wallpaper tokens:");
9996 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
9997 WindowToken token = mWallpaperTokens.get(i);
9998 pw.print(" Wallpaper #"); pw.print(i);
9999 pw.print(' '); pw.print(token); pw.println(':');
10000 token.dump(pw, " ");
10001 }
10002 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 if (mAppTokens.size() > 0) {
10004 pw.println(" ");
10005 pw.println(" Application tokens in Z order:");
10006 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010007 pw.print(" App #"); pw.print(i); pw.print(": ");
10008 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010009 }
10010 }
10011 if (mFinishedStarting.size() > 0) {
10012 pw.println(" ");
10013 pw.println(" Finishing start of application tokens:");
10014 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10015 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010016 pw.print(" Finished Starting #"); pw.print(i);
10017 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 token.dump(pw, " ");
10019 }
10020 }
10021 if (mExitingTokens.size() > 0) {
10022 pw.println(" ");
10023 pw.println(" Exiting tokens:");
10024 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10025 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010026 pw.print(" Exiting #"); pw.print(i);
10027 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010028 token.dump(pw, " ");
10029 }
10030 }
10031 if (mExitingAppTokens.size() > 0) {
10032 pw.println(" ");
10033 pw.println(" Exiting application tokens:");
10034 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10035 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010036 pw.print(" Exiting App #"); pw.print(i);
10037 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010038 token.dump(pw, " ");
10039 }
10040 }
10041 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010042 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10043 pw.print(" mLastFocus="); pw.println(mLastFocus);
10044 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10045 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10046 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010047 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010048 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10049 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10050 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10051 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010052 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10053 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10054 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010055 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10056 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10057 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10058 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010059 if (mDimAnimator != null) {
10060 mDimAnimator.printTo(pw);
10061 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010062 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010063 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010064 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010065 pw.print(mInputMethodAnimLayerAdjustment);
10066 pw.print(" mWallpaperAnimLayerAdjustment=");
10067 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010068 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10069 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010070 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10071 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010072 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10073 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010074 pw.print(" mRotation="); pw.print(mRotation);
10075 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10076 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10077 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10078 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10079 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10080 pw.print(" mNextAppTransition=0x");
10081 pw.print(Integer.toHexString(mNextAppTransition));
10082 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010083 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010084 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010085 if (mNextAppTransitionPackage != null) {
10086 pw.print(" mNextAppTransitionPackage=");
10087 pw.print(mNextAppTransitionPackage);
10088 pw.print(", mNextAppTransitionEnter=0x");
10089 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10090 pw.print(", mNextAppTransitionExit=0x");
10091 pw.print(Integer.toHexString(mNextAppTransitionExit));
10092 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010093 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10094 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010095 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10096 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10097 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10098 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010099 if (mOpeningApps.size() > 0) {
10100 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10101 }
10102 if (mClosingApps.size() > 0) {
10103 pw.print(" mClosingApps="); pw.println(mClosingApps);
10104 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010105 if (mToTopApps.size() > 0) {
10106 pw.print(" mToTopApps="); pw.println(mToTopApps);
10107 }
10108 if (mToBottomApps.size() > 0) {
10109 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10110 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010111 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10112 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010113 }
10114 }
10115
Jeff Brown349703e2010-06-22 01:27:15 -070010116 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 public void monitor() {
10118 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010119 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010120 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010121
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010122 /**
10123 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010124 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010125 */
10126 private static class DimAnimator {
10127 Surface mDimSurface;
10128 boolean mDimShown = false;
10129 float mDimCurrentAlpha;
10130 float mDimTargetAlpha;
10131 float mDimDeltaPerMs;
10132 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010133
10134 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010135
10136 DimAnimator (SurfaceSession session) {
10137 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010138 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010139 + mDimSurface + ": CREATE");
10140 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010141 mDimSurface = new Surface(session, 0,
10142 "DimSurface",
10143 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010144 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010145 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010146 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010147 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010148 }
10149 }
10150 }
10151
10152 /**
10153 * Show the dim surface.
10154 */
10155 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010156 if (!mDimShown) {
10157 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10158 dw + "x" + dh + ")");
10159 mDimShown = true;
10160 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010161 mLastDimWidth = dw;
10162 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010163 mDimSurface.setPosition(0, 0);
10164 mDimSurface.setSize(dw, dh);
10165 mDimSurface.show();
10166 } catch (RuntimeException e) {
10167 Slog.w(TAG, "Failure showing dim surface", e);
10168 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010169 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10170 mLastDimWidth = dw;
10171 mLastDimHeight = dh;
10172 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010173 }
10174 }
10175
10176 /**
10177 * Set's the dim surface's layer and update dim parameters that will be used in
10178 * {@link updateSurface} after all windows are examined.
10179 */
10180 void updateParameters(WindowState w, long currentTime) {
10181 mDimSurface.setLayer(w.mAnimLayer-1);
10182
10183 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010184 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010185 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010186 if (mDimTargetAlpha != target) {
10187 // If the desired dim level has changed, then
10188 // start an animation to it.
10189 mLastDimAnimTime = currentTime;
10190 long duration = (w.mAnimating && w.mAnimation != null)
10191 ? w.mAnimation.computeDurationHint()
10192 : DEFAULT_DIM_DURATION;
10193 if (target > mDimTargetAlpha) {
10194 // This is happening behind the activity UI,
10195 // so we can make it run a little longer to
10196 // give a stronger impression without disrupting
10197 // the user.
10198 duration *= DIM_DURATION_MULTIPLIER;
10199 }
10200 if (duration < 1) {
10201 // Don't divide by zero
10202 duration = 1;
10203 }
10204 mDimTargetAlpha = target;
10205 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10206 }
10207 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010208
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010209 /**
10210 * Updating the surface's alpha. Returns true if the animation continues, or returns
10211 * false when the animation is finished and the dim surface is hidden.
10212 */
10213 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10214 if (!dimming) {
10215 if (mDimTargetAlpha != 0) {
10216 mLastDimAnimTime = currentTime;
10217 mDimTargetAlpha = 0;
10218 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10219 }
10220 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010221
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010222 boolean animating = false;
10223 if (mLastDimAnimTime != 0) {
10224 mDimCurrentAlpha += mDimDeltaPerMs
10225 * (currentTime-mLastDimAnimTime);
10226 boolean more = true;
10227 if (displayFrozen) {
10228 // If the display is frozen, there is no reason to animate.
10229 more = false;
10230 } else if (mDimDeltaPerMs > 0) {
10231 if (mDimCurrentAlpha > mDimTargetAlpha) {
10232 more = false;
10233 }
10234 } else if (mDimDeltaPerMs < 0) {
10235 if (mDimCurrentAlpha < mDimTargetAlpha) {
10236 more = false;
10237 }
10238 } else {
10239 more = false;
10240 }
10241
10242 // Do we need to continue animating?
10243 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010244 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010245 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10246 mLastDimAnimTime = currentTime;
10247 mDimSurface.setAlpha(mDimCurrentAlpha);
10248 animating = true;
10249 } else {
10250 mDimCurrentAlpha = mDimTargetAlpha;
10251 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010252 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010253 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10254 mDimSurface.setAlpha(mDimCurrentAlpha);
10255 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010256 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010257 + ": HIDE");
10258 try {
10259 mDimSurface.hide();
10260 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010261 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010262 }
10263 mDimShown = false;
10264 }
10265 }
10266 }
10267 return animating;
10268 }
10269
10270 public void printTo(PrintWriter pw) {
10271 pw.print(" mDimShown="); pw.print(mDimShown);
10272 pw.print(" current="); pw.print(mDimCurrentAlpha);
10273 pw.print(" target="); pw.print(mDimTargetAlpha);
10274 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10275 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10276 }
10277 }
10278
10279 /**
10280 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10281 * This is used for opening/closing transition for apps in compatible mode.
10282 */
10283 private static class FadeInOutAnimation extends Animation {
10284 int mWidth;
10285 boolean mFadeIn;
10286
10287 public FadeInOutAnimation(boolean fadeIn) {
10288 setInterpolator(new AccelerateInterpolator());
10289 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10290 mFadeIn = fadeIn;
10291 }
10292
10293 @Override
10294 protected void applyTransformation(float interpolatedTime, Transformation t) {
10295 float x = interpolatedTime;
10296 if (!mFadeIn) {
10297 x = 1.0f - x; // reverse the interpolation for fade out
10298 }
10299 if (x < 0.5) {
10300 // move the window out of the screen.
10301 t.getMatrix().setTranslate(mWidth, 0);
10302 } else {
10303 t.getMatrix().setTranslate(0, 0);// show
10304 t.setAlpha((x - 0.5f) * 2);
10305 }
10306 }
10307
10308 @Override
10309 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10310 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10311 mWidth = width;
10312 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010313
10314 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010315 public int getZAdjustment() {
10316 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010317 }
10318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010319}