blob: c6e5cd24590418c5224fce26263d0d063e50cfce [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.am.BatteryStatsService;
52
53import android.Manifest;
54import android.app.ActivityManagerNative;
55import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070056import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070057import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070059import android.content.Intent;
60import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.pm.ActivityInfo;
62import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.content.res.Configuration;
65import android.graphics.Matrix;
66import android.graphics.PixelFormat;
67import android.graphics.Rect;
68import android.graphics.Region;
69import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070075import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.LocalPowerManager;
77import android.os.Looper;
78import android.os.Message;
79import android.os.Parcel;
80import android.os.ParcelFileDescriptor;
81import android.os.Power;
82import android.os.PowerManager;
83import android.os.Process;
84import android.os.RemoteException;
85import android.os.ServiceManager;
86import android.os.SystemClock;
87import android.os.SystemProperties;
88import android.os.TokenWatcher;
89import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070090import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070092import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080093import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.SparseIntArray;
95import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700104import android.view.InputChannel;
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 Brown46b9ac0a2010-04-22 18:58:52 -0700477 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478
479 // Who is holding the screen on.
480 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700481 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700482
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700483 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 /**
486 * Whether the UI is currently running in touch mode (not showing
487 * navigational focus because the user is directly pressing the screen).
488 */
489 boolean mInTouchMode = false;
490
491 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700492 private ArrayList<WindowChangeListener> mWindowChangeListeners =
493 new ArrayList<WindowChangeListener>();
494 private boolean mWindowsChanged = false;
495
496 public interface WindowChangeListener {
497 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700498 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700499 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500
Dianne Hackbornc485a602009-03-24 22:39:49 -0700501 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700502 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700503
504 // The frame use to limit the size of the app running in compatibility mode.
505 Rect mCompatibleScreenFrame = new Rect();
506 // The surface used to fill the outer rim of the app running in compatibility mode.
507 Surface mBackgroundFillerSurface = null;
508 boolean mBackgroundFillerShown = false;
509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 public static WindowManagerService main(Context context,
511 PowerManagerService pm, boolean haveInputMethods) {
512 WMThread thr = new WMThread(context, pm, haveInputMethods);
513 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 synchronized (thr) {
516 while (thr.mService == null) {
517 try {
518 thr.wait();
519 } catch (InterruptedException e) {
520 }
521 }
522 }
Romain Guy06882f82009-06-10 13:36:04 -0700523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 return thr.mService;
525 }
Romain Guy06882f82009-06-10 13:36:04 -0700526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 static class WMThread extends Thread {
528 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 private final Context mContext;
531 private final PowerManagerService mPM;
532 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 public WMThread(Context context, PowerManagerService pm,
535 boolean haveInputMethods) {
536 super("WindowManager");
537 mContext = context;
538 mPM = pm;
539 mHaveInputMethods = haveInputMethods;
540 }
Romain Guy06882f82009-06-10 13:36:04 -0700541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 public void run() {
543 Looper.prepare();
544 WindowManagerService s = new WindowManagerService(mContext, mPM,
545 mHaveInputMethods);
546 android.os.Process.setThreadPriority(
547 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700548 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 synchronized (this) {
551 mService = s;
552 notifyAll();
553 }
Romain Guy06882f82009-06-10 13:36:04 -0700554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 Looper.loop();
556 }
557 }
558
559 static class PolicyThread extends Thread {
560 private final WindowManagerPolicy mPolicy;
561 private final WindowManagerService mService;
562 private final Context mContext;
563 private final PowerManagerService mPM;
564 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 public PolicyThread(WindowManagerPolicy policy,
567 WindowManagerService service, Context context,
568 PowerManagerService pm) {
569 super("WindowManagerPolicy");
570 mPolicy = policy;
571 mService = service;
572 mContext = context;
573 mPM = pm;
574 }
Romain Guy06882f82009-06-10 13:36:04 -0700575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 public void run() {
577 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800578 WindowManagerPolicyThread.set(this, Looper.myLooper());
579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800581 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 android.os.Process.setThreadPriority(
583 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700584 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 synchronized (this) {
588 mRunning = true;
589 notifyAll();
590 }
Romain Guy06882f82009-06-10 13:36:04 -0700591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 Looper.loop();
593 }
594 }
595
596 private WindowManagerService(Context context, PowerManagerService pm,
597 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700598 if (MEASURE_LATENCY) {
599 lt = new LatencyTimer(100, 1000);
600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 mContext = context;
603 mHaveInputMethods = haveInputMethods;
604 mLimitedAlphaCompositing = context.getResources().getBoolean(
605 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 mPowerManager = pm;
608 mPowerManager.setPolicy(mPolicy);
609 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
610 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
611 "SCREEN_FROZEN");
612 mScreenFrozenLock.setReferenceCounted(false);
613
614 mActivityManager = ActivityManagerNative.getDefault();
615 mBatteryStats = BatteryStatsService.getService();
616
617 // Get persisted window scale setting
618 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
619 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
620 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
621 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700622
Jim Miller284b62e2010-06-08 14:27:42 -0700623 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
624 IntentFilter filter = new IntentFilter();
625 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
626 mContext.registerReceiver(mBroadcastReceiver, filter);
627
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700628 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
629 "KEEP_SCREEN_ON_FLAG");
630 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700632 mInputManager = new InputManager(context, this, pmc, mPowerManager);
Romain Guy06882f82009-06-10 13:36:04 -0700633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
635 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 synchronized (thr) {
638 while (!thr.mRunning) {
639 try {
640 thr.wait();
641 } catch (InterruptedException e) {
642 }
643 }
644 }
Romain Guy06882f82009-06-10 13:36:04 -0700645
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700646 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 // Add ourself to the Watchdog monitors.
649 Watchdog.getInstance().addMonitor(this);
650 }
651
652 @Override
653 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
654 throws RemoteException {
655 try {
656 return super.onTransact(code, data, reply, flags);
657 } catch (RuntimeException e) {
658 // The window manager only throws security exceptions, so let's
659 // log all others.
660 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800661 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 }
663 throw e;
664 }
665 }
666
667 private void placeWindowAfter(Object pos, WindowState window) {
668 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800669 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 TAG, "Adding window " + window + " at "
671 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
672 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700673 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 }
675
676 private void placeWindowBefore(Object pos, WindowState window) {
677 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800678 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 TAG, "Adding window " + window + " at "
680 + i + " of " + mWindows.size() + " (before " + pos + ")");
681 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700682 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 }
684
685 //This method finds out the index of a window that has the same app token as
686 //win. used for z ordering the windows in mWindows
687 private int findIdxBasedOnAppTokens(WindowState win) {
688 //use a local variable to cache mWindows
689 ArrayList localmWindows = mWindows;
690 int jmax = localmWindows.size();
691 if(jmax == 0) {
692 return -1;
693 }
694 for(int j = (jmax-1); j >= 0; j--) {
695 WindowState wentry = (WindowState)localmWindows.get(j);
696 if(wentry.mAppToken == win.mAppToken) {
697 return j;
698 }
699 }
700 return -1;
701 }
Romain Guy06882f82009-06-10 13:36:04 -0700702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
704 final IWindow client = win.mClient;
705 final WindowToken token = win.mToken;
706 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 final int N = localmWindows.size();
709 final WindowState attached = win.mAttachedWindow;
710 int i;
711 if (attached == null) {
712 int tokenWindowsPos = token.windows.size();
713 if (token.appWindowToken != null) {
714 int index = tokenWindowsPos-1;
715 if (index >= 0) {
716 // If this application has existing windows, we
717 // simply place the new window on top of them... but
718 // keep the starting window on top.
719 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
720 // Base windows go behind everything else.
721 placeWindowBefore(token.windows.get(0), win);
722 tokenWindowsPos = 0;
723 } else {
724 AppWindowToken atoken = win.mAppToken;
725 if (atoken != null &&
726 token.windows.get(index) == atoken.startingWindow) {
727 placeWindowBefore(token.windows.get(index), win);
728 tokenWindowsPos--;
729 } else {
730 int newIdx = findIdxBasedOnAppTokens(win);
731 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700732 //there is a window above this one associated with the same
733 //apptoken note that the window could be a floating window
734 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800736 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700737 TAG, "Adding window " + win + " at "
738 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700740 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700741 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 }
743 }
744 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800745 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 TAG, "Figuring out where to add app window "
747 + client.asBinder() + " (token=" + token + ")");
748 // Figure out where the window should go, based on the
749 // order of applications.
750 final int NA = mAppTokens.size();
751 Object pos = null;
752 for (i=NA-1; i>=0; i--) {
753 AppWindowToken t = mAppTokens.get(i);
754 if (t == token) {
755 i--;
756 break;
757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800758
Dianne Hackborna8f60182009-09-01 19:01:50 -0700759 // We haven't reached the token yet; if this token
760 // is not going to the bottom and has windows, we can
761 // use it as an anchor for when we do reach the token.
762 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 pos = t.windows.get(0);
764 }
765 }
766 // We now know the index into the apps. If we found
767 // an app window above, that gives us the position; else
768 // we need to look some more.
769 if (pos != null) {
770 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700771 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 mTokenMap.get(((WindowState)pos).mClient.asBinder());
773 if (atoken != null) {
774 final int NC = atoken.windows.size();
775 if (NC > 0) {
776 WindowState bottom = atoken.windows.get(0);
777 if (bottom.mSubLayer < 0) {
778 pos = bottom;
779 }
780 }
781 }
782 placeWindowBefore(pos, win);
783 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700784 // Continue looking down until we find the first
785 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 while (i >= 0) {
787 AppWindowToken t = mAppTokens.get(i);
788 final int NW = t.windows.size();
789 if (NW > 0) {
790 pos = t.windows.get(NW-1);
791 break;
792 }
793 i--;
794 }
795 if (pos != null) {
796 // Move in front of any windows attached to this
797 // one.
798 WindowToken atoken =
799 mTokenMap.get(((WindowState)pos).mClient.asBinder());
800 if (atoken != null) {
801 final int NC = atoken.windows.size();
802 if (NC > 0) {
803 WindowState top = atoken.windows.get(NC-1);
804 if (top.mSubLayer >= 0) {
805 pos = top;
806 }
807 }
808 }
809 placeWindowAfter(pos, win);
810 } else {
811 // Just search for the start of this layer.
812 final int myLayer = win.mBaseLayer;
813 for (i=0; i<N; i++) {
814 WindowState w = (WindowState)localmWindows.get(i);
815 if (w.mBaseLayer > myLayer) {
816 break;
817 }
818 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800819 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700820 TAG, "Adding window " + win + " at "
821 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700823 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 }
825 }
826 }
827 } else {
828 // Figure out where window should go, based on layer.
829 final int myLayer = win.mBaseLayer;
830 for (i=N-1; i>=0; i--) {
831 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
832 i++;
833 break;
834 }
835 }
836 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800837 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700838 TAG, "Adding window " + win + " at "
839 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700841 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 }
843 if (addToToken) {
844 token.windows.add(tokenWindowsPos, win);
845 }
846
847 } else {
848 // Figure out this window's ordering relative to the window
849 // it is attached to.
850 final int NA = token.windows.size();
851 final int sublayer = win.mSubLayer;
852 int largestSublayer = Integer.MIN_VALUE;
853 WindowState windowWithLargestSublayer = null;
854 for (i=0; i<NA; i++) {
855 WindowState w = token.windows.get(i);
856 final int wSublayer = w.mSubLayer;
857 if (wSublayer >= largestSublayer) {
858 largestSublayer = wSublayer;
859 windowWithLargestSublayer = w;
860 }
861 if (sublayer < 0) {
862 // For negative sublayers, we go below all windows
863 // in the same sublayer.
864 if (wSublayer >= sublayer) {
865 if (addToToken) {
866 token.windows.add(i, win);
867 }
868 placeWindowBefore(
869 wSublayer >= 0 ? attached : w, win);
870 break;
871 }
872 } else {
873 // For positive sublayers, we go above all windows
874 // in the same sublayer.
875 if (wSublayer > sublayer) {
876 if (addToToken) {
877 token.windows.add(i, win);
878 }
879 placeWindowBefore(w, win);
880 break;
881 }
882 }
883 }
884 if (i >= NA) {
885 if (addToToken) {
886 token.windows.add(win);
887 }
888 if (sublayer < 0) {
889 placeWindowBefore(attached, win);
890 } else {
891 placeWindowAfter(largestSublayer >= 0
892 ? windowWithLargestSublayer
893 : attached,
894 win);
895 }
896 }
897 }
Romain Guy06882f82009-06-10 13:36:04 -0700898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 if (win.mAppToken != null && addToToken) {
900 win.mAppToken.allAppWindows.add(win);
901 }
902 }
Romain Guy06882f82009-06-10 13:36:04 -0700903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 static boolean canBeImeTarget(WindowState w) {
905 final int fl = w.mAttrs.flags
906 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
907 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
908 return w.isVisibleOrAdding();
909 }
910 return false;
911 }
Romain Guy06882f82009-06-10 13:36:04 -0700912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
914 final ArrayList localmWindows = mWindows;
915 final int N = localmWindows.size();
916 WindowState w = null;
917 int i = N;
918 while (i > 0) {
919 i--;
920 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700921
Joe Onorato8a9b2202010-02-26 18:56:32 -0800922 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 // + Integer.toHexString(w.mAttrs.flags));
924 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800925 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 // Yet more tricksyness! If this window is a "starting"
928 // window, we do actually want to be on top of it, but
929 // it is not -really- where input will go. So if the caller
930 // is not actually looking to move the IME, look down below
931 // for a real window to target...
932 if (!willMove
933 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
934 && i > 0) {
935 WindowState wb = (WindowState)localmWindows.get(i-1);
936 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
937 i--;
938 w = wb;
939 }
940 }
941 break;
942 }
943 }
Romain Guy06882f82009-06-10 13:36:04 -0700944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700946
Joe Onorato8a9b2202010-02-26 18:56:32 -0800947 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 if (willMove && w != null) {
951 final WindowState curTarget = mInputMethodTarget;
952 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 // Now some fun for dealing with window animations that
955 // modify the Z order. We need to look at all windows below
956 // the current target that are in this app, finding the highest
957 // visible one in layering.
958 AppWindowToken token = curTarget.mAppToken;
959 WindowState highestTarget = null;
960 int highestPos = 0;
961 if (token.animating || token.animation != null) {
962 int pos = 0;
963 pos = localmWindows.indexOf(curTarget);
964 while (pos >= 0) {
965 WindowState win = (WindowState)localmWindows.get(pos);
966 if (win.mAppToken != token) {
967 break;
968 }
969 if (!win.mRemoved) {
970 if (highestTarget == null || win.mAnimLayer >
971 highestTarget.mAnimLayer) {
972 highestTarget = win;
973 highestPos = pos;
974 }
975 }
976 pos--;
977 }
978 }
Romain Guy06882f82009-06-10 13:36:04 -0700979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800981 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 + mNextAppTransition + " " + highestTarget
983 + " animating=" + highestTarget.isAnimating()
984 + " layer=" + highestTarget.mAnimLayer
985 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700986
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700987 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 // If we are currently setting up for an animation,
989 // hold everything until we can find out what will happen.
990 mInputMethodTargetWaitingAnim = true;
991 mInputMethodTarget = highestTarget;
992 return highestPos + 1;
993 } else if (highestTarget.isAnimating() &&
994 highestTarget.mAnimLayer > w.mAnimLayer) {
995 // If the window we are currently targeting is involved
996 // with an animation, and it is on top of the next target
997 // we will be over, then hold off on moving until
998 // that is done.
999 mInputMethodTarget = highestTarget;
1000 return highestPos + 1;
1001 }
1002 }
1003 }
1004 }
Romain Guy06882f82009-06-10 13:36:04 -07001005
Joe Onorato8a9b2202010-02-26 18:56:32 -08001006 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 if (w != null) {
1008 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001009 if (DEBUG_INPUT_METHOD) {
1010 RuntimeException e = null;
1011 if (!HIDE_STACK_CRAWLS) {
1012 e = new RuntimeException();
1013 e.fillInStackTrace();
1014 }
1015 Slog.w(TAG, "Moving IM target from "
1016 + mInputMethodTarget + " to " + w, e);
1017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 mInputMethodTarget = w;
1019 if (w.mAppToken != null) {
1020 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1021 } else {
1022 setInputMethodAnimLayerAdjustment(0);
1023 }
1024 }
1025 return i+1;
1026 }
1027 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001028 if (DEBUG_INPUT_METHOD) {
1029 RuntimeException e = null;
1030 if (!HIDE_STACK_CRAWLS) {
1031 e = new RuntimeException();
1032 e.fillInStackTrace();
1033 }
1034 Slog.w(TAG, "Moving IM target from "
1035 + mInputMethodTarget + " to null", e);
1036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 mInputMethodTarget = null;
1038 setInputMethodAnimLayerAdjustment(0);
1039 }
1040 return -1;
1041 }
Romain Guy06882f82009-06-10 13:36:04 -07001042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 void addInputMethodWindowToListLocked(WindowState win) {
1044 int pos = findDesiredInputMethodWindowIndexLocked(true);
1045 if (pos >= 0) {
1046 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001047 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001048 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001050 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 moveInputMethodDialogsLocked(pos+1);
1052 return;
1053 }
1054 win.mTargetAppToken = null;
1055 addWindowToListInOrderLocked(win, true);
1056 moveInputMethodDialogsLocked(pos);
1057 }
Romain Guy06882f82009-06-10 13:36:04 -07001058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001060 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 mInputMethodAnimLayerAdjustment = adj;
1062 WindowState imw = mInputMethodWindow;
1063 if (imw != null) {
1064 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001065 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 + " anim layer: " + imw.mAnimLayer);
1067 int wi = imw.mChildWindows.size();
1068 while (wi > 0) {
1069 wi--;
1070 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1071 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001072 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 + " anim layer: " + cw.mAnimLayer);
1074 }
1075 }
1076 int di = mInputMethodDialogs.size();
1077 while (di > 0) {
1078 di --;
1079 imw = mInputMethodDialogs.get(di);
1080 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001081 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 + " anim layer: " + imw.mAnimLayer);
1083 }
1084 }
Romain Guy06882f82009-06-10 13:36:04 -07001085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1087 int wpos = mWindows.indexOf(win);
1088 if (wpos >= 0) {
1089 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001090 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001092 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 int NC = win.mChildWindows.size();
1094 while (NC > 0) {
1095 NC--;
1096 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1097 int cpos = mWindows.indexOf(cw);
1098 if (cpos >= 0) {
1099 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001100 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001101 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 mWindows.remove(cpos);
1103 }
1104 }
1105 }
1106 return interestingPos;
1107 }
Romain Guy06882f82009-06-10 13:36:04 -07001108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 private void reAddWindowToListInOrderLocked(WindowState win) {
1110 addWindowToListInOrderLocked(win, false);
1111 // This is a hack to get all of the child windows added as well
1112 // at the right position. Child windows should be rare and
1113 // this case should be rare, so it shouldn't be that big a deal.
1114 int wpos = mWindows.indexOf(win);
1115 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001116 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001117 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001119 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 reAddWindowLocked(wpos, win);
1121 }
1122 }
Romain Guy06882f82009-06-10 13:36:04 -07001123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 void logWindowList(String prefix) {
1125 int N = mWindows.size();
1126 while (N > 0) {
1127 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001128 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 }
1130 }
Romain Guy06882f82009-06-10 13:36:04 -07001131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 void moveInputMethodDialogsLocked(int pos) {
1133 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001136 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 for (int i=0; i<N; i++) {
1138 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1139 }
1140 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001141 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 logWindowList(" ");
1143 }
Romain Guy06882f82009-06-10 13:36:04 -07001144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 if (pos >= 0) {
1146 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1147 if (pos < mWindows.size()) {
1148 WindowState wp = (WindowState)mWindows.get(pos);
1149 if (wp == mInputMethodWindow) {
1150 pos++;
1151 }
1152 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001153 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 for (int i=0; i<N; i++) {
1155 WindowState win = dialogs.get(i);
1156 win.mTargetAppToken = targetAppToken;
1157 pos = reAddWindowLocked(pos, win);
1158 }
1159 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001160 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 logWindowList(" ");
1162 }
1163 return;
1164 }
1165 for (int i=0; i<N; i++) {
1166 WindowState win = dialogs.get(i);
1167 win.mTargetAppToken = null;
1168 reAddWindowToListInOrderLocked(win);
1169 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001170 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 logWindowList(" ");
1172 }
1173 }
1174 }
Romain Guy06882f82009-06-10 13:36:04 -07001175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1177 final WindowState imWin = mInputMethodWindow;
1178 final int DN = mInputMethodDialogs.size();
1179 if (imWin == null && DN == 0) {
1180 return false;
1181 }
Romain Guy06882f82009-06-10 13:36:04 -07001182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1184 if (imPos >= 0) {
1185 // In this case, the input method windows are to be placed
1186 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 // First check to see if the input method windows are already
1189 // located here, and contiguous.
1190 final int N = mWindows.size();
1191 WindowState firstImWin = imPos < N
1192 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 // Figure out the actual input method window that should be
1195 // at the bottom of their stack.
1196 WindowState baseImWin = imWin != null
1197 ? imWin : mInputMethodDialogs.get(0);
1198 if (baseImWin.mChildWindows.size() > 0) {
1199 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1200 if (cw.mSubLayer < 0) baseImWin = cw;
1201 }
Romain Guy06882f82009-06-10 13:36:04 -07001202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 if (firstImWin == baseImWin) {
1204 // The windows haven't moved... but are they still contiguous?
1205 // First find the top IM window.
1206 int pos = imPos+1;
1207 while (pos < N) {
1208 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1209 break;
1210 }
1211 pos++;
1212 }
1213 pos++;
1214 // Now there should be no more input method windows above.
1215 while (pos < N) {
1216 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1217 break;
1218 }
1219 pos++;
1220 }
1221 if (pos >= N) {
1222 // All is good!
1223 return false;
1224 }
1225 }
Romain Guy06882f82009-06-10 13:36:04 -07001226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 if (imWin != null) {
1228 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001229 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 logWindowList(" ");
1231 }
1232 imPos = tmpRemoveWindowLocked(imPos, imWin);
1233 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001234 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 logWindowList(" ");
1236 }
1237 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1238 reAddWindowLocked(imPos, imWin);
1239 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001240 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 logWindowList(" ");
1242 }
1243 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1244 } else {
1245 moveInputMethodDialogsLocked(imPos);
1246 }
Romain Guy06882f82009-06-10 13:36:04 -07001247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 } else {
1249 // In this case, the input method windows go in a fixed layer,
1250 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001253 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 tmpRemoveWindowLocked(0, imWin);
1255 imWin.mTargetAppToken = null;
1256 reAddWindowToListInOrderLocked(imWin);
1257 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001258 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 logWindowList(" ");
1260 }
1261 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1262 } else {
1263 moveInputMethodDialogsLocked(-1);;
1264 }
Romain Guy06882f82009-06-10 13:36:04 -07001265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 }
Romain Guy06882f82009-06-10 13:36:04 -07001267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 if (needAssignLayers) {
1269 assignLayersLocked();
1270 }
Romain Guy06882f82009-06-10 13:36:04 -07001271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 return true;
1273 }
Romain Guy06882f82009-06-10 13:36:04 -07001274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 void adjustInputMethodDialogsLocked() {
1276 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1277 }
Romain Guy06882f82009-06-10 13:36:04 -07001278
Dianne Hackborn25994b42009-09-04 14:21:19 -07001279 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001280 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001281 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1282 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1283 ? wallpaperTarget.mAppToken.animation : null)
1284 + " upper=" + mUpperWallpaperTarget
1285 + " lower=" + mLowerWallpaperTarget);
1286 return (wallpaperTarget != null
1287 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1288 && wallpaperTarget.mAppToken.animation != null)))
1289 || mUpperWallpaperTarget != null
1290 || mLowerWallpaperTarget != null;
1291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001292
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001293 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1294 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001295
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001296 int adjustWallpaperWindowsLocked() {
1297 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001298
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001299 final int dw = mDisplay.getWidth();
1300 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001301
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001302 // First find top-most window that has asked to be on top of the
1303 // wallpaper; all wallpapers go behind it.
1304 final ArrayList localmWindows = mWindows;
1305 int N = localmWindows.size();
1306 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001307 WindowState foundW = null;
1308 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001309 WindowState topCurW = null;
1310 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001311 int i = N;
1312 while (i > 0) {
1313 i--;
1314 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001315 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1316 if (topCurW == null) {
1317 topCurW = w;
1318 topCurI = i;
1319 }
1320 continue;
1321 }
1322 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001323 if (w.mAppToken != null) {
1324 // If this window's app token is hidden and not animating,
1325 // it is of no interest to us.
1326 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001327 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001328 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001329 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001330 continue;
1331 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001332 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001334 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1335 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001336 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001337 && (mWallpaperTarget == w
1338 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001339 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001340 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001341 foundW = w;
1342 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001343 if (w == mWallpaperTarget && ((w.mAppToken != null
1344 && w.mAppToken.animation != null)
1345 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001346 // The current wallpaper target is animating, so we'll
1347 // look behind it for another possible target and figure
1348 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001349 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001350 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001351 continue;
1352 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001353 break;
1354 }
1355 }
1356
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001357 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001358 // If we are currently waiting for an app transition, and either
1359 // the current target or the next target are involved with it,
1360 // then hold off on doing anything with the wallpaper.
1361 // Note that we are checking here for just whether the target
1362 // is part of an app token... which is potentially overly aggressive
1363 // (the app token may not be involved in the transition), but good
1364 // enough (we'll just wait until whatever transition is pending
1365 // executes).
1366 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001367 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001368 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001369 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001370 }
1371 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001372 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001373 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001374 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001375 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001376 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001377
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001378 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001379 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001380 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 + " oldTarget: " + mWallpaperTarget);
1382 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001383
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001384 mLowerWallpaperTarget = null;
1385 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001386
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001387 WindowState oldW = mWallpaperTarget;
1388 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001389
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001390 // Now what is happening... if the current and new targets are
1391 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001392 if (foundW != null && oldW != null) {
1393 boolean oldAnim = oldW.mAnimation != null
1394 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1395 boolean foundAnim = foundW.mAnimation != null
1396 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001398 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001399 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001400 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001401 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001402 int oldI = localmWindows.indexOf(oldW);
1403 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001404 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001405 }
1406 if (oldI >= 0) {
1407 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001408 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001409 + "=" + oldW + "; new#" + foundI
1410 + "=" + foundW);
1411 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001412
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001413 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001414 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001415 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001416 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001417 }
1418 mWallpaperTarget = oldW;
1419 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001420
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001421 // Now set the upper and lower wallpaper targets
1422 // correctly, and make sure that we are positioning
1423 // the wallpaper below the lower.
1424 if (foundI > oldI) {
1425 // The new target is on top of the old one.
1426 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001427 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001428 }
1429 mUpperWallpaperTarget = foundW;
1430 mLowerWallpaperTarget = oldW;
1431 foundW = oldW;
1432 foundI = oldI;
1433 } else {
1434 // The new target is below the old one.
1435 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001436 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001437 }
1438 mUpperWallpaperTarget = oldW;
1439 mLowerWallpaperTarget = foundW;
1440 }
1441 }
1442 }
1443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001444
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001445 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001446 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001447 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1448 || (mLowerWallpaperTarget.mAppToken != null
1449 && mLowerWallpaperTarget.mAppToken.animation != null);
1450 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1451 || (mUpperWallpaperTarget.mAppToken != null
1452 && mUpperWallpaperTarget.mAppToken.animation != null);
1453 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001454 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001455 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001456 }
1457 mLowerWallpaperTarget = null;
1458 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001459 }
1460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001461
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001462 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001463 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001464 // The window is visible to the compositor... but is it visible
1465 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001466 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001468
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001469 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001470 // its layer adjustment. Only do this if we are not transfering
1471 // between two wallpaper targets.
1472 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001473 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001474 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001475
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001476 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1477 * TYPE_LAYER_MULTIPLIER
1478 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001479
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001480 // Now w is the window we are supposed to be behind... but we
1481 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001482 // AND any starting window associated with it, AND below the
1483 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001484 while (foundI > 0) {
1485 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001486 if (wb.mBaseLayer < maxLayer &&
1487 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001488 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001489 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001490 // This window is not related to the previous one in any
1491 // interesting way, so stop here.
1492 break;
1493 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001494 foundW = wb;
1495 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001496 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001497 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001498 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001499 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001500
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001501 if (foundW == null && topCurW != null) {
1502 // There is no wallpaper target, so it goes at the bottom.
1503 // We will assume it is the same place as last time, if known.
1504 foundW = topCurW;
1505 foundI = topCurI+1;
1506 } else {
1507 // Okay i is the position immediately above the wallpaper. Look at
1508 // what is below it for later.
1509 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1510 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001511
Dianne Hackborn284ac932009-08-28 10:34:25 -07001512 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001513 if (mWallpaperTarget.mWallpaperX >= 0) {
1514 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001515 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001516 }
1517 if (mWallpaperTarget.mWallpaperY >= 0) {
1518 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001519 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001520 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001521 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001522
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001523 // Start stepping backwards from here, ensuring that our wallpaper windows
1524 // are correctly placed.
1525 int curTokenIndex = mWallpaperTokens.size();
1526 while (curTokenIndex > 0) {
1527 curTokenIndex--;
1528 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001529 if (token.hidden == visible) {
1530 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1531 token.hidden = !visible;
1532 // Need to do a layout to ensure the wallpaper now has the
1533 // correct size.
1534 mLayoutNeeded = true;
1535 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001536
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001537 int curWallpaperIndex = token.windows.size();
1538 while (curWallpaperIndex > 0) {
1539 curWallpaperIndex--;
1540 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001541
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001542 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001543 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001544 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001545
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001546 // First, make sure the client has the current visibility
1547 // state.
1548 if (wallpaper.mWallpaperVisible != visible) {
1549 wallpaper.mWallpaperVisible = visible;
1550 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001551 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001552 "Setting visibility of wallpaper " + wallpaper
1553 + ": " + visible);
1554 wallpaper.mClient.dispatchAppVisibility(visible);
1555 } catch (RemoteException e) {
1556 }
1557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001558
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001559 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001561 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001562
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001563 // First, if this window is at the current index, then all
1564 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001565 if (wallpaper == foundW) {
1566 foundI--;
1567 foundW = foundI > 0
1568 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 continue;
1570 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001571
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001572 // The window didn't match... the current wallpaper window,
1573 // wherever it is, is in the wrong place, so make sure it is
1574 // not in the list.
1575 int oldIndex = localmWindows.indexOf(wallpaper);
1576 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001577 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001578 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001579 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001580 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001581 if (oldIndex < foundI) {
1582 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001583 }
1584 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001585
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001586 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001587 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001588 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001589 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001590
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001591 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001592 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001593 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001594 }
1595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001596
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001597 return changed;
1598 }
1599
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001600 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001601 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001602 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001603 mWallpaperAnimLayerAdjustment = adj;
1604 int curTokenIndex = mWallpaperTokens.size();
1605 while (curTokenIndex > 0) {
1606 curTokenIndex--;
1607 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1608 int curWallpaperIndex = token.windows.size();
1609 while (curWallpaperIndex > 0) {
1610 curWallpaperIndex--;
1611 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1612 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001613 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001614 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001615 }
1616 }
1617 }
1618
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001619 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1620 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001621 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001622 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001624 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001625 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1626 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1627 changed = wallpaperWin.mXOffset != offset;
1628 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001629 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001630 + wallpaperWin + " x: " + offset);
1631 wallpaperWin.mXOffset = offset;
1632 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001635 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001636 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001637 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001638
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001639 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001640 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001641 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1642 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1643 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001644 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001645 + wallpaperWin + " y: " + offset);
1646 changed = true;
1647 wallpaperWin.mYOffset = offset;
1648 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001649 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001651 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001652 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001654
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001655 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001656 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001657 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001658 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1659 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001661 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001662 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001663 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001664 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1665 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001666 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001667 if (mWaitingOnWallpaper != null) {
1668 long start = SystemClock.uptimeMillis();
1669 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1670 < start) {
1671 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001672 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001673 "Waiting for offset complete...");
1674 mWindowMap.wait(WALLPAPER_TIMEOUT);
1675 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001676 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 if ((start+WALLPAPER_TIMEOUT)
1679 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001680 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001681 + wallpaperWin);
1682 mLastWallpaperTimeoutTime = start;
1683 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001684 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001685 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001686 }
1687 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001688 } catch (RemoteException e) {
1689 }
1690 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001691
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001692 return changed;
1693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001694
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001695 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001696 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001697 if (mWaitingOnWallpaper != null &&
1698 mWaitingOnWallpaper.mClient.asBinder() == window) {
1699 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001700 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001701 }
1702 }
1703 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001704
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001705 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001706 final int dw = mDisplay.getWidth();
1707 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001709 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001710
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001711 WindowState target = mWallpaperTarget;
1712 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001713 if (target.mWallpaperX >= 0) {
1714 mLastWallpaperX = target.mWallpaperX;
1715 } else if (changingTarget.mWallpaperX >= 0) {
1716 mLastWallpaperX = changingTarget.mWallpaperX;
1717 }
1718 if (target.mWallpaperY >= 0) {
1719 mLastWallpaperY = target.mWallpaperY;
1720 } else if (changingTarget.mWallpaperY >= 0) {
1721 mLastWallpaperY = changingTarget.mWallpaperY;
1722 }
1723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001724
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001725 int curTokenIndex = mWallpaperTokens.size();
1726 while (curTokenIndex > 0) {
1727 curTokenIndex--;
1728 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1729 int curWallpaperIndex = token.windows.size();
1730 while (curWallpaperIndex > 0) {
1731 curWallpaperIndex--;
1732 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1733 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1734 wallpaper.computeShownFrameLocked();
1735 changed = true;
1736 // We only want to be synchronous with one wallpaper.
1737 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001738 }
1739 }
1740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001742 return changed;
1743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001744
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001745 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001746 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001747 final int dw = mDisplay.getWidth();
1748 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001749
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001750 int curTokenIndex = mWallpaperTokens.size();
1751 while (curTokenIndex > 0) {
1752 curTokenIndex--;
1753 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001754 if (token.hidden == visible) {
1755 token.hidden = !visible;
1756 // Need to do a layout to ensure the wallpaper now has the
1757 // correct size.
1758 mLayoutNeeded = true;
1759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001760
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001761 int curWallpaperIndex = token.windows.size();
1762 while (curWallpaperIndex > 0) {
1763 curWallpaperIndex--;
1764 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1765 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001766 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001768
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001769 if (wallpaper.mWallpaperVisible != visible) {
1770 wallpaper.mWallpaperVisible = visible;
1771 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001772 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001773 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001774 + ": " + visible);
1775 wallpaper.mClient.dispatchAppVisibility(visible);
1776 } catch (RemoteException e) {
1777 }
1778 }
1779 }
1780 }
1781 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 public int addWindow(Session session, IWindow client,
1784 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001785 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 int res = mPolicy.checkAddPermission(attrs);
1787 if (res != WindowManagerImpl.ADD_OKAY) {
1788 return res;
1789 }
Romain Guy06882f82009-06-10 13:36:04 -07001790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 boolean reportNewConfig = false;
1792 WindowState attachedWindow = null;
1793 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 synchronized(mWindowMap) {
1796 // Instantiating a Display requires talking with the simulator,
1797 // so don't do it until we know the system is mostly up and
1798 // running.
1799 if (mDisplay == null) {
1800 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1801 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001802 mInitialDisplayWidth = mDisplay.getWidth();
1803 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001804 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 reportNewConfig = true;
1806 }
Romain Guy06882f82009-06-10 13:36:04 -07001807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1811 }
1812
1813 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001814 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001816 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 + attrs.token + ". Aborting.");
1818 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1819 }
1820 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1821 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001822 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 + attrs.token + ". Aborting.");
1824 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1825 }
1826 }
1827
1828 boolean addToken = false;
1829 WindowToken token = mTokenMap.get(attrs.token);
1830 if (token == null) {
1831 if (attrs.type >= FIRST_APPLICATION_WINDOW
1832 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 + attrs.token + ". Aborting.");
1835 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1836 }
1837 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001838 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 + attrs.token + ". Aborting.");
1840 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1841 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001842 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001843 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001844 + attrs.token + ". Aborting.");
1845 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 token = new WindowToken(attrs.token, -1, false);
1848 addToken = true;
1849 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1850 && attrs.type <= LAST_APPLICATION_WINDOW) {
1851 AppWindowToken atoken = token.appWindowToken;
1852 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001853 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 + token + ". Aborting.");
1855 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1856 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001857 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 + token + ". Aborting.");
1859 return WindowManagerImpl.ADD_APP_EXITING;
1860 }
1861 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1862 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1865 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1866 }
1867 } else if (attrs.type == TYPE_INPUT_METHOD) {
1868 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 + attrs.token + ". Aborting.");
1871 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1872 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001873 } else if (attrs.type == TYPE_WALLPAPER) {
1874 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001875 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001876 + attrs.token + ". Aborting.");
1877 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 }
1880
1881 win = new WindowState(session, client, token,
1882 attachedWindow, attrs, viewVisibility);
1883 if (win.mDeathRecipient == null) {
1884 // Client has apparently died, so there is no reason to
1885 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001886 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 + " that is dead, aborting.");
1888 return WindowManagerImpl.ADD_APP_EXITING;
1889 }
1890
1891 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 res = mPolicy.prepareAddWindowLw(win, attrs);
1894 if (res != WindowManagerImpl.ADD_OKAY) {
1895 return res;
1896 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001897
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001898 if (outInputChannel != null) {
1899 String name = win.makeInputChannelName();
1900 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1901 win.mInputChannel = inputChannels[0];
1902 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1903
1904 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001906
1907 // From now on, no exceptions or errors allowed!
1908
1909 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 if (addToken) {
1914 mTokenMap.put(attrs.token, token);
1915 mTokenList.add(token);
1916 }
1917 win.attach();
1918 mWindowMap.put(client.asBinder(), win);
1919
1920 if (attrs.type == TYPE_APPLICATION_STARTING &&
1921 token.appWindowToken != null) {
1922 token.appWindowToken.startingWindow = win;
1923 }
1924
1925 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 if (attrs.type == TYPE_INPUT_METHOD) {
1928 mInputMethodWindow = win;
1929 addInputMethodWindowToListLocked(win);
1930 imMayMove = false;
1931 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1932 mInputMethodDialogs.add(win);
1933 addWindowToListInOrderLocked(win, true);
1934 adjustInputMethodDialogsLocked();
1935 imMayMove = false;
1936 } else {
1937 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001938 if (attrs.type == TYPE_WALLPAPER) {
1939 mLastWallpaperTimeoutTime = 0;
1940 adjustWallpaperWindowsLocked();
1941 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001942 adjustWallpaperWindowsLocked();
1943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 }
Romain Guy06882f82009-06-10 13:36:04 -07001945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 if (mInTouchMode) {
1951 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1952 }
1953 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1954 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1955 }
Romain Guy06882f82009-06-10 13:36:04 -07001956
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001957 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001959 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1960 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 imMayMove = false;
1962 }
1963 }
Romain Guy06882f82009-06-10 13:36:04 -07001964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001966 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 }
Romain Guy06882f82009-06-10 13:36:04 -07001968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 assignLayersLocked();
1970 // Don't do layout here, the window must call
1971 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 //dump();
1974
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001975 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001976 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001977 }
Jeff Brown349703e2010-06-22 01:27:15 -07001978
Joe Onorato8a9b2202010-02-26 18:56:32 -08001979 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 TAG, "New client " + client.asBinder()
1981 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001982
1983 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1984 reportNewConfig = true;
1985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 }
1987
1988 // sendNewConfiguration() checks caller permissions so we must call it with
1989 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1990 // identity anyway, so it's safe to just clear & restore around this whole
1991 // block.
1992 final long origId = Binder.clearCallingIdentity();
1993 if (reportNewConfig) {
1994 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 }
1996 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 return res;
1999 }
Romain Guy06882f82009-06-10 13:36:04 -07002000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 public void removeWindow(Session session, IWindow client) {
2002 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002003 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 if (win == null) {
2005 return;
2006 }
2007 removeWindowLocked(session, win);
2008 }
2009 }
Romain Guy06882f82009-06-10 13:36:04 -07002010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 public void removeWindowLocked(Session session, WindowState win) {
2012
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 TAG, "Remove " + win + " client="
2015 + Integer.toHexString(System.identityHashCode(
2016 win.mClient.asBinder()))
2017 + ", surface=" + win.mSurface);
2018
2019 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002020
Joe Onorato8a9b2202010-02-26 18:56:32 -08002021 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002022 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2023 + " mExiting=" + win.mExiting
2024 + " isAnimating=" + win.isAnimating()
2025 + " app-animation="
2026 + (win.mAppToken != null ? win.mAppToken.animation : null)
2027 + " inPendingTransaction="
2028 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2029 + " mDisplayFrozen=" + mDisplayFrozen);
2030 // Visibility of the removed window. Will be used later to update orientation later on.
2031 boolean wasVisible = false;
2032 // First, see if we need to run an animation. If we do, we have
2033 // to hold off on removing the window until the animation is done.
2034 // If the display is frozen, just remove immediately, since the
2035 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002036 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037 // If we are not currently running the exit animation, we
2038 // need to see about starting one.
2039 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2042 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2043 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2044 }
2045 // Try starting an animation.
2046 if (applyAnimationLocked(win, transit, false)) {
2047 win.mExiting = true;
2048 }
2049 }
2050 if (win.mExiting || win.isAnimating()) {
2051 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002052 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 win.mExiting = true;
2054 win.mRemoveOnExit = true;
2055 mLayoutNeeded = true;
2056 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2057 performLayoutAndPlaceSurfacesLocked();
2058 if (win.mAppToken != null) {
2059 win.mAppToken.updateReportedVisibilityLocked();
2060 }
2061 //dump();
2062 Binder.restoreCallingIdentity(origId);
2063 return;
2064 }
2065 }
2066
2067 removeWindowInnerLocked(session, win);
2068 // Removing a visible window will effect the computed orientation
2069 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002070 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002071 != mForcedAppOrientation
2072 && updateOrientationFromAppTokensLocked()) {
2073 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 }
2075 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2076 Binder.restoreCallingIdentity(origId);
2077 }
Romain Guy06882f82009-06-10 13:36:04 -07002078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 private void removeWindowInnerLocked(Session session, WindowState win) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002080 mInputMonitor.windowIsBeingRemovedLw(win);
Romain Guy06882f82009-06-10 13:36:04 -07002081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 if (mInputMethodTarget == win) {
2085 moveInputMethodWindowsIfNeededLocked(false);
2086 }
Romain Guy06882f82009-06-10 13:36:04 -07002087
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002088 if (false) {
2089 RuntimeException e = new RuntimeException("here");
2090 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002091 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 mPolicy.removeWindowLw(win);
2095 win.removeLocked();
2096
2097 mWindowMap.remove(win.mClient.asBinder());
2098 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002099 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002100 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101
2102 if (mInputMethodWindow == win) {
2103 mInputMethodWindow = null;
2104 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2105 mInputMethodDialogs.remove(win);
2106 }
Romain Guy06882f82009-06-10 13:36:04 -07002107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002108 final WindowToken token = win.mToken;
2109 final AppWindowToken atoken = win.mAppToken;
2110 token.windows.remove(win);
2111 if (atoken != null) {
2112 atoken.allAppWindows.remove(win);
2113 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002114 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 TAG, "**** Removing window " + win + ": count="
2116 + token.windows.size());
2117 if (token.windows.size() == 0) {
2118 if (!token.explicit) {
2119 mTokenMap.remove(token.token);
2120 mTokenList.remove(token);
2121 } else if (atoken != null) {
2122 atoken.firstWindowDrawn = false;
2123 }
2124 }
2125
2126 if (atoken != null) {
2127 if (atoken.startingWindow == win) {
2128 atoken.startingWindow = null;
2129 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2130 // If this is the last window and we had requested a starting
2131 // transition window, well there is no point now.
2132 atoken.startingData = null;
2133 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2134 // If this is the last window except for a starting transition
2135 // window, we need to get rid of the starting transition.
2136 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002137 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 + ": no more real windows");
2139 }
2140 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2141 mH.sendMessage(m);
2142 }
2143 }
Romain Guy06882f82009-06-10 13:36:04 -07002144
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002145 if (win.mAttrs.type == TYPE_WALLPAPER) {
2146 mLastWallpaperTimeoutTime = 0;
2147 adjustWallpaperWindowsLocked();
2148 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002149 adjustWallpaperWindowsLocked();
2150 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 if (!mInLayout) {
2153 assignLayersLocked();
2154 mLayoutNeeded = true;
2155 performLayoutAndPlaceSurfacesLocked();
2156 if (win.mAppToken != null) {
2157 win.mAppToken.updateReportedVisibilityLocked();
2158 }
2159 }
2160 }
2161
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002162 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2163 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2164 + ": " + msg + " / " + w.mAttrs.getTitle();
2165 if (where != null) {
2166 Slog.i(TAG, str, where);
2167 } else {
2168 Slog.i(TAG, str);
2169 }
2170 }
2171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2173 long origId = Binder.clearCallingIdentity();
2174 try {
2175 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002176 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002177 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002178 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 Surface.openTransaction();
2180 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002181 if (SHOW_TRANSACTIONS) logSurface(w,
2182 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 w.mSurface.setTransparentRegionHint(region);
2184 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002185 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 Surface.closeTransaction();
2187 }
2188 }
2189 }
2190 } finally {
2191 Binder.restoreCallingIdentity(origId);
2192 }
2193 }
2194
2195 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002196 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 Rect visibleInsets) {
2198 long origId = Binder.clearCallingIdentity();
2199 try {
2200 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002201 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 if (w != null) {
2203 w.mGivenInsetsPending = false;
2204 w.mGivenContentInsets.set(contentInsets);
2205 w.mGivenVisibleInsets.set(visibleInsets);
2206 w.mTouchableInsets = touchableInsets;
2207 mLayoutNeeded = true;
2208 performLayoutAndPlaceSurfacesLocked();
2209 }
2210 }
2211 } finally {
2212 Binder.restoreCallingIdentity(origId);
2213 }
2214 }
Romain Guy06882f82009-06-10 13:36:04 -07002215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 public void getWindowDisplayFrame(Session session, IWindow client,
2217 Rect outDisplayFrame) {
2218 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002219 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 if (win == null) {
2221 outDisplayFrame.setEmpty();
2222 return;
2223 }
2224 outDisplayFrame.set(win.mDisplayFrame);
2225 }
2226 }
2227
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002228 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2229 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002230 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2231 window.mWallpaperX = x;
2232 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002233 window.mWallpaperXStep = xStep;
2234 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002235 if (updateWallpaperOffsetLocked(window, true)) {
2236 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002237 }
2238 }
2239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002240
Dianne Hackborn75804932009-10-20 20:15:20 -07002241 void wallpaperCommandComplete(IBinder window, Bundle result) {
2242 synchronized (mWindowMap) {
2243 if (mWaitingOnWallpaper != null &&
2244 mWaitingOnWallpaper.mClient.asBinder() == window) {
2245 mWaitingOnWallpaper = null;
2246 mWindowMap.notifyAll();
2247 }
2248 }
2249 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002250
Dianne Hackborn75804932009-10-20 20:15:20 -07002251 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2252 String action, int x, int y, int z, Bundle extras, boolean sync) {
2253 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2254 || window == mUpperWallpaperTarget) {
2255 boolean doWait = sync;
2256 int curTokenIndex = mWallpaperTokens.size();
2257 while (curTokenIndex > 0) {
2258 curTokenIndex--;
2259 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2260 int curWallpaperIndex = token.windows.size();
2261 while (curWallpaperIndex > 0) {
2262 curWallpaperIndex--;
2263 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2264 try {
2265 wallpaper.mClient.dispatchWallpaperCommand(action,
2266 x, y, z, extras, sync);
2267 // We only want to be synchronous with one wallpaper.
2268 sync = false;
2269 } catch (RemoteException e) {
2270 }
2271 }
2272 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002273
Dianne Hackborn75804932009-10-20 20:15:20 -07002274 if (doWait) {
2275 // XXX Need to wait for result.
2276 }
2277 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002278
Dianne Hackborn75804932009-10-20 20:15:20 -07002279 return null;
2280 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 public int relayoutWindow(Session session, IWindow client,
2283 WindowManager.LayoutParams attrs, int requestedWidth,
2284 int requestedHeight, int viewVisibility, boolean insetsPending,
2285 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002286 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 boolean displayed = false;
2288 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002289 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002293 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 if (win == null) {
2295 return 0;
2296 }
2297 win.mRequestedWidth = requestedWidth;
2298 win.mRequestedHeight = requestedHeight;
2299
2300 if (attrs != null) {
2301 mPolicy.adjustWindowParamsLw(attrs);
2302 }
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 int attrChanges = 0;
2305 int flagChanges = 0;
2306 if (attrs != null) {
2307 flagChanges = win.mAttrs.flags ^= attrs.flags;
2308 attrChanges = win.mAttrs.copyFrom(attrs);
2309 }
2310
Joe Onorato8a9b2202010-02-26 18:56:32 -08002311 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312
2313 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2314 win.mAlpha = attrs.alpha;
2315 }
2316
2317 final boolean scaledWindow =
2318 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2319
2320 if (scaledWindow) {
2321 // requested{Width|Height} Surface's physical size
2322 // attrs.{width|height} Size on screen
2323 win.mHScale = (attrs.width != requestedWidth) ?
2324 (attrs.width / (float)requestedWidth) : 1.0f;
2325 win.mVScale = (attrs.height != requestedHeight) ?
2326 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002327 } else {
2328 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 }
2330
2331 boolean imMayMove = (flagChanges&(
2332 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2333 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 boolean focusMayChange = win.mViewVisibility != viewVisibility
2336 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2337 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002338
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002339 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2340 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 win.mRelayoutCalled = true;
2343 final int oldVisibility = win.mViewVisibility;
2344 win.mViewVisibility = viewVisibility;
2345 if (viewVisibility == View.VISIBLE &&
2346 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2347 displayed = !win.isVisibleLw();
2348 if (win.mExiting) {
2349 win.mExiting = false;
2350 win.mAnimation = null;
2351 }
2352 if (win.mDestroying) {
2353 win.mDestroying = false;
2354 mDestroySurface.remove(win);
2355 }
2356 if (oldVisibility == View.GONE) {
2357 win.mEnterAnimationPending = true;
2358 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002359 if (displayed) {
2360 if (win.mSurface != null && !win.mDrawPending
2361 && !win.mCommitDrawPending && !mDisplayFrozen
2362 && mPolicy.isScreenOn()) {
2363 applyEnterAnimationLocked(win);
2364 }
2365 if ((win.mAttrs.flags
2366 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2367 if (DEBUG_VISIBILITY) Slog.v(TAG,
2368 "Relayout window turning screen on: " + win);
2369 win.mTurnOnScreen = true;
2370 }
2371 int diff = 0;
2372 if (win.mConfiguration != mCurConfiguration
2373 && (win.mConfiguration == null
2374 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2375 win.mConfiguration = mCurConfiguration;
2376 if (DEBUG_CONFIGURATION) {
2377 Slog.i(TAG, "Window " + win + " visible with new config: "
2378 + win.mConfiguration + " / 0x"
2379 + Integer.toHexString(diff));
2380 }
2381 outConfig.setTo(mCurConfiguration);
2382 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2385 // To change the format, we need to re-build the surface.
2386 win.destroySurfaceLocked();
2387 displayed = true;
2388 }
2389 try {
2390 Surface surface = win.createSurfaceLocked();
2391 if (surface != null) {
2392 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002393 win.mReportDestroySurface = false;
2394 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002395 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002396 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002398 // For some reason there isn't a surface. Clear the
2399 // caller's object so they see the same state.
2400 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 }
2402 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002403 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002404 + client + " (" + win.mAttrs.getTitle() + ")",
2405 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 Binder.restoreCallingIdentity(origId);
2407 return 0;
2408 }
2409 if (displayed) {
2410 focusMayChange = true;
2411 }
2412 if (win.mAttrs.type == TYPE_INPUT_METHOD
2413 && mInputMethodWindow == null) {
2414 mInputMethodWindow = win;
2415 imMayMove = true;
2416 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002417 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2418 && win.mAppToken != null
2419 && win.mAppToken.startingWindow != null) {
2420 // Special handling of starting window over the base
2421 // window of the app: propagate lock screen flags to it,
2422 // to provide the correct semantics while starting.
2423 final int mask =
2424 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002425 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2426 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002427 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2428 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 } else {
2431 win.mEnterAnimationPending = false;
2432 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002433 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002434 + ": mExiting=" + win.mExiting
2435 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 // If we are not currently running the exit animation, we
2437 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002438 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 // Try starting an animation; if there isn't one, we
2440 // can destroy the surface right away.
2441 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2442 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2443 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2444 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002445 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002447 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 win.mExiting = true;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002449 mInputMonitor.windowIsBecomingInvisibleLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 } else if (win.isAnimating()) {
2451 // Currently in a hide animation... turn this into
2452 // an exit.
2453 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002454 } else if (win == mWallpaperTarget) {
2455 // If the wallpaper is currently behind this
2456 // window, we need to change both of them inside
2457 // of a transaction to avoid artifacts.
2458 win.mExiting = true;
2459 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 } else {
2461 if (mInputMethodWindow == win) {
2462 mInputMethodWindow = null;
2463 }
2464 win.destroySurfaceLocked();
2465 }
2466 }
2467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002468
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002469 if (win.mSurface == null || (win.getAttrs().flags
2470 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2471 || win.mSurfacePendingDestroy) {
2472 // We are being called from a local process, which
2473 // means outSurface holds its current surface. Ensure the
2474 // surface object is cleared, but we don't want it actually
2475 // destroyed at this point.
2476 win.mSurfacePendingDestroy = false;
2477 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002478 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002479 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002480 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002481 "Keeping surface, will report destroy: " + win);
2482 win.mReportDestroySurface = true;
2483 outSurface.copyFrom(win.mSurface);
2484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 }
2486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 if (focusMayChange) {
2488 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2489 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 imMayMove = false;
2491 }
2492 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2493 }
Romain Guy06882f82009-06-10 13:36:04 -07002494
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002495 // updateFocusedWindowLocked() already assigned layers so we only need to
2496 // reassign them at this point if the IM window state gets shuffled
2497 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002500 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2501 // Little hack here -- we -should- be able to rely on the
2502 // function to return true if the IME has moved and needs
2503 // its layer recomputed. However, if the IME was hidden
2504 // and isn't actually moved in the list, its layer may be
2505 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 assignLayers = true;
2507 }
2508 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002509 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002510 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002511 assignLayers = true;
2512 }
2513 }
Romain Guy06882f82009-06-10 13:36:04 -07002514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 mLayoutNeeded = true;
2516 win.mGivenInsetsPending = insetsPending;
2517 if (assignLayers) {
2518 assignLayersLocked();
2519 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002520 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002522 if (displayed && win.mIsWallpaper) {
2523 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002524 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002525 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 if (win.mAppToken != null) {
2527 win.mAppToken.updateReportedVisibilityLocked();
2528 }
2529 outFrame.set(win.mFrame);
2530 outContentInsets.set(win.mContentInsets);
2531 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002532 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002534 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 + ", requestedHeight=" + requestedHeight
2536 + ", viewVisibility=" + viewVisibility
2537 + "\nRelayout returning frame=" + outFrame
2538 + ", surface=" + outSurface);
2539
Joe Onorato8a9b2202010-02-26 18:56:32 -08002540 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2542
2543 inTouchMode = mInTouchMode;
2544 }
2545
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002546 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 sendNewConfiguration();
2548 }
Romain Guy06882f82009-06-10 13:36:04 -07002549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2553 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2554 }
2555
2556 public void finishDrawingWindow(Session session, IWindow client) {
2557 final long origId = Binder.clearCallingIdentity();
2558 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002559 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002561 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2562 adjustWallpaperWindowsLocked();
2563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 mLayoutNeeded = true;
2565 performLayoutAndPlaceSurfacesLocked();
2566 }
2567 }
2568 Binder.restoreCallingIdentity(origId);
2569 }
2570
2571 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002572 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 + (lp != null ? lp.packageName : null)
2574 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2575 if (lp != null && lp.windowAnimations != 0) {
2576 // If this is a system resource, don't try to load it from the
2577 // application resources. It is nice to avoid loading application
2578 // resources if we can.
2579 String packageName = lp.packageName != null ? lp.packageName : "android";
2580 int resId = lp.windowAnimations;
2581 if ((resId&0xFF000000) == 0x01000000) {
2582 packageName = "android";
2583 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002584 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 + packageName);
2586 return AttributeCache.instance().get(packageName, resId,
2587 com.android.internal.R.styleable.WindowAnimation);
2588 }
2589 return null;
2590 }
Romain Guy06882f82009-06-10 13:36:04 -07002591
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002592 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002593 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002594 + packageName + " resId=0x" + Integer.toHexString(resId));
2595 if (packageName != null) {
2596 if ((resId&0xFF000000) == 0x01000000) {
2597 packageName = "android";
2598 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002599 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002600 + packageName);
2601 return AttributeCache.instance().get(packageName, resId,
2602 com.android.internal.R.styleable.WindowAnimation);
2603 }
2604 return null;
2605 }
2606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 private void applyEnterAnimationLocked(WindowState win) {
2608 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2609 if (win.mEnterAnimationPending) {
2610 win.mEnterAnimationPending = false;
2611 transit = WindowManagerPolicy.TRANSIT_ENTER;
2612 }
2613
2614 applyAnimationLocked(win, transit, true);
2615 }
2616
2617 private boolean applyAnimationLocked(WindowState win,
2618 int transit, boolean isEntrance) {
2619 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2620 // If we are trying to apply an animation, but already running
2621 // an animation of the same type, then just leave that one alone.
2622 return true;
2623 }
Romain Guy06882f82009-06-10 13:36:04 -07002624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 // Only apply an animation if the display isn't frozen. If it is
2626 // frozen, there is no reason to animate and it can cause strange
2627 // artifacts when we unfreeze the display if some different animation
2628 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002629 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002630 int anim = mPolicy.selectAnimationLw(win, transit);
2631 int attr = -1;
2632 Animation a = null;
2633 if (anim != 0) {
2634 a = AnimationUtils.loadAnimation(mContext, anim);
2635 } else {
2636 switch (transit) {
2637 case WindowManagerPolicy.TRANSIT_ENTER:
2638 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2639 break;
2640 case WindowManagerPolicy.TRANSIT_EXIT:
2641 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2642 break;
2643 case WindowManagerPolicy.TRANSIT_SHOW:
2644 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2645 break;
2646 case WindowManagerPolicy.TRANSIT_HIDE:
2647 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2648 break;
2649 }
2650 if (attr >= 0) {
2651 a = loadAnimation(win.mAttrs, attr);
2652 }
2653 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002654 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2656 + " mAnimation=" + win.mAnimation
2657 + " isEntrance=" + isEntrance);
2658 if (a != null) {
2659 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002660 RuntimeException e = null;
2661 if (!HIDE_STACK_CRAWLS) {
2662 e = new RuntimeException();
2663 e.fillInStackTrace();
2664 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002665 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 }
2667 win.setAnimation(a);
2668 win.mAnimationIsEntrance = isEntrance;
2669 }
2670 } else {
2671 win.clearAnimation();
2672 }
2673
2674 return win.mAnimation != null;
2675 }
2676
2677 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2678 int anim = 0;
2679 Context context = mContext;
2680 if (animAttr >= 0) {
2681 AttributeCache.Entry ent = getCachedAnimations(lp);
2682 if (ent != null) {
2683 context = ent.context;
2684 anim = ent.array.getResourceId(animAttr, 0);
2685 }
2686 }
2687 if (anim != 0) {
2688 return AnimationUtils.loadAnimation(context, anim);
2689 }
2690 return null;
2691 }
Romain Guy06882f82009-06-10 13:36:04 -07002692
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002693 private Animation loadAnimation(String packageName, int resId) {
2694 int anim = 0;
2695 Context context = mContext;
2696 if (resId >= 0) {
2697 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2698 if (ent != null) {
2699 context = ent.context;
2700 anim = resId;
2701 }
2702 }
2703 if (anim != 0) {
2704 return AnimationUtils.loadAnimation(context, anim);
2705 }
2706 return null;
2707 }
2708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 private boolean applyAnimationLocked(AppWindowToken wtoken,
2710 WindowManager.LayoutParams lp, int transit, boolean enter) {
2711 // Only apply an animation if the display isn't frozen. If it is
2712 // frozen, there is no reason to animate and it can cause strange
2713 // artifacts when we unfreeze the display if some different animation
2714 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002715 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002716 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002717 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002718 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002719 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002720 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002721 } else if (mNextAppTransitionPackage != null) {
2722 a = loadAnimation(mNextAppTransitionPackage, enter ?
2723 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002724 } else {
2725 int animAttr = 0;
2726 switch (transit) {
2727 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2728 animAttr = enter
2729 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2730 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2731 break;
2732 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2733 animAttr = enter
2734 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2735 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2736 break;
2737 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2738 animAttr = enter
2739 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2740 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2741 break;
2742 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2743 animAttr = enter
2744 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2745 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2746 break;
2747 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2748 animAttr = enter
2749 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2750 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2751 break;
2752 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2753 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002754 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002755 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2756 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002757 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002758 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002759 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2760 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002761 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002762 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002763 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002764 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2765 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2766 break;
2767 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2768 animAttr = enter
2769 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2770 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2771 break;
2772 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2773 animAttr = enter
2774 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2775 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002776 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002777 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002778 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002779 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002780 + " anim=" + a
2781 + " animAttr=0x" + Integer.toHexString(animAttr)
2782 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 if (a != null) {
2785 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002786 RuntimeException e = null;
2787 if (!HIDE_STACK_CRAWLS) {
2788 e = new RuntimeException();
2789 e.fillInStackTrace();
2790 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002791 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 }
2793 wtoken.setAnimation(a);
2794 }
2795 } else {
2796 wtoken.clearAnimation();
2797 }
2798
2799 return wtoken.animation != null;
2800 }
2801
2802 // -------------------------------------------------------------
2803 // Application Window Tokens
2804 // -------------------------------------------------------------
2805
2806 public void validateAppTokens(List tokens) {
2807 int v = tokens.size()-1;
2808 int m = mAppTokens.size()-1;
2809 while (v >= 0 && m >= 0) {
2810 AppWindowToken wtoken = mAppTokens.get(m);
2811 if (wtoken.removed) {
2812 m--;
2813 continue;
2814 }
2815 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002816 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002817 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2818 }
2819 v--;
2820 m--;
2821 }
2822 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002823 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 v--;
2825 }
2826 while (m >= 0) {
2827 AppWindowToken wtoken = mAppTokens.get(m);
2828 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002829 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 }
2831 m--;
2832 }
2833 }
2834
2835 boolean checkCallingPermission(String permission, String func) {
2836 // Quick check: if the calling permission is me, it's all okay.
2837 if (Binder.getCallingPid() == Process.myPid()) {
2838 return true;
2839 }
Romain Guy06882f82009-06-10 13:36:04 -07002840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 if (mContext.checkCallingPermission(permission)
2842 == PackageManager.PERMISSION_GRANTED) {
2843 return true;
2844 }
2845 String msg = "Permission Denial: " + func + " from pid="
2846 + Binder.getCallingPid()
2847 + ", uid=" + Binder.getCallingUid()
2848 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002849 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 return false;
2851 }
Romain Guy06882f82009-06-10 13:36:04 -07002852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 AppWindowToken findAppWindowToken(IBinder token) {
2854 WindowToken wtoken = mTokenMap.get(token);
2855 if (wtoken == null) {
2856 return null;
2857 }
2858 return wtoken.appWindowToken;
2859 }
Romain Guy06882f82009-06-10 13:36:04 -07002860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 public void addWindowToken(IBinder token, int type) {
2862 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2863 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002864 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 }
Romain Guy06882f82009-06-10 13:36:04 -07002866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 synchronized(mWindowMap) {
2868 WindowToken wtoken = mTokenMap.get(token);
2869 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002870 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 return;
2872 }
2873 wtoken = new WindowToken(token, type, true);
2874 mTokenMap.put(token, wtoken);
2875 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002876 if (type == TYPE_WALLPAPER) {
2877 mWallpaperTokens.add(wtoken);
2878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 }
2880 }
Romain Guy06882f82009-06-10 13:36:04 -07002881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 public void removeWindowToken(IBinder token) {
2883 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2884 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002885 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 }
2887
2888 final long origId = Binder.clearCallingIdentity();
2889 synchronized(mWindowMap) {
2890 WindowToken wtoken = mTokenMap.remove(token);
2891 mTokenList.remove(wtoken);
2892 if (wtoken != null) {
2893 boolean delayed = false;
2894 if (!wtoken.hidden) {
2895 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 final int N = wtoken.windows.size();
2898 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 for (int i=0; i<N; i++) {
2901 WindowState win = wtoken.windows.get(i);
2902
2903 if (win.isAnimating()) {
2904 delayed = true;
2905 }
Romain Guy06882f82009-06-10 13:36:04 -07002906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 if (win.isVisibleNow()) {
2908 applyAnimationLocked(win,
2909 WindowManagerPolicy.TRANSIT_EXIT, false);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002910 mInputMonitor.windowIsBeingRemovedLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 changed = true;
2912 }
2913 }
2914
2915 if (changed) {
2916 mLayoutNeeded = true;
2917 performLayoutAndPlaceSurfacesLocked();
2918 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2919 }
Romain Guy06882f82009-06-10 13:36:04 -07002920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 if (delayed) {
2922 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002923 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2924 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 }
2926 }
Romain Guy06882f82009-06-10 13:36:04 -07002927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002929 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 }
2931 }
2932 Binder.restoreCallingIdentity(origId);
2933 }
2934
2935 public void addAppToken(int addPos, IApplicationToken token,
2936 int groupId, int requestedOrientation, boolean fullscreen) {
2937 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2938 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002939 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 }
Jeff Brown349703e2010-06-22 01:27:15 -07002941
2942 // Get the dispatching timeout here while we are not holding any locks so that it
2943 // can be cached by the AppWindowToken. The timeout value is used later by the
2944 // input dispatcher in code that does hold locks. If we did not cache the value
2945 // here we would run the chance of introducing a deadlock between the window manager
2946 // (which holds locks while updating the input dispatcher state) and the activity manager
2947 // (which holds locks while querying the application token).
2948 long inputDispatchingTimeoutNanos;
2949 try {
2950 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2951 } catch (RemoteException ex) {
2952 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2953 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2954 }
Romain Guy06882f82009-06-10 13:36:04 -07002955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 synchronized(mWindowMap) {
2957 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2958 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002959 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 return;
2961 }
2962 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002963 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 wtoken.groupId = groupId;
2965 wtoken.appFullscreen = fullscreen;
2966 wtoken.requestedOrientation = requestedOrientation;
2967 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002968 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 mTokenMap.put(token.asBinder(), wtoken);
2970 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 // Application tokens start out hidden.
2973 wtoken.hidden = true;
2974 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 //dump();
2977 }
2978 }
Romain Guy06882f82009-06-10 13:36:04 -07002979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 public void setAppGroupId(IBinder token, int groupId) {
2981 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2982 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002983 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 }
2985
2986 synchronized(mWindowMap) {
2987 AppWindowToken wtoken = findAppWindowToken(token);
2988 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002989 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002990 return;
2991 }
2992 wtoken.groupId = groupId;
2993 }
2994 }
Romain Guy06882f82009-06-10 13:36:04 -07002995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 public int getOrientationFromWindowsLocked() {
2997 int pos = mWindows.size() - 1;
2998 while (pos >= 0) {
2999 WindowState wtoken = (WindowState) mWindows.get(pos);
3000 pos--;
3001 if (wtoken.mAppToken != null) {
3002 // We hit an application window. so the orientation will be determined by the
3003 // app window. No point in continuing further.
3004 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3005 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003006 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 continue;
3008 }
3009 int req = wtoken.mAttrs.screenOrientation;
3010 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3011 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3012 continue;
3013 } else {
3014 return req;
3015 }
3016 }
3017 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3018 }
Romain Guy06882f82009-06-10 13:36:04 -07003019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003020 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003021 int pos = mAppTokens.size() - 1;
3022 int curGroup = 0;
3023 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3024 boolean findingBehind = false;
3025 boolean haveGroup = false;
3026 boolean lastFullscreen = false;
3027 while (pos >= 0) {
3028 AppWindowToken wtoken = mAppTokens.get(pos);
3029 pos--;
3030 // if we're about to tear down this window and not seek for
3031 // the behind activity, don't use it for orientation
3032 if (!findingBehind
3033 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3034 continue;
3035 }
3036
3037 if (!haveGroup) {
3038 // We ignore any hidden applications on the top.
3039 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003040 continue;
3041 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003042 haveGroup = true;
3043 curGroup = wtoken.groupId;
3044 lastOrientation = wtoken.requestedOrientation;
3045 } else if (curGroup != wtoken.groupId) {
3046 // If we have hit a new application group, and the bottom
3047 // of the previous group didn't explicitly say to use
3048 // the orientation behind it, and the last app was
3049 // full screen, then we'll stick with the
3050 // user's orientation.
3051 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3052 && lastFullscreen) {
3053 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003054 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003055 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003056 int or = wtoken.requestedOrientation;
3057 // If this application is fullscreen, and didn't explicitly say
3058 // to use the orientation behind it, then just take whatever
3059 // orientation it has and ignores whatever is under it.
3060 lastFullscreen = wtoken.appFullscreen;
3061 if (lastFullscreen
3062 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3063 return or;
3064 }
3065 // If this application has requested an explicit orientation,
3066 // then use it.
3067 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3068 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3069 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3070 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3071 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3072 return or;
3073 }
3074 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3075 }
3076 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 }
Romain Guy06882f82009-06-10 13:36:04 -07003078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003080 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003081 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3082 "updateOrientationFromAppTokens()")) {
3083 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3084 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003085
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003086 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003088
3089 synchronized(mWindowMap) {
3090 if (updateOrientationFromAppTokensLocked()) {
3091 if (freezeThisOneIfNeeded != null) {
3092 AppWindowToken wtoken = findAppWindowToken(
3093 freezeThisOneIfNeeded);
3094 if (wtoken != null) {
3095 startAppFreezingScreenLocked(wtoken,
3096 ActivityInfo.CONFIG_ORIENTATION);
3097 }
3098 }
3099 config = computeNewConfigurationLocked();
3100
3101 } else if (currentConfig != null) {
3102 // No obvious action we need to take, but if our current
3103 // state mismatches the activity maanager's, update it
3104 mTempConfiguration.setToDefaults();
3105 if (computeNewConfigurationLocked(mTempConfiguration)) {
3106 if (currentConfig.diff(mTempConfiguration) != 0) {
3107 mWaitingForConfig = true;
3108 mLayoutNeeded = true;
3109 startFreezingDisplayLocked();
3110 config = new Configuration(mTempConfiguration);
3111 }
3112 }
3113 }
3114 }
3115
Dianne Hackborncfaef692009-06-15 14:24:44 -07003116 Binder.restoreCallingIdentity(ident);
3117 return config;
3118 }
3119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003121 * Determine the new desired orientation of the display, returning
3122 * a non-null new Configuration if it has changed from the current
3123 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3124 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3125 * SCREEN. This will typically be done for you if you call
3126 * sendNewConfiguration().
3127 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 * The orientation is computed from non-application windows first. If none of
3129 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003130 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3132 * android.os.IBinder)
3133 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003134 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003135 if (mDisplayFrozen) {
3136 // If the display is frozen, some activities may be in the middle
3137 // of restarting, and thus have removed their old window. If the
3138 // window has the flag to hide the lock screen, then the lock screen
3139 // can re-appear and inflict its own orientation on us. Keep the
3140 // orientation stable until this all settles down.
3141 return false;
3142 }
3143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 long ident = Binder.clearCallingIdentity();
3146 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003147 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 mForcedAppOrientation = req;
3151 //send a message to Policy indicating orientation change to take
3152 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003153 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003154 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3155 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3156 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003157 }
3158 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003159
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003160 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 } finally {
3162 Binder.restoreCallingIdentity(ident);
3163 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 }
Romain Guy06882f82009-06-10 13:36:04 -07003165
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003166 int computeForcedAppOrientationLocked() {
3167 int req = getOrientationFromWindowsLocked();
3168 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3169 req = getOrientationFromAppTokensLocked();
3170 }
3171 return req;
3172 }
Romain Guy06882f82009-06-10 13:36:04 -07003173
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003174 public void setNewConfiguration(Configuration config) {
3175 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3176 "setNewConfiguration()")) {
3177 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3178 }
3179
3180 synchronized(mWindowMap) {
3181 mCurConfiguration = new Configuration(config);
3182 mWaitingForConfig = false;
3183 performLayoutAndPlaceSurfacesLocked();
3184 }
3185 }
3186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3188 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3189 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003190 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 }
Romain Guy06882f82009-06-10 13:36:04 -07003192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 synchronized(mWindowMap) {
3194 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3195 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003196 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 return;
3198 }
Romain Guy06882f82009-06-10 13:36:04 -07003199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 wtoken.requestedOrientation = requestedOrientation;
3201 }
3202 }
Romain Guy06882f82009-06-10 13:36:04 -07003203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204 public int getAppOrientation(IApplicationToken token) {
3205 synchronized(mWindowMap) {
3206 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3207 if (wtoken == null) {
3208 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3209 }
Romain Guy06882f82009-06-10 13:36:04 -07003210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 return wtoken.requestedOrientation;
3212 }
3213 }
Romain Guy06882f82009-06-10 13:36:04 -07003214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3216 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3217 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003218 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 }
3220
3221 synchronized(mWindowMap) {
3222 boolean changed = false;
3223 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003224 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 changed = mFocusedApp != null;
3226 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003227 if (changed) {
3228 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 } else {
3231 AppWindowToken newFocus = findAppWindowToken(token);
3232 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003233 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003234 return;
3235 }
3236 changed = mFocusedApp != newFocus;
3237 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003238 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003239 if (changed) {
3240 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 }
3243
3244 if (moveFocusNow && changed) {
3245 final long origId = Binder.clearCallingIdentity();
3246 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3247 Binder.restoreCallingIdentity(origId);
3248 }
3249 }
3250 }
3251
3252 public void prepareAppTransition(int transit) {
3253 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3254 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003255 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 }
Romain Guy06882f82009-06-10 13:36:04 -07003257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003259 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 TAG, "Prepare app transition: transit=" + transit
3261 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003262 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003263 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3264 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003266 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3267 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3268 // Opening a new task always supersedes a close for the anim.
3269 mNextAppTransition = transit;
3270 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3271 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3272 // Opening a new activity always supersedes a close for the anim.
3273 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 }
3275 mAppTransitionReady = false;
3276 mAppTransitionTimeout = false;
3277 mStartingIconInTransition = false;
3278 mSkipAppTransitionAnimation = false;
3279 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3280 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3281 5000);
3282 }
3283 }
3284 }
3285
3286 public int getPendingAppTransition() {
3287 return mNextAppTransition;
3288 }
Romain Guy06882f82009-06-10 13:36:04 -07003289
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003290 public void overridePendingAppTransition(String packageName,
3291 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003292 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003293 mNextAppTransitionPackage = packageName;
3294 mNextAppTransitionEnter = enterAnim;
3295 mNextAppTransitionExit = exitAnim;
3296 }
3297 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 public void executeAppTransition() {
3300 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3301 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003302 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 }
Romain Guy06882f82009-06-10 13:36:04 -07003304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003306 if (DEBUG_APP_TRANSITIONS) {
3307 RuntimeException e = new RuntimeException("here");
3308 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003309 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003310 + mNextAppTransition, e);
3311 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003312 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003313 mAppTransitionReady = true;
3314 final long origId = Binder.clearCallingIdentity();
3315 performLayoutAndPlaceSurfacesLocked();
3316 Binder.restoreCallingIdentity(origId);
3317 }
3318 }
3319 }
3320
3321 public void setAppStartingWindow(IBinder token, String pkg,
3322 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3323 IBinder transferFrom, boolean createIfNeeded) {
3324 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3325 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003326 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 }
3328
3329 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003330 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3332 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 AppWindowToken wtoken = findAppWindowToken(token);
3335 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003336 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 return;
3338 }
3339
3340 // If the display is frozen, we won't do anything until the
3341 // actual window is displayed so there is no reason to put in
3342 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003343 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 return;
3345 }
Romain Guy06882f82009-06-10 13:36:04 -07003346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 if (wtoken.startingData != null) {
3348 return;
3349 }
Romain Guy06882f82009-06-10 13:36:04 -07003350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003351 if (transferFrom != null) {
3352 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3353 if (ttoken != null) {
3354 WindowState startingWindow = ttoken.startingWindow;
3355 if (startingWindow != null) {
3356 if (mStartingIconInTransition) {
3357 // In this case, the starting icon has already
3358 // been displayed, so start letting windows get
3359 // shown immediately without any more transitions.
3360 mSkipAppTransitionAnimation = true;
3361 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003362 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 "Moving existing starting from " + ttoken
3364 + " to " + wtoken);
3365 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 // Transfer the starting window over to the new
3368 // token.
3369 wtoken.startingData = ttoken.startingData;
3370 wtoken.startingView = ttoken.startingView;
3371 wtoken.startingWindow = startingWindow;
3372 ttoken.startingData = null;
3373 ttoken.startingView = null;
3374 ttoken.startingWindow = null;
3375 ttoken.startingMoved = true;
3376 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003377 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003379 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003380 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003382 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 ttoken.windows.remove(startingWindow);
3384 ttoken.allAppWindows.remove(startingWindow);
3385 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 // Propagate other interesting state between the
3388 // tokens. If the old token is displayed, we should
3389 // immediately force the new one to be displayed. If
3390 // it is animating, we need to move that animation to
3391 // the new one.
3392 if (ttoken.allDrawn) {
3393 wtoken.allDrawn = true;
3394 }
3395 if (ttoken.firstWindowDrawn) {
3396 wtoken.firstWindowDrawn = true;
3397 }
3398 if (!ttoken.hidden) {
3399 wtoken.hidden = false;
3400 wtoken.hiddenRequested = false;
3401 wtoken.willBeHidden = false;
3402 }
3403 if (wtoken.clientHidden != ttoken.clientHidden) {
3404 wtoken.clientHidden = ttoken.clientHidden;
3405 wtoken.sendAppVisibilityToClients();
3406 }
3407 if (ttoken.animation != null) {
3408 wtoken.animation = ttoken.animation;
3409 wtoken.animating = ttoken.animating;
3410 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3411 ttoken.animation = null;
3412 ttoken.animLayerAdjustment = 0;
3413 wtoken.updateLayers();
3414 ttoken.updateLayers();
3415 }
Romain Guy06882f82009-06-10 13:36:04 -07003416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418 mLayoutNeeded = true;
3419 performLayoutAndPlaceSurfacesLocked();
3420 Binder.restoreCallingIdentity(origId);
3421 return;
3422 } else if (ttoken.startingData != null) {
3423 // The previous app was getting ready to show a
3424 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003425 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 "Moving pending starting from " + ttoken
3427 + " to " + wtoken);
3428 wtoken.startingData = ttoken.startingData;
3429 ttoken.startingData = null;
3430 ttoken.startingMoved = true;
3431 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3432 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3433 // want to process the message ASAP, before any other queued
3434 // messages.
3435 mH.sendMessageAtFrontOfQueue(m);
3436 return;
3437 }
3438 }
3439 }
3440
3441 // There is no existing starting window, and the caller doesn't
3442 // want us to create one, so that's it!
3443 if (!createIfNeeded) {
3444 return;
3445 }
Romain Guy06882f82009-06-10 13:36:04 -07003446
Dianne Hackborn284ac932009-08-28 10:34:25 -07003447 // If this is a translucent or wallpaper window, then don't
3448 // show a starting window -- the current effect (a full-screen
3449 // opaque starting window that fades away to the real contents
3450 // when it is ready) does not work for this.
3451 if (theme != 0) {
3452 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3453 com.android.internal.R.styleable.Window);
3454 if (ent.array.getBoolean(
3455 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3456 return;
3457 }
3458 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003459 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3460 return;
3461 }
3462 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003463 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3464 return;
3465 }
3466 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 mStartingIconInTransition = true;
3469 wtoken.startingData = new StartingData(
3470 pkg, theme, nonLocalizedLabel,
3471 labelRes, icon);
3472 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3473 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3474 // want to process the message ASAP, before any other queued
3475 // messages.
3476 mH.sendMessageAtFrontOfQueue(m);
3477 }
3478 }
3479
3480 public void setAppWillBeHidden(IBinder token) {
3481 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3482 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003483 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003484 }
3485
3486 AppWindowToken wtoken;
3487
3488 synchronized(mWindowMap) {
3489 wtoken = findAppWindowToken(token);
3490 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003491 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 -08003492 return;
3493 }
3494 wtoken.willBeHidden = true;
3495 }
3496 }
Romain Guy06882f82009-06-10 13:36:04 -07003497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3499 boolean visible, int transit, boolean performLayout) {
3500 boolean delayed = false;
3501
3502 if (wtoken.clientHidden == visible) {
3503 wtoken.clientHidden = !visible;
3504 wtoken.sendAppVisibilityToClients();
3505 }
Romain Guy06882f82009-06-10 13:36:04 -07003506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 wtoken.willBeHidden = false;
3508 if (wtoken.hidden == visible) {
3509 final int N = wtoken.allAppWindows.size();
3510 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003511 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3513 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003516
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003517 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 if (wtoken.animation == sDummyAnimation) {
3519 wtoken.animation = null;
3520 }
3521 applyAnimationLocked(wtoken, lp, transit, visible);
3522 changed = true;
3523 if (wtoken.animation != null) {
3524 delayed = runningAppAnimation = true;
3525 }
3526 }
Romain Guy06882f82009-06-10 13:36:04 -07003527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 for (int i=0; i<N; i++) {
3529 WindowState win = wtoken.allAppWindows.get(i);
3530 if (win == wtoken.startingWindow) {
3531 continue;
3532 }
3533
3534 if (win.isAnimating()) {
3535 delayed = true;
3536 }
Romain Guy06882f82009-06-10 13:36:04 -07003537
Joe Onorato8a9b2202010-02-26 18:56:32 -08003538 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 //win.dump(" ");
3540 if (visible) {
3541 if (!win.isVisibleNow()) {
3542 if (!runningAppAnimation) {
3543 applyAnimationLocked(win,
3544 WindowManagerPolicy.TRANSIT_ENTER, true);
3545 }
3546 changed = true;
3547 }
3548 } else if (win.isVisibleNow()) {
3549 if (!runningAppAnimation) {
3550 applyAnimationLocked(win,
3551 WindowManagerPolicy.TRANSIT_EXIT, false);
3552 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003553 mInputMonitor.windowIsBecomingInvisibleLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 changed = true;
3555 }
3556 }
3557
3558 wtoken.hidden = wtoken.hiddenRequested = !visible;
3559 if (!visible) {
3560 unsetAppFreezingScreenLocked(wtoken, true, true);
3561 } else {
3562 // If we are being set visible, and the starting window is
3563 // not yet displayed, then make sure it doesn't get displayed.
3564 WindowState swin = wtoken.startingWindow;
3565 if (swin != null && (swin.mDrawPending
3566 || swin.mCommitDrawPending)) {
3567 swin.mPolicyVisibility = false;
3568 swin.mPolicyVisibilityAfterAnim = false;
3569 }
3570 }
Romain Guy06882f82009-06-10 13:36:04 -07003571
Joe Onorato8a9b2202010-02-26 18:56:32 -08003572 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003573 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3574 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003575
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003576 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003578 if (performLayout) {
3579 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3580 performLayoutAndPlaceSurfacesLocked();
3581 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 }
3583 }
3584
3585 if (wtoken.animation != null) {
3586 delayed = true;
3587 }
Romain Guy06882f82009-06-10 13:36:04 -07003588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003589 return delayed;
3590 }
3591
3592 public void setAppVisibility(IBinder token, boolean visible) {
3593 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3594 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003595 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 }
3597
3598 AppWindowToken wtoken;
3599
3600 synchronized(mWindowMap) {
3601 wtoken = findAppWindowToken(token);
3602 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003603 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 return;
3605 }
3606
3607 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003608 RuntimeException e = null;
3609 if (!HIDE_STACK_CRAWLS) {
3610 e = new RuntimeException();
3611 e.fillInStackTrace();
3612 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003613 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 + "): mNextAppTransition=" + mNextAppTransition
3615 + " hidden=" + wtoken.hidden
3616 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3617 }
Romain Guy06882f82009-06-10 13:36:04 -07003618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 // If we are preparing an app transition, then delay changing
3620 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003621 if (!mDisplayFrozen && mPolicy.isScreenOn()
3622 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 // Already in requested state, don't do anything more.
3624 if (wtoken.hiddenRequested != visible) {
3625 return;
3626 }
3627 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003628
Joe Onorato8a9b2202010-02-26 18:56:32 -08003629 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 TAG, "Setting dummy animation on: " + wtoken);
3631 wtoken.setDummyAnimation();
3632 mOpeningApps.remove(wtoken);
3633 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003634 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 wtoken.inPendingTransaction = true;
3636 if (visible) {
3637 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 wtoken.startingDisplayed = false;
3639 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003640
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003641 // If the token is currently hidden (should be the
3642 // common case), then we need to set up to wait for
3643 // its windows to be ready.
3644 if (wtoken.hidden) {
3645 wtoken.allDrawn = false;
3646 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003647
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003648 if (wtoken.clientHidden) {
3649 // In the case where we are making an app visible
3650 // but holding off for a transition, we still need
3651 // to tell the client to make its windows visible so
3652 // they get drawn. Otherwise, we will wait on
3653 // performing the transition until all windows have
3654 // been drawn, they never will be, and we are sad.
3655 wtoken.clientHidden = false;
3656 wtoken.sendAppVisibilityToClients();
3657 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 }
3659 } else {
3660 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003661
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003662 // If the token is currently visible (should be the
3663 // common case), then set up to wait for it to be hidden.
3664 if (!wtoken.hidden) {
3665 wtoken.waitingToHide = true;
3666 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 }
3668 return;
3669 }
Romain Guy06882f82009-06-10 13:36:04 -07003670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003672 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 wtoken.updateReportedVisibilityLocked();
3674 Binder.restoreCallingIdentity(origId);
3675 }
3676 }
3677
3678 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3679 boolean unfreezeSurfaceNow, boolean force) {
3680 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003681 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 + " force=" + force);
3683 final int N = wtoken.allAppWindows.size();
3684 boolean unfrozeWindows = false;
3685 for (int i=0; i<N; i++) {
3686 WindowState w = wtoken.allAppWindows.get(i);
3687 if (w.mAppFreezing) {
3688 w.mAppFreezing = false;
3689 if (w.mSurface != null && !w.mOrientationChanging) {
3690 w.mOrientationChanging = true;
3691 }
3692 unfrozeWindows = true;
3693 }
3694 }
3695 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003696 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003697 wtoken.freezingScreen = false;
3698 mAppsFreezingScreen--;
3699 }
3700 if (unfreezeSurfaceNow) {
3701 if (unfrozeWindows) {
3702 mLayoutNeeded = true;
3703 performLayoutAndPlaceSurfacesLocked();
3704 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003705 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 }
3707 }
3708 }
Romain Guy06882f82009-06-10 13:36:04 -07003709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3711 int configChanges) {
3712 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003713 RuntimeException e = null;
3714 if (!HIDE_STACK_CRAWLS) {
3715 e = new RuntimeException();
3716 e.fillInStackTrace();
3717 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003718 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 + ": hidden=" + wtoken.hidden + " freezing="
3720 + wtoken.freezingScreen, e);
3721 }
3722 if (!wtoken.hiddenRequested) {
3723 if (!wtoken.freezingScreen) {
3724 wtoken.freezingScreen = true;
3725 mAppsFreezingScreen++;
3726 if (mAppsFreezingScreen == 1) {
3727 startFreezingDisplayLocked();
3728 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3729 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3730 5000);
3731 }
3732 }
3733 final int N = wtoken.allAppWindows.size();
3734 for (int i=0; i<N; i++) {
3735 WindowState w = wtoken.allAppWindows.get(i);
3736 w.mAppFreezing = true;
3737 }
3738 }
3739 }
Romain Guy06882f82009-06-10 13:36:04 -07003740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 public void startAppFreezingScreen(IBinder token, int configChanges) {
3742 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3743 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003744 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 }
3746
3747 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003748 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003749 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 return;
3751 }
Romain Guy06882f82009-06-10 13:36:04 -07003752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 AppWindowToken wtoken = findAppWindowToken(token);
3754 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003755 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 return;
3757 }
3758 final long origId = Binder.clearCallingIdentity();
3759 startAppFreezingScreenLocked(wtoken, configChanges);
3760 Binder.restoreCallingIdentity(origId);
3761 }
3762 }
Romain Guy06882f82009-06-10 13:36:04 -07003763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 public void stopAppFreezingScreen(IBinder token, boolean force) {
3765 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3766 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003767 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 }
3769
3770 synchronized(mWindowMap) {
3771 AppWindowToken wtoken = findAppWindowToken(token);
3772 if (wtoken == null || wtoken.appToken == null) {
3773 return;
3774 }
3775 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003776 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3778 unsetAppFreezingScreenLocked(wtoken, true, force);
3779 Binder.restoreCallingIdentity(origId);
3780 }
3781 }
Romain Guy06882f82009-06-10 13:36:04 -07003782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 public void removeAppToken(IBinder token) {
3784 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3785 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003786 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 }
3788
3789 AppWindowToken wtoken = null;
3790 AppWindowToken startingToken = null;
3791 boolean delayed = false;
3792
3793 final long origId = Binder.clearCallingIdentity();
3794 synchronized(mWindowMap) {
3795 WindowToken basewtoken = mTokenMap.remove(token);
3796 mTokenList.remove(basewtoken);
3797 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003798 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003799 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 wtoken.inPendingTransaction = false;
3801 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003802 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 if (mClosingApps.contains(wtoken)) {
3804 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003805 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003807 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003808 delayed = true;
3809 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003810 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 TAG, "Removing app " + wtoken + " delayed=" + delayed
3812 + " animation=" + wtoken.animation
3813 + " animating=" + wtoken.animating);
3814 if (delayed) {
3815 // set the token aside because it has an active animation to be finished
3816 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003817 } else {
3818 // Make sure there is no animation running on this token,
3819 // so any windows associated with it will be removed as
3820 // soon as their animations are complete
3821 wtoken.animation = null;
3822 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 }
3824 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003825 if (mLastEnterAnimToken == wtoken) {
3826 mLastEnterAnimToken = null;
3827 mLastEnterAnimParams = null;
3828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 wtoken.removed = true;
3830 if (wtoken.startingData != null) {
3831 startingToken = wtoken;
3832 }
3833 unsetAppFreezingScreenLocked(wtoken, true, true);
3834 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003835 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 mFocusedApp = null;
3837 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003838 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003839 }
3840 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003841 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 }
Romain Guy06882f82009-06-10 13:36:04 -07003843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 if (!delayed && wtoken != null) {
3845 wtoken.updateReportedVisibilityLocked();
3846 }
3847 }
3848 Binder.restoreCallingIdentity(origId);
3849
3850 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003851 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003852 + startingToken + ": app token removed");
3853 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3854 mH.sendMessage(m);
3855 }
3856 }
3857
3858 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3859 final int NW = token.windows.size();
3860 for (int i=0; i<NW; i++) {
3861 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003862 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003864 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 int j = win.mChildWindows.size();
3866 while (j > 0) {
3867 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003868 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003869 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003870 "Tmp removing child window " + cwin);
3871 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 }
3873 }
3874 return NW > 0;
3875 }
3876
3877 void dumpAppTokensLocked() {
3878 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003879 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003880 }
3881 }
Romain Guy06882f82009-06-10 13:36:04 -07003882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 void dumpWindowsLocked() {
3884 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003885 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 }
3887 }
Romain Guy06882f82009-06-10 13:36:04 -07003888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 private int findWindowOffsetLocked(int tokenPos) {
3890 final int NW = mWindows.size();
3891
3892 if (tokenPos >= mAppTokens.size()) {
3893 int i = NW;
3894 while (i > 0) {
3895 i--;
3896 WindowState win = (WindowState)mWindows.get(i);
3897 if (win.getAppToken() != null) {
3898 return i+1;
3899 }
3900 }
3901 }
3902
3903 while (tokenPos > 0) {
3904 // Find the first app token below the new position that has
3905 // a window displayed.
3906 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003907 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003908 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003909 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003910 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003911 "Skipping token -- currently sending to bottom");
3912 tokenPos--;
3913 continue;
3914 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003915 int i = wtoken.windows.size();
3916 while (i > 0) {
3917 i--;
3918 WindowState win = wtoken.windows.get(i);
3919 int j = win.mChildWindows.size();
3920 while (j > 0) {
3921 j--;
3922 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003923 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003924 for (int pos=NW-1; pos>=0; pos--) {
3925 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003926 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 "Found child win @" + (pos+1));
3928 return pos+1;
3929 }
3930 }
3931 }
3932 }
3933 for (int pos=NW-1; pos>=0; pos--) {
3934 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003935 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003936 return pos+1;
3937 }
3938 }
3939 }
3940 tokenPos--;
3941 }
3942
3943 return 0;
3944 }
3945
3946 private final int reAddWindowLocked(int index, WindowState win) {
3947 final int NCW = win.mChildWindows.size();
3948 boolean added = false;
3949 for (int j=0; j<NCW; j++) {
3950 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3951 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003952 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003953 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 mWindows.add(index, win);
3955 index++;
3956 added = true;
3957 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003958 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003959 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003960 mWindows.add(index, cwin);
3961 index++;
3962 }
3963 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003964 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003965 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 mWindows.add(index, win);
3967 index++;
3968 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003969 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 return index;
3971 }
Romain Guy06882f82009-06-10 13:36:04 -07003972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3974 final int NW = token.windows.size();
3975 for (int i=0; i<NW; i++) {
3976 index = reAddWindowLocked(index, token.windows.get(i));
3977 }
3978 return index;
3979 }
3980
3981 public void moveAppToken(int index, IBinder token) {
3982 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3983 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003984 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 }
3986
3987 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003988 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 if (DEBUG_REORDER) dumpAppTokensLocked();
3990 final AppWindowToken wtoken = findAppWindowToken(token);
3991 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003992 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 + token + " (" + wtoken + ")");
3994 return;
3995 }
3996 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003997 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004001 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 if (DEBUG_REORDER) dumpWindowsLocked();
4003 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004004 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 if (DEBUG_REORDER) dumpWindowsLocked();
4006 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004007 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 if (DEBUG_REORDER) dumpWindowsLocked();
4009 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 mLayoutNeeded = true;
4011 performLayoutAndPlaceSurfacesLocked();
4012 }
4013 Binder.restoreCallingIdentity(origId);
4014 }
4015 }
4016
4017 private void removeAppTokensLocked(List<IBinder> tokens) {
4018 // XXX This should be done more efficiently!
4019 // (take advantage of the fact that both lists should be
4020 // ordered in the same way.)
4021 int N = tokens.size();
4022 for (int i=0; i<N; i++) {
4023 IBinder token = tokens.get(i);
4024 final AppWindowToken wtoken = findAppWindowToken(token);
4025 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004026 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004027 + token + " (" + wtoken + ")");
4028 i--;
4029 N--;
4030 }
4031 }
4032 }
4033
Dianne Hackborna8f60182009-09-01 19:01:50 -07004034 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4035 boolean updateFocusAndLayout) {
4036 // First remove all of the windows from the list.
4037 tmpRemoveAppWindowsLocked(wtoken);
4038
4039 // Where to start adding?
4040 int pos = findWindowOffsetLocked(tokenPos);
4041
4042 // And now add them back at the correct place.
4043 pos = reAddAppWindowsLocked(pos, wtoken);
4044
4045 if (updateFocusAndLayout) {
4046 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4047 assignLayersLocked();
4048 }
4049 mLayoutNeeded = true;
4050 performLayoutAndPlaceSurfacesLocked();
4051 }
4052 }
4053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4055 // First remove all of the windows from the list.
4056 final int N = tokens.size();
4057 int i;
4058 for (i=0; i<N; i++) {
4059 WindowToken token = mTokenMap.get(tokens.get(i));
4060 if (token != null) {
4061 tmpRemoveAppWindowsLocked(token);
4062 }
4063 }
4064
4065 // Where to start adding?
4066 int pos = findWindowOffsetLocked(tokenPos);
4067
4068 // And now add them back at the correct place.
4069 for (i=0; i<N; i++) {
4070 WindowToken token = mTokenMap.get(tokens.get(i));
4071 if (token != null) {
4072 pos = reAddAppWindowsLocked(pos, token);
4073 }
4074 }
4075
Dianne Hackborna8f60182009-09-01 19:01:50 -07004076 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4077 assignLayersLocked();
4078 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004079 mLayoutNeeded = true;
4080 performLayoutAndPlaceSurfacesLocked();
4081
4082 //dump();
4083 }
4084
4085 public void moveAppTokensToTop(List<IBinder> tokens) {
4086 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4087 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004088 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004089 }
4090
4091 final long origId = Binder.clearCallingIdentity();
4092 synchronized(mWindowMap) {
4093 removeAppTokensLocked(tokens);
4094 final int N = tokens.size();
4095 for (int i=0; i<N; i++) {
4096 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4097 if (wt != null) {
4098 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004099 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004100 mToTopApps.remove(wt);
4101 mToBottomApps.remove(wt);
4102 mToTopApps.add(wt);
4103 wt.sendingToBottom = false;
4104 wt.sendingToTop = true;
4105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004106 }
4107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004108
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004109 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004110 moveAppWindowsLocked(tokens, mAppTokens.size());
4111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 }
4113 Binder.restoreCallingIdentity(origId);
4114 }
4115
4116 public void moveAppTokensToBottom(List<IBinder> tokens) {
4117 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4118 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004119 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004120 }
4121
4122 final long origId = Binder.clearCallingIdentity();
4123 synchronized(mWindowMap) {
4124 removeAppTokensLocked(tokens);
4125 final int N = tokens.size();
4126 int pos = 0;
4127 for (int i=0; i<N; i++) {
4128 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4129 if (wt != null) {
4130 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004131 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004132 mToTopApps.remove(wt);
4133 mToBottomApps.remove(wt);
4134 mToBottomApps.add(i, wt);
4135 wt.sendingToTop = false;
4136 wt.sendingToBottom = true;
4137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004138 pos++;
4139 }
4140 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004141
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004142 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004143 moveAppWindowsLocked(tokens, 0);
4144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 }
4146 Binder.restoreCallingIdentity(origId);
4147 }
4148
4149 // -------------------------------------------------------------
4150 // Misc IWindowSession methods
4151 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004152
Jim Miller284b62e2010-06-08 14:27:42 -07004153 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004154 {
Jim Miller284b62e2010-06-08 14:27:42 -07004155 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4156 // called before DevicePolicyManagerService has started.
4157 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4158 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4159 Context.DEVICE_POLICY_SERVICE);
4160 if (dpm != null) {
4161 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4162 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4163 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4164 }
Jim Millerd6b57052010-06-07 17:52:42 -07004165 }
Jim Miller284b62e2010-06-08 14:27:42 -07004166 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004167 }
4168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004170 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 != PackageManager.PERMISSION_GRANTED) {
4172 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4173 }
Jim Millerd6b57052010-06-07 17:52:42 -07004174
Jim Miller284b62e2010-06-08 14:27:42 -07004175 synchronized (mKeyguardTokenWatcher) {
4176 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004178 }
4179
4180 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004181 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 != PackageManager.PERMISSION_GRANTED) {
4183 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4184 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185
Jim Miller284b62e2010-06-08 14:27:42 -07004186 synchronized (mKeyguardTokenWatcher) {
4187 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004188
Jim Miller284b62e2010-06-08 14:27:42 -07004189 if (!mKeyguardTokenWatcher.isAcquired()) {
4190 // If we are the last one to reenable the keyguard wait until
4191 // we have actually finished reenabling until returning.
4192 // It is possible that reenableKeyguard() can be called before
4193 // the previous disableKeyguard() is handled, in which case
4194 // neither mKeyguardTokenWatcher.acquired() or released() would
4195 // be called. In that case mKeyguardDisabled will be false here
4196 // and we have nothing to wait for.
4197 while (mKeyguardDisabled) {
4198 try {
4199 mKeyguardTokenWatcher.wait();
4200 } catch (InterruptedException e) {
4201 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 }
4203 }
4204 }
4205 }
4206 }
4207
4208 /**
4209 * @see android.app.KeyguardManager#exitKeyguardSecurely
4210 */
4211 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004212 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 != PackageManager.PERMISSION_GRANTED) {
4214 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4215 }
4216 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4217 public void onKeyguardExitResult(boolean success) {
4218 try {
4219 callback.onKeyguardExitResult(success);
4220 } catch (RemoteException e) {
4221 // Client has died, we don't care.
4222 }
4223 }
4224 });
4225 }
4226
4227 public boolean inKeyguardRestrictedInputMode() {
4228 return mPolicy.inKeyguardRestrictedKeyInputMode();
4229 }
Romain Guy06882f82009-06-10 13:36:04 -07004230
Dianne Hackbornffa42482009-09-23 22:20:11 -07004231 public void closeSystemDialogs(String reason) {
4232 synchronized(mWindowMap) {
4233 for (int i=mWindows.size()-1; i>=0; i--) {
4234 WindowState w = (WindowState)mWindows.get(i);
4235 if (w.mSurface != null) {
4236 try {
4237 w.mClient.closeSystemDialogs(reason);
4238 } catch (RemoteException e) {
4239 }
4240 }
4241 }
4242 }
4243 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 static float fixScale(float scale) {
4246 if (scale < 0) scale = 0;
4247 else if (scale > 20) scale = 20;
4248 return Math.abs(scale);
4249 }
Romain Guy06882f82009-06-10 13:36:04 -07004250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 public void setAnimationScale(int which, float scale) {
4252 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4253 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004254 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 }
4256
4257 if (scale < 0) scale = 0;
4258 else if (scale > 20) scale = 20;
4259 scale = Math.abs(scale);
4260 switch (which) {
4261 case 0: mWindowAnimationScale = fixScale(scale); break;
4262 case 1: mTransitionAnimationScale = fixScale(scale); break;
4263 }
Romain Guy06882f82009-06-10 13:36:04 -07004264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 // Persist setting
4266 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4267 }
Romain Guy06882f82009-06-10 13:36:04 -07004268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 public void setAnimationScales(float[] scales) {
4270 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4271 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004272 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 }
4274
4275 if (scales != null) {
4276 if (scales.length >= 1) {
4277 mWindowAnimationScale = fixScale(scales[0]);
4278 }
4279 if (scales.length >= 2) {
4280 mTransitionAnimationScale = fixScale(scales[1]);
4281 }
4282 }
Romain Guy06882f82009-06-10 13:36:04 -07004283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 // Persist setting
4285 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4286 }
Romain Guy06882f82009-06-10 13:36:04 -07004287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 public float getAnimationScale(int which) {
4289 switch (which) {
4290 case 0: return mWindowAnimationScale;
4291 case 1: return mTransitionAnimationScale;
4292 }
4293 return 0;
4294 }
Romain Guy06882f82009-06-10 13:36:04 -07004295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 public float[] getAnimationScales() {
4297 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4298 }
Romain Guy06882f82009-06-10 13:36:04 -07004299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 public int getSwitchState(int sw) {
4301 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4302 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004303 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004305 return mInputManager.getSwitchState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 }
Romain Guy06882f82009-06-10 13:36:04 -07004307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 public int getSwitchStateForDevice(int devid, int sw) {
4309 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4310 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004311 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004313 return mInputManager.getSwitchState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004314 }
Romain Guy06882f82009-06-10 13:36:04 -07004315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 public int getScancodeState(int sw) {
4317 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4318 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004319 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004321 return mInputManager.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 }
Romain Guy06882f82009-06-10 13:36:04 -07004323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 public int getScancodeStateForDevice(int devid, int sw) {
4325 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4326 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004327 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004329 return mInputManager.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 }
Romain Guy06882f82009-06-10 13:36:04 -07004331
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004332 public int getTrackballScancodeState(int sw) {
4333 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4334 "getTrackballScancodeState()")) {
4335 throw new SecurityException("Requires READ_INPUT_STATE permission");
4336 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004337 return mInputManager.getTrackballScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004338 }
4339
4340 public int getDPadScancodeState(int sw) {
4341 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4342 "getDPadScancodeState()")) {
4343 throw new SecurityException("Requires READ_INPUT_STATE permission");
4344 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004345 return mInputManager.getDPadScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004346 }
4347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004348 public int getKeycodeState(int sw) {
4349 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4350 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004351 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004353 return mInputManager.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 }
Romain Guy06882f82009-06-10 13:36:04 -07004355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 public int getKeycodeStateForDevice(int devid, int sw) {
4357 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4358 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004359 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004361 return mInputManager.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 }
Romain Guy06882f82009-06-10 13:36:04 -07004363
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004364 public int getTrackballKeycodeState(int sw) {
4365 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4366 "getTrackballKeycodeState()")) {
4367 throw new SecurityException("Requires READ_INPUT_STATE permission");
4368 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004369 return mInputManager.getTrackballKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004370 }
4371
4372 public int getDPadKeycodeState(int sw) {
4373 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4374 "getDPadKeycodeState()")) {
4375 throw new SecurityException("Requires READ_INPUT_STATE permission");
4376 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004377 return mInputManager.getDPadKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004378 }
4379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004380 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004381 return mInputManager.hasKeys(keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 }
Romain Guy06882f82009-06-10 13:36:04 -07004383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 public void enableScreenAfterBoot() {
4385 synchronized(mWindowMap) {
4386 if (mSystemBooted) {
4387 return;
4388 }
4389 mSystemBooted = true;
4390 }
Romain Guy06882f82009-06-10 13:36:04 -07004391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004392 performEnableScreen();
4393 }
Romain Guy06882f82009-06-10 13:36:04 -07004394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 public void enableScreenIfNeededLocked() {
4396 if (mDisplayEnabled) {
4397 return;
4398 }
4399 if (!mSystemBooted) {
4400 return;
4401 }
4402 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4403 }
Romain Guy06882f82009-06-10 13:36:04 -07004404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004405 public void performEnableScreen() {
4406 synchronized(mWindowMap) {
4407 if (mDisplayEnabled) {
4408 return;
4409 }
4410 if (!mSystemBooted) {
4411 return;
4412 }
Romain Guy06882f82009-06-10 13:36:04 -07004413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004414 // Don't enable the screen until all existing windows
4415 // have been drawn.
4416 final int N = mWindows.size();
4417 for (int i=0; i<N; i++) {
4418 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004419 if (w.isVisibleLw() && !w.mObscured
4420 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004421 return;
4422 }
4423 }
Romain Guy06882f82009-06-10 13:36:04 -07004424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425 mDisplayEnabled = true;
4426 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004427 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 StringWriter sw = new StringWriter();
4429 PrintWriter pw = new PrintWriter(sw);
4430 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004431 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 }
4433 try {
4434 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4435 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004436 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 Parcel data = Parcel.obtain();
4438 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4439 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4440 data, null, 0);
4441 data.recycle();
4442 }
4443 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004444 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004445 }
4446 }
Romain Guy06882f82009-06-10 13:36:04 -07004447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004450 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004451 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4452 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 }
Romain Guy06882f82009-06-10 13:36:04 -07004454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 public void setInTouchMode(boolean mode) {
4456 synchronized(mWindowMap) {
4457 mInTouchMode = mode;
4458 }
4459 }
4460
Romain Guy06882f82009-06-10 13:36:04 -07004461 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004462 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004463 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004464 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004465 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 }
4467
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004468 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
Romain Guy06882f82009-06-10 13:36:04 -07004470
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004471 public void setRotationUnchecked(int rotation,
4472 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004473 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 long origId = Binder.clearCallingIdentity();
4477 boolean changed;
4478 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004479 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 }
Romain Guy06882f82009-06-10 13:36:04 -07004481
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004482 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 sendNewConfiguration();
4484 }
Romain Guy06882f82009-06-10 13:36:04 -07004485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 Binder.restoreCallingIdentity(origId);
4487 }
Romain Guy06882f82009-06-10 13:36:04 -07004488
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004489 /**
4490 * Apply a new rotation to the screen, respecting the requests of
4491 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4492 * re-evaluate the desired rotation.
4493 *
4494 * Returns null if the rotation has been changed. In this case YOU
4495 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4496 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004497 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 boolean changed;
4499 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4500 rotation = mRequestedRotation;
4501 } else {
4502 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004503 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004504 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004505 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004506 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004508 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004512 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 "Rotation changed to " + rotation
4514 + " from " + mRotation
4515 + " (forceApp=" + mForcedAppOrientation
4516 + ", req=" + mRequestedRotation + ")");
4517 mRotation = rotation;
4518 mWindowsFreezingScreen = true;
4519 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4520 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4521 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004522 mWaitingForConfig = true;
4523 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004524 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004525 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004526 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004528 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 }
4530 for (int i=mWindows.size()-1; i>=0; i--) {
4531 WindowState w = (WindowState)mWindows.get(i);
4532 if (w.mSurface != null) {
4533 w.mOrientationChanging = true;
4534 }
4535 }
4536 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4537 try {
4538 mRotationWatchers.get(i).onRotationChanged(rotation);
4539 } catch (RemoteException e) {
4540 }
4541 }
4542 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004544 return changed;
4545 }
Romain Guy06882f82009-06-10 13:36:04 -07004546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 public int getRotation() {
4548 return mRotation;
4549 }
4550
4551 public int watchRotation(IRotationWatcher watcher) {
4552 final IBinder watcherBinder = watcher.asBinder();
4553 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4554 public void binderDied() {
4555 synchronized (mWindowMap) {
4556 for (int i=0; i<mRotationWatchers.size(); i++) {
4557 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004558 IRotationWatcher removed = mRotationWatchers.remove(i);
4559 if (removed != null) {
4560 removed.asBinder().unlinkToDeath(this, 0);
4561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004562 i--;
4563 }
4564 }
4565 }
4566 }
4567 };
Romain Guy06882f82009-06-10 13:36:04 -07004568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004569 synchronized (mWindowMap) {
4570 try {
4571 watcher.asBinder().linkToDeath(dr, 0);
4572 mRotationWatchers.add(watcher);
4573 } catch (RemoteException e) {
4574 // Client died, no cleanup needed.
4575 }
Romain Guy06882f82009-06-10 13:36:04 -07004576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004577 return mRotation;
4578 }
4579 }
4580
4581 /**
4582 * Starts the view server on the specified port.
4583 *
4584 * @param port The port to listener to.
4585 *
4586 * @return True if the server was successfully started, false otherwise.
4587 *
4588 * @see com.android.server.ViewServer
4589 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4590 */
4591 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004592 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 return false;
4594 }
4595
4596 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4597 return false;
4598 }
4599
4600 if (port < 1024) {
4601 return false;
4602 }
4603
4604 if (mViewServer != null) {
4605 if (!mViewServer.isRunning()) {
4606 try {
4607 return mViewServer.start();
4608 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004609 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004610 }
4611 }
4612 return false;
4613 }
4614
4615 try {
4616 mViewServer = new ViewServer(this, port);
4617 return mViewServer.start();
4618 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004619 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004620 }
4621 return false;
4622 }
4623
Romain Guy06882f82009-06-10 13:36:04 -07004624 private boolean isSystemSecure() {
4625 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4626 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4627 }
4628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004629 /**
4630 * Stops the view server if it exists.
4631 *
4632 * @return True if the server stopped, false if it wasn't started or
4633 * couldn't be stopped.
4634 *
4635 * @see com.android.server.ViewServer
4636 */
4637 public boolean stopViewServer() {
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, "stopViewServer")) {
4643 return false;
4644 }
4645
4646 if (mViewServer != null) {
4647 return mViewServer.stop();
4648 }
4649 return false;
4650 }
4651
4652 /**
4653 * Indicates whether the view server is running.
4654 *
4655 * @return True if the server is running, false otherwise.
4656 *
4657 * @see com.android.server.ViewServer
4658 */
4659 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004660 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004661 return false;
4662 }
4663
4664 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4665 return false;
4666 }
4667
4668 return mViewServer != null && mViewServer.isRunning();
4669 }
4670
4671 /**
4672 * Lists all availble windows in the system. The listing is written in the
4673 * specified Socket's output stream with the following syntax:
4674 * windowHashCodeInHexadecimal windowName
4675 * Each line of the ouput represents a different window.
4676 *
4677 * @param client The remote client to send the listing to.
4678 * @return False if an error occured, true otherwise.
4679 */
4680 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004681 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 return false;
4683 }
4684
4685 boolean result = true;
4686
4687 Object[] windows;
4688 synchronized (mWindowMap) {
4689 windows = new Object[mWindows.size()];
4690 //noinspection unchecked
4691 windows = mWindows.toArray(windows);
4692 }
4693
4694 BufferedWriter out = null;
4695
4696 // Any uncaught exception will crash the system process
4697 try {
4698 OutputStream clientStream = client.getOutputStream();
4699 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4700
4701 final int count = windows.length;
4702 for (int i = 0; i < count; i++) {
4703 final WindowState w = (WindowState) windows[i];
4704 out.write(Integer.toHexString(System.identityHashCode(w)));
4705 out.write(' ');
4706 out.append(w.mAttrs.getTitle());
4707 out.write('\n');
4708 }
4709
4710 out.write("DONE.\n");
4711 out.flush();
4712 } catch (Exception e) {
4713 result = false;
4714 } finally {
4715 if (out != null) {
4716 try {
4717 out.close();
4718 } catch (IOException e) {
4719 result = false;
4720 }
4721 }
4722 }
4723
4724 return result;
4725 }
4726
4727 /**
4728 * Sends a command to a target window. The result of the command, if any, will be
4729 * written in the output stream of the specified socket.
4730 *
4731 * The parameters must follow this syntax:
4732 * windowHashcode extra
4733 *
4734 * Where XX is the length in characeters of the windowTitle.
4735 *
4736 * The first parameter is the target window. The window with the specified hashcode
4737 * will be the target. If no target can be found, nothing happens. The extra parameters
4738 * will be delivered to the target window and as parameters to the command itself.
4739 *
4740 * @param client The remote client to sent the result, if any, to.
4741 * @param command The command to execute.
4742 * @param parameters The command parameters.
4743 *
4744 * @return True if the command was successfully delivered, false otherwise. This does
4745 * not indicate whether the command itself was successful.
4746 */
4747 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004748 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004749 return false;
4750 }
4751
4752 boolean success = true;
4753 Parcel data = null;
4754 Parcel reply = null;
4755
4756 // Any uncaught exception will crash the system process
4757 try {
4758 // Find the hashcode of the window
4759 int index = parameters.indexOf(' ');
4760 if (index == -1) {
4761 index = parameters.length();
4762 }
4763 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004764 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004765
4766 // Extract the command's parameter after the window description
4767 if (index < parameters.length()) {
4768 parameters = parameters.substring(index + 1);
4769 } else {
4770 parameters = "";
4771 }
4772
4773 final WindowManagerService.WindowState window = findWindow(hashCode);
4774 if (window == null) {
4775 return false;
4776 }
4777
4778 data = Parcel.obtain();
4779 data.writeInterfaceToken("android.view.IWindow");
4780 data.writeString(command);
4781 data.writeString(parameters);
4782 data.writeInt(1);
4783 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4784
4785 reply = Parcel.obtain();
4786
4787 final IBinder binder = window.mClient.asBinder();
4788 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4789 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4790
4791 reply.readException();
4792
4793 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004794 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 success = false;
4796 } finally {
4797 if (data != null) {
4798 data.recycle();
4799 }
4800 if (reply != null) {
4801 reply.recycle();
4802 }
4803 }
4804
4805 return success;
4806 }
4807
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004808 public void addWindowChangeListener(WindowChangeListener listener) {
4809 synchronized(mWindowMap) {
4810 mWindowChangeListeners.add(listener);
4811 }
4812 }
4813
4814 public void removeWindowChangeListener(WindowChangeListener listener) {
4815 synchronized(mWindowMap) {
4816 mWindowChangeListeners.remove(listener);
4817 }
4818 }
4819
4820 private void notifyWindowsChanged() {
4821 WindowChangeListener[] windowChangeListeners;
4822 synchronized(mWindowMap) {
4823 if(mWindowChangeListeners.isEmpty()) {
4824 return;
4825 }
4826 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4827 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4828 }
4829 int N = windowChangeListeners.length;
4830 for(int i = 0; i < N; i++) {
4831 windowChangeListeners[i].windowsChanged();
4832 }
4833 }
4834
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004835 private void notifyFocusChanged() {
4836 WindowChangeListener[] windowChangeListeners;
4837 synchronized(mWindowMap) {
4838 if(mWindowChangeListeners.isEmpty()) {
4839 return;
4840 }
4841 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4842 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4843 }
4844 int N = windowChangeListeners.length;
4845 for(int i = 0; i < N; i++) {
4846 windowChangeListeners[i].focusChanged();
4847 }
4848 }
4849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 private WindowState findWindow(int hashCode) {
4851 if (hashCode == -1) {
4852 return getFocusedWindow();
4853 }
4854
4855 synchronized (mWindowMap) {
4856 final ArrayList windows = mWindows;
4857 final int count = windows.size();
4858
4859 for (int i = 0; i < count; i++) {
4860 WindowState w = (WindowState) windows.get(i);
4861 if (System.identityHashCode(w) == hashCode) {
4862 return w;
4863 }
4864 }
4865 }
4866
4867 return null;
4868 }
4869
4870 /*
4871 * Instruct the Activity Manager to fetch the current configuration and broadcast
4872 * that to config-changed listeners if appropriate.
4873 */
4874 void sendNewConfiguration() {
4875 try {
4876 mActivityManager.updateConfiguration(null);
4877 } catch (RemoteException e) {
4878 }
4879 }
Romain Guy06882f82009-06-10 13:36:04 -07004880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 public Configuration computeNewConfiguration() {
4882 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004883 return computeNewConfigurationLocked();
4884 }
4885 }
Romain Guy06882f82009-06-10 13:36:04 -07004886
Dianne Hackbornc485a602009-03-24 22:39:49 -07004887 Configuration computeNewConfigurationLocked() {
4888 Configuration config = new Configuration();
4889 if (!computeNewConfigurationLocked(config)) {
4890 return null;
4891 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004892 return config;
4893 }
Romain Guy06882f82009-06-10 13:36:04 -07004894
Dianne Hackbornc485a602009-03-24 22:39:49 -07004895 boolean computeNewConfigurationLocked(Configuration config) {
4896 if (mDisplay == null) {
4897 return false;
4898 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004899
4900 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004901
4902 // Use the effective "visual" dimensions based on current rotation
4903 final boolean rotated = (mRotation == Surface.ROTATION_90
4904 || mRotation == Surface.ROTATION_270);
4905 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4906 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4907
Dianne Hackbornc485a602009-03-24 22:39:49 -07004908 int orientation = Configuration.ORIENTATION_SQUARE;
4909 if (dw < dh) {
4910 orientation = Configuration.ORIENTATION_PORTRAIT;
4911 } else if (dw > dh) {
4912 orientation = Configuration.ORIENTATION_LANDSCAPE;
4913 }
4914 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004915
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004916 DisplayMetrics dm = new DisplayMetrics();
4917 mDisplay.getMetrics(dm);
4918 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4919
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004920 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004921 // Note we only do this once because at this point we don't
4922 // expect the screen to change in this way at runtime, and want
4923 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004924 int longSize = dw;
4925 int shortSize = dh;
4926 if (longSize < shortSize) {
4927 int tmp = longSize;
4928 longSize = shortSize;
4929 shortSize = tmp;
4930 }
4931 longSize = (int)(longSize/dm.density);
4932 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004933
Dianne Hackborn723738c2009-06-25 19:48:04 -07004934 // These semi-magic numbers define our compatibility modes for
4935 // applications with different screens. Don't change unless you
4936 // make sure to test lots and lots of apps!
4937 if (longSize < 470) {
4938 // This is shorter than an HVGA normal density screen (which
4939 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004940 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4941 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004942 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004943 // What size is this screen screen?
4944 if (longSize >= 800 && shortSize >= 600) {
4945 // SVGA or larger screens at medium density are the point
4946 // at which we consider it to be an extra large screen.
4947 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4948 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004949 // VGA or larger screens at medium density are the point
4950 // at which we consider it to be a large screen.
4951 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4952 } else {
4953 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004954
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004955 // If this screen is wider than normal HVGA, or taller
4956 // than FWVGA, then for old apps we want to run in size
4957 // compatibility mode.
4958 if (shortSize > 321 || longSize > 570) {
4959 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4960 }
4961 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004962
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004963 // Is this a long screen?
4964 if (((longSize*3)/5) >= (shortSize-1)) {
4965 // Anything wider than WVGA (5:3) is considering to be long.
4966 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4967 } else {
4968 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4969 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004970 }
4971 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004972 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004973
Dianne Hackbornc485a602009-03-24 22:39:49 -07004974 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4975 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4976 mPolicy.adjustConfigurationLw(config);
4977 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004978 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 // -------------------------------------------------------------
4981 // Input Events and Focus Management
4982 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07004983
Jeff Brown349703e2010-06-22 01:27:15 -07004984 InputMonitor mInputMonitor = new InputMonitor();
4985
4986 /* Tracks the progress of input dispatch and ensures that input dispatch state
4987 * is kept in sync with changes in window focus, visibility, registration, and
4988 * other relevant Window Manager state transitions. */
4989 final class InputMonitor {
4990 // Current window with input focus for keys and other non-touch events. May be null.
4991 private WindowState mInputFocus;
4992
4993 // When true, prevents input dispatch from proceeding until set to false again.
4994 private boolean mInputDispatchFrozen;
4995
4996 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
4997 private boolean mInputDispatchEnabled = true;
4998
4999 // Temporary list of windows information to provide to the input dispatcher.
5000 private InputWindowList mTempInputWindows = new InputWindowList();
5001
5002 // Temporary input application object to provide to the input dispatcher.
5003 private InputApplication mTempInputApplication = new InputApplication();
5004
5005 /* Notifies the window manager about a broken input channel.
5006 *
5007 * Called by the InputManager.
5008 */
5009 public void notifyInputChannelBroken(InputChannel inputChannel) {
5010 synchronized (mWindowMap) {
5011 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5012 if (windowState == null) {
5013 return; // irrelevant
5014 }
5015
5016 Slog.i(TAG, "WINDOW DIED " + windowState);
5017 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005018 }
5019 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005020
Jeff Brown349703e2010-06-22 01:27:15 -07005021 /* Notifies the window manager about an input channel that is not responding.
5022 * The method can either cause dispatching to be aborted by returning -2 or
5023 * return a new timeout in nanoseconds.
5024 *
5025 * Called by the InputManager.
5026 */
5027 public long notifyInputChannelANR(InputChannel inputChannel) {
5028 AppWindowToken token;
5029 synchronized (mWindowMap) {
5030 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5031 if (windowState == null) {
5032 return -2; // irrelevant, abort dispatching (-2)
5033 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005034
Jeff Brown349703e2010-06-22 01:27:15 -07005035 Slog.i(TAG, "Input event dispatching timed out sending to "
5036 + windowState.mAttrs.getTitle());
5037 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005038 }
5039
Jeff Brown349703e2010-06-22 01:27:15 -07005040 return notifyANRInternal(token);
5041 }
5042
5043 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5044 * by successfully delivering the event that originally timed out.
5045 *
5046 * Called by the InputManager.
5047 */
5048 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5049 // Nothing to do just now.
5050 // Just wait for the user to dismiss the ANR dialog.
5051 }
5052
5053 /* Notifies the window manager about an application that is not responding
5054 * in general rather than with respect to a particular input channel.
5055 * The method can either cause dispatching to be aborted by returning -2 or
5056 * return a new timeout in nanoseconds.
5057 *
5058 * Called by the InputManager.
5059 */
5060 public long notifyANR(Object token) {
5061 AppWindowToken appWindowToken = (AppWindowToken) token;
5062
5063 Slog.i(TAG, "Input event dispatching timed out sending to application "
5064 + appWindowToken.stringName);
5065 return notifyANRInternal(appWindowToken);
5066 }
5067
5068 private long notifyANRInternal(AppWindowToken token) {
5069 if (token != null && token.appToken != null) {
5070 try {
5071 // Notify the activity manager about the timeout and let it decide whether
5072 // to abort dispatching or keep waiting.
5073 boolean abort = token.appToken.keyDispatchingTimedOut();
5074 if (! abort) {
5075 // The activity manager declined to abort dispatching.
5076 // Wait a bit longer and timeout again later.
5077 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005078 }
Jeff Brown349703e2010-06-22 01:27:15 -07005079 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005080 }
5081 }
Jeff Brown349703e2010-06-22 01:27:15 -07005082 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005083 }
5084
Jeff Brown349703e2010-06-22 01:27:15 -07005085 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5086 synchronized (mWindowMap) {
5087 return getWindowStateForInputChannelLocked(inputChannel);
5088 }
5089 }
5090
5091 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5092 int windowCount = mWindows.size();
5093 for (int i = 0; i < windowCount; i++) {
5094 WindowState windowState = (WindowState) mWindows.get(i);
5095 if (windowState.mInputChannel == inputChannel) {
5096 return windowState;
5097 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005098 }
5099
Jeff Brown349703e2010-06-22 01:27:15 -07005100 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005101 }
5102
Jeff Brown349703e2010-06-22 01:27:15 -07005103 /* Updates the cached window information provided to the input dispatcher. */
5104 public void updateInputWindowsLw() {
5105 // Populate the input window list with information about all of the windows that
5106 // could potentially receive input.
5107 // As an optimization, we could try to prune the list of windows but this turns
5108 // out to be difficult because only the native code knows for sure which window
5109 // currently has touch focus.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005110 final ArrayList windows = mWindows;
5111 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005112 for (int i = N - 1; i >= 0; i--) {
5113 final WindowState child = (WindowState) windows.get(i);
5114 if (child.mInputChannel == null) {
5115 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005116 continue;
5117 }
5118
Jeff Brown349703e2010-06-22 01:27:15 -07005119 final int flags = child.mAttrs.flags;
5120 final int type = child.mAttrs.type;
5121
5122 final boolean hasFocus = (child == mInputFocus);
5123 final boolean isVisible = child.isVisibleLw();
5124 final boolean hasWallpaper = (child == mWallpaperTarget)
5125 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5126
5127 // Add a window to our list of input windows.
5128 final InputWindow inputWindow = mTempInputWindows.add();
5129 inputWindow.inputChannel = child.mInputChannel;
5130 inputWindow.layoutParamsFlags = flags;
5131 inputWindow.layoutParamsType = type;
5132 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5133 inputWindow.visible = isVisible;
5134 inputWindow.hasFocus = hasFocus;
5135 inputWindow.hasWallpaper = hasWallpaper;
5136 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5137 inputWindow.ownerPid = child.mSession.mPid;
5138 inputWindow.ownerUid = child.mSession.mUid;
5139
5140 final Rect frame = child.mFrame;
5141 inputWindow.frameLeft = frame.left;
5142 inputWindow.frameTop = frame.top;
5143
5144 switch (child.mTouchableInsets) {
5145 default:
5146 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5147 inputWindow.touchableAreaLeft = frame.left;
5148 inputWindow.touchableAreaTop = frame.top;
5149 inputWindow.touchableAreaRight = frame.right;
5150 inputWindow.touchableAreaBottom = frame.bottom;
5151 break;
5152
5153 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5154 Rect inset = child.mGivenContentInsets;
5155 inputWindow.touchableAreaLeft = frame.left + inset.left;
5156 inputWindow.touchableAreaTop = frame.top + inset.top;
5157 inputWindow.touchableAreaRight = frame.right - inset.right;
5158 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5159 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005160 }
Jeff Brown349703e2010-06-22 01:27:15 -07005161
5162 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5163 Rect inset = child.mGivenVisibleInsets;
5164 inputWindow.touchableAreaLeft = frame.left + inset.left;
5165 inputWindow.touchableAreaTop = frame.top + inset.top;
5166 inputWindow.touchableAreaRight = frame.right - inset.right;
5167 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005168 break;
5169 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005170 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005171 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005172
Jeff Brown349703e2010-06-22 01:27:15 -07005173 // Send windows to native code.
5174 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005175
Jeff Brown349703e2010-06-22 01:27:15 -07005176 // Clear the list in preparation for the next round.
5177 // Also avoids keeping InputChannel objects referenced unnecessarily.
5178 mTempInputWindows.clear();
5179 }
5180
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005181 /* Provides feedback for a virtual key down. */
5182 public void virtualKeyDownFeedback() {
5183 synchronized (mWindowMap) {
5184 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5185 }
5186 }
5187
Jeff Brown349703e2010-06-22 01:27:15 -07005188 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5189 * This essentially starts a .5 second timeout for the application to process
5190 * subsequent input events while waiting for the app switch to occur. If it takes longer
5191 * than this, the pending events will be dropped.
5192 */
5193 public void notifyAppSwitchComing() {
5194 // TODO Not implemented yet. Should go in the native side.
5195 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005196
5197 /* Notifies that the lid switch changed state. */
5198 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5199 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5200 }
5201
Jeff Brown349703e2010-06-22 01:27:15 -07005202 /* Provides an opportunity for the window manager policy to intercept early key
5203 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005204 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5205 int policyFlags, boolean isScreenOn) {
5206 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5207 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005208 }
5209
5210 /* Provides an opportunity for the window manager policy to process a key before
5211 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005212 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5213 int action, int flags, int keyCode, int metaState, int repeatCount,
5214 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005215 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005216 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5217 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005218 }
5219
5220 /* Called when the current input focus changes.
5221 * Layer assignment is assumed to be complete by the time this is called.
5222 */
5223 public void setInputFocusLw(WindowState newWindow) {
5224 if (DEBUG_INPUT) {
5225 Slog.d(TAG, "Input focus has changed to " + newWindow);
5226 }
5227
5228 if (newWindow != mInputFocus) {
5229 if (newWindow != null && newWindow.canReceiveKeys()) {
5230 // If the new input focus is an error window or appears above the current
5231 // input focus, preempt any pending synchronous dispatch so that we can
5232 // start delivering events to the new input focus as soon as possible.
5233 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5234 if (DEBUG_INPUT) {
5235 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005236 }
Jeff Brown349703e2010-06-22 01:27:15 -07005237 preemptInputDispatchLw();
5238 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5239 if (DEBUG_INPUT) {
5240 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5241 + "old win layer=" + mInputFocus.mLayer
5242 + ", new win layer=" + newWindow.mLayer);
5243 }
5244 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005245 }
Jeff Brown349703e2010-06-22 01:27:15 -07005246
5247 // Displaying a window implicitly causes dispatching to be unpaused.
5248 // This is to protect against bugs if someone pauses dispatching but
5249 // forgets to resume.
5250 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005251 }
Jeff Brown349703e2010-06-22 01:27:15 -07005252
5253 mInputFocus = newWindow;
5254 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005255 }
5256 }
5257
Jeff Brown349703e2010-06-22 01:27:15 -07005258 public void windowIsBecomingInvisibleLw(WindowState window) {
5259 // The window is becoming invisible. Preempt input dispatch in progress
5260 // so that the next window below can receive focus.
5261 if (window == mInputFocus) {
5262 mInputFocus = null;
5263 preemptInputDispatchLw();
5264 }
5265
5266 updateInputWindowsLw();
5267 }
5268
5269 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5270 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5271 * can begin.
5272 */
5273 private void preemptInputDispatchLw() {
5274 mInputManager.preemptInputDispatch();
5275 }
5276
5277 public void setFocusedAppLw(AppWindowToken newApp) {
5278 // Focused app has changed.
5279 if (newApp == null) {
5280 mInputManager.setFocusedApplication(null);
5281 } else {
5282 mTempInputApplication.name = newApp.toString();
5283 mTempInputApplication.dispatchingTimeoutNanos =
5284 newApp.inputDispatchingTimeoutNanos;
5285 mTempInputApplication.token = newApp;
5286
5287 mInputManager.setFocusedApplication(mTempInputApplication);
5288 }
5289 }
5290
5291 public void windowIsBeingRemovedLw(WindowState window) {
5292 // Window is being removed.
5293 updateInputWindowsLw();
5294 }
5295
5296 public void pauseDispatchingLw(WindowToken window) {
5297 if (! window.paused) {
5298 if (DEBUG_INPUT) {
5299 Slog.v(TAG, "Pausing WindowToken " + window);
5300 }
5301
5302 window.paused = true;
5303 updateInputWindowsLw();
5304 }
5305 }
5306
5307 public void resumeDispatchingLw(WindowToken window) {
5308 if (window.paused) {
5309 if (DEBUG_INPUT) {
5310 Slog.v(TAG, "Resuming WindowToken " + window);
5311 }
5312
5313 window.paused = false;
5314 updateInputWindowsLw();
5315 }
5316 }
5317
5318 public void freezeInputDispatchingLw() {
5319 if (! mInputDispatchFrozen) {
5320 if (DEBUG_INPUT) {
5321 Slog.v(TAG, "Freezing input dispatching");
5322 }
5323
5324 mInputDispatchFrozen = true;
5325 updateInputDispatchModeLw();
5326 }
5327 }
5328
5329 public void thawInputDispatchingLw() {
5330 if (mInputDispatchFrozen) {
5331 if (DEBUG_INPUT) {
5332 Slog.v(TAG, "Thawing input dispatching");
5333 }
5334
5335 mInputDispatchFrozen = false;
5336 updateInputDispatchModeLw();
5337 }
5338 }
5339
5340 public void setEventDispatchingLw(boolean enabled) {
5341 if (mInputDispatchEnabled != enabled) {
5342 if (DEBUG_INPUT) {
5343 Slog.v(TAG, "Setting event dispatching to " + enabled);
5344 }
5345
5346 mInputDispatchEnabled = enabled;
5347 updateInputDispatchModeLw();
5348 }
5349 }
5350
5351 private void updateInputDispatchModeLw() {
5352 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5353 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005354 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005356 public void pauseKeyDispatching(IBinder _token) {
5357 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5358 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005359 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005360 }
5361
5362 synchronized (mWindowMap) {
5363 WindowToken token = mTokenMap.get(_token);
5364 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005365 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005366 }
5367 }
5368 }
5369
5370 public void resumeKeyDispatching(IBinder _token) {
5371 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5372 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005373 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374 }
5375
5376 synchronized (mWindowMap) {
5377 WindowToken token = mTokenMap.get(_token);
5378 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005379 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 }
5381 }
5382 }
5383
5384 public void setEventDispatching(boolean enabled) {
5385 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5386 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005387 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005388 }
5389
5390 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005391 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005392 }
5393 }
Romain Guy06882f82009-06-10 13:36:04 -07005394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005395 /**
5396 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005397 *
5398 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005399 * {@link SystemClock#uptimeMillis()} as the timebase.)
5400 * @param sync If true, wait for the event to be completed before returning to the caller.
5401 * @return Returns true if event was dispatched, false if it was dropped for any reason
5402 */
5403 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5404 long downTime = ev.getDownTime();
5405 long eventTime = ev.getEventTime();
5406
5407 int action = ev.getAction();
5408 int code = ev.getKeyCode();
5409 int repeatCount = ev.getRepeatCount();
5410 int metaState = ev.getMetaState();
5411 int deviceId = ev.getDeviceId();
5412 int scancode = ev.getScanCode();
5413
5414 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5415 if (downTime == 0) downTime = eventTime;
5416
5417 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005418 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005419
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005420 final int pid = Binder.getCallingPid();
5421 final int uid = Binder.getCallingUid();
5422 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005423
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005424 final int result = mInputManager.injectKeyEvent(newEvent,
5425 InputQueue.INPUT_EVENT_NATURE_KEY, pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005426
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005427 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005428 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005429 }
5430
5431 /**
5432 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005433 *
5434 * @param ev A motion event describing the pointer (touch) action. (As noted in
5435 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 * {@link SystemClock#uptimeMillis()} as the timebase.)
5437 * @param sync If true, wait for the event to be completed before returning to the caller.
5438 * @return Returns true if event was dispatched, false if it was dropped for any reason
5439 */
5440 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005441 final int pid = Binder.getCallingPid();
5442 final int uid = Binder.getCallingUid();
5443 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005444
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005445 final int result = mInputManager.injectMotionEvent(ev,
5446 InputQueue.INPUT_EVENT_NATURE_TOUCH, pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005447
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005448 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005449 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005450 }
Romain Guy06882f82009-06-10 13:36:04 -07005451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005452 /**
5453 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005454 *
5455 * @param ev A motion event describing the trackball action. (As noted in
5456 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 * {@link SystemClock#uptimeMillis()} as the timebase.)
5458 * @param sync If true, wait for the event to be completed before returning to the caller.
5459 * @return Returns true if event was dispatched, false if it was dropped for any reason
5460 */
5461 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005462 final int pid = Binder.getCallingPid();
5463 final int uid = Binder.getCallingUid();
5464 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005465
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005466 final int result = mInputManager.injectMotionEvent(ev,
5467 InputQueue.INPUT_EVENT_NATURE_TRACKBALL, pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005468
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005469 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005470 return reportInjectionResult(result);
5471 }
5472
5473 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005474 switch (result) {
5475 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5476 Slog.w(TAG, "Input event injection permission denied.");
5477 throw new SecurityException(
5478 "Injecting to another application requires INJECT_EVENTS permission");
5479 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
5480 Slog.v(TAG, "Input event injection succeeded.");
5481 return true;
5482 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5483 Slog.w(TAG, "Input event injection timed out.");
5484 return false;
5485 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5486 default:
5487 Slog.w(TAG, "Input event injection failed.");
5488 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005489 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005490 }
Romain Guy06882f82009-06-10 13:36:04 -07005491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005492 private WindowState getFocusedWindow() {
5493 synchronized (mWindowMap) {
5494 return getFocusedWindowLocked();
5495 }
5496 }
5497
5498 private WindowState getFocusedWindowLocked() {
5499 return mCurrentFocus;
5500 }
Romain Guy06882f82009-06-10 13:36:04 -07005501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005502 public boolean detectSafeMode() {
5503 mSafeMode = mPolicy.detectSafeMode();
5504 return mSafeMode;
5505 }
Romain Guy06882f82009-06-10 13:36:04 -07005506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005507 public void systemReady() {
5508 mPolicy.systemReady();
5509 }
Romain Guy06882f82009-06-10 13:36:04 -07005510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005511 // -------------------------------------------------------------
5512 // Client Session State
5513 // -------------------------------------------------------------
5514
5515 private final class Session extends IWindowSession.Stub
5516 implements IBinder.DeathRecipient {
5517 final IInputMethodClient mClient;
5518 final IInputContext mInputContext;
5519 final int mUid;
5520 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005521 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005522 SurfaceSession mSurfaceSession;
5523 int mNumWindow = 0;
5524 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005526 public Session(IInputMethodClient client, IInputContext inputContext) {
5527 mClient = client;
5528 mInputContext = inputContext;
5529 mUid = Binder.getCallingUid();
5530 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005531 StringBuilder sb = new StringBuilder();
5532 sb.append("Session{");
5533 sb.append(Integer.toHexString(System.identityHashCode(this)));
5534 sb.append(" uid ");
5535 sb.append(mUid);
5536 sb.append("}");
5537 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 synchronized (mWindowMap) {
5540 if (mInputMethodManager == null && mHaveInputMethods) {
5541 IBinder b = ServiceManager.getService(
5542 Context.INPUT_METHOD_SERVICE);
5543 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5544 }
5545 }
5546 long ident = Binder.clearCallingIdentity();
5547 try {
5548 // Note: it is safe to call in to the input method manager
5549 // here because we are not holding our lock.
5550 if (mInputMethodManager != null) {
5551 mInputMethodManager.addClient(client, inputContext,
5552 mUid, mPid);
5553 } else {
5554 client.setUsingInputMethod(false);
5555 }
5556 client.asBinder().linkToDeath(this, 0);
5557 } catch (RemoteException e) {
5558 // The caller has died, so we can just forget about this.
5559 try {
5560 if (mInputMethodManager != null) {
5561 mInputMethodManager.removeClient(client);
5562 }
5563 } catch (RemoteException ee) {
5564 }
5565 } finally {
5566 Binder.restoreCallingIdentity(ident);
5567 }
5568 }
Romain Guy06882f82009-06-10 13:36:04 -07005569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005570 @Override
5571 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5572 throws RemoteException {
5573 try {
5574 return super.onTransact(code, data, reply, flags);
5575 } catch (RuntimeException e) {
5576 // Log all 'real' exceptions thrown to the caller
5577 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005578 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005579 }
5580 throw e;
5581 }
5582 }
5583
5584 public void binderDied() {
5585 // Note: it is safe to call in to the input method manager
5586 // here because we are not holding our lock.
5587 try {
5588 if (mInputMethodManager != null) {
5589 mInputMethodManager.removeClient(mClient);
5590 }
5591 } catch (RemoteException e) {
5592 }
5593 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005594 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005595 mClientDead = true;
5596 killSessionLocked();
5597 }
5598 }
5599
5600 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005601 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5602 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5603 outInputChannel);
5604 }
5605
5606 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005607 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005608 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005609 }
Romain Guy06882f82009-06-10 13:36:04 -07005610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005611 public void remove(IWindow window) {
5612 removeWindow(this, window);
5613 }
Romain Guy06882f82009-06-10 13:36:04 -07005614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005615 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5616 int requestedWidth, int requestedHeight, int viewFlags,
5617 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005618 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005619 return relayoutWindow(this, window, attrs,
5620 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005621 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005622 }
Romain Guy06882f82009-06-10 13:36:04 -07005623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005624 public void setTransparentRegion(IWindow window, Region region) {
5625 setTransparentRegionWindow(this, window, region);
5626 }
Romain Guy06882f82009-06-10 13:36:04 -07005627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005628 public void setInsets(IWindow window, int touchableInsets,
5629 Rect contentInsets, Rect visibleInsets) {
5630 setInsetsWindow(this, window, touchableInsets, contentInsets,
5631 visibleInsets);
5632 }
Romain Guy06882f82009-06-10 13:36:04 -07005633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005634 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5635 getWindowDisplayFrame(this, window, outDisplayFrame);
5636 }
Romain Guy06882f82009-06-10 13:36:04 -07005637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005638 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005639 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005640 TAG, "IWindow finishDrawing called for " + window);
5641 finishDrawingWindow(this, window);
5642 }
5643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005644 public void setInTouchMode(boolean mode) {
5645 synchronized(mWindowMap) {
5646 mInTouchMode = mode;
5647 }
5648 }
5649
5650 public boolean getInTouchMode() {
5651 synchronized(mWindowMap) {
5652 return mInTouchMode;
5653 }
5654 }
5655
5656 public boolean performHapticFeedback(IWindow window, int effectId,
5657 boolean always) {
5658 synchronized(mWindowMap) {
5659 long ident = Binder.clearCallingIdentity();
5660 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005661 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005662 windowForClientLocked(this, window, true),
5663 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005664 } finally {
5665 Binder.restoreCallingIdentity(ident);
5666 }
5667 }
5668 }
Romain Guy06882f82009-06-10 13:36:04 -07005669
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005670 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005671 synchronized(mWindowMap) {
5672 long ident = Binder.clearCallingIdentity();
5673 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005674 setWindowWallpaperPositionLocked(
5675 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005676 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005677 } finally {
5678 Binder.restoreCallingIdentity(ident);
5679 }
5680 }
5681 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005682
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005683 public void wallpaperOffsetsComplete(IBinder window) {
5684 WindowManagerService.this.wallpaperOffsetsComplete(window);
5685 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005686
Dianne Hackborn75804932009-10-20 20:15:20 -07005687 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5688 int z, Bundle extras, boolean sync) {
5689 synchronized(mWindowMap) {
5690 long ident = Binder.clearCallingIdentity();
5691 try {
5692 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005693 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005694 action, x, y, z, extras, sync);
5695 } finally {
5696 Binder.restoreCallingIdentity(ident);
5697 }
5698 }
5699 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005700
Dianne Hackborn75804932009-10-20 20:15:20 -07005701 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5702 WindowManagerService.this.wallpaperCommandComplete(window, result);
5703 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005705 void windowAddedLocked() {
5706 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005707 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005708 TAG, "First window added to " + this + ", creating SurfaceSession");
5709 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005710 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005711 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005712 mSessions.add(this);
5713 }
5714 mNumWindow++;
5715 }
5716
5717 void windowRemovedLocked() {
5718 mNumWindow--;
5719 killSessionLocked();
5720 }
Romain Guy06882f82009-06-10 13:36:04 -07005721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005722 void killSessionLocked() {
5723 if (mNumWindow <= 0 && mClientDead) {
5724 mSessions.remove(this);
5725 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005726 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005727 TAG, "Last window removed from " + this
5728 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005729 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005730 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005731 try {
5732 mSurfaceSession.kill();
5733 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005734 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005735 + mSurfaceSession + " in session " + this
5736 + ": " + e.toString());
5737 }
5738 mSurfaceSession = null;
5739 }
5740 }
5741 }
Romain Guy06882f82009-06-10 13:36:04 -07005742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005743 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005744 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5745 pw.print(" mClientDead="); pw.print(mClientDead);
5746 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005747 }
5748
5749 @Override
5750 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005751 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005752 }
5753 }
5754
5755 // -------------------------------------------------------------
5756 // Client Window State
5757 // -------------------------------------------------------------
5758
5759 private final class WindowState implements WindowManagerPolicy.WindowState {
5760 final Session mSession;
5761 final IWindow mClient;
5762 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005763 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005764 AppWindowToken mAppToken;
5765 AppWindowToken mTargetAppToken;
5766 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5767 final DeathRecipient mDeathRecipient;
5768 final WindowState mAttachedWindow;
5769 final ArrayList mChildWindows = new ArrayList();
5770 final int mBaseLayer;
5771 final int mSubLayer;
5772 final boolean mLayoutAttached;
5773 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005774 final boolean mIsWallpaper;
5775 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005776 int mViewVisibility;
5777 boolean mPolicyVisibility = true;
5778 boolean mPolicyVisibilityAfterAnim = true;
5779 boolean mAppFreezing;
5780 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005781 boolean mReportDestroySurface;
5782 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005783 boolean mAttachedHidden; // is our parent window hidden?
5784 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005785 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005786 int mRequestedWidth;
5787 int mRequestedHeight;
5788 int mLastRequestedWidth;
5789 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005790 int mLayer;
5791 int mAnimLayer;
5792 int mLastLayer;
5793 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005794 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005795 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005796
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005797 int mLayoutSeq = -1;
5798
5799 Configuration mConfiguration = null;
5800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005801 // Actual frame shown on-screen (may be modified by animation)
5802 final Rect mShownFrame = new Rect();
5803 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005805 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005806 * Set when we have changed the size of the surface, to know that
5807 * we must tell them application to resize (and thus redraw itself).
5808 */
5809 boolean mSurfaceResized;
5810
5811 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005812 * Insets that determine the actually visible area
5813 */
5814 final Rect mVisibleInsets = new Rect();
5815 final Rect mLastVisibleInsets = new Rect();
5816 boolean mVisibleInsetsChanged;
5817
5818 /**
5819 * Insets that are covered by system windows
5820 */
5821 final Rect mContentInsets = new Rect();
5822 final Rect mLastContentInsets = new Rect();
5823 boolean mContentInsetsChanged;
5824
5825 /**
5826 * Set to true if we are waiting for this window to receive its
5827 * given internal insets before laying out other windows based on it.
5828 */
5829 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831 /**
5832 * These are the content insets that were given during layout for
5833 * this window, to be applied to windows behind it.
5834 */
5835 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 /**
5838 * These are the visible insets that were given during layout for
5839 * this window, to be applied to windows behind it.
5840 */
5841 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005843 /**
5844 * Flag indicating whether the touchable region should be adjusted by
5845 * the visible insets; if false the area outside the visible insets is
5846 * NOT touchable, so we must use those to adjust the frame during hit
5847 * tests.
5848 */
5849 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005851 // Current transformation being applied.
5852 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5853 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5854 float mHScale=1, mVScale=1;
5855 float mLastHScale=1, mLastVScale=1;
5856 final Matrix mTmpMatrix = new Matrix();
5857
5858 // "Real" frame that the application sees.
5859 final Rect mFrame = new Rect();
5860 final Rect mLastFrame = new Rect();
5861
5862 final Rect mContainingFrame = new Rect();
5863 final Rect mDisplayFrame = new Rect();
5864 final Rect mContentFrame = new Rect();
5865 final Rect mVisibleFrame = new Rect();
5866
5867 float mShownAlpha = 1;
5868 float mAlpha = 1;
5869 float mLastAlpha = 1;
5870
5871 // Set to true if, when the window gets displayed, it should perform
5872 // an enter animation.
5873 boolean mEnterAnimationPending;
5874
5875 // Currently running animation.
5876 boolean mAnimating;
5877 boolean mLocalAnimating;
5878 Animation mAnimation;
5879 boolean mAnimationIsEntrance;
5880 boolean mHasTransformation;
5881 boolean mHasLocalTransformation;
5882 final Transformation mTransformation = new Transformation();
5883
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005884 // If a window showing a wallpaper: the requested offset for the
5885 // wallpaper; if a wallpaper window: the currently applied offset.
5886 float mWallpaperX = -1;
5887 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005888
5889 // If a window showing a wallpaper: what fraction of the offset
5890 // range corresponds to a full virtual screen.
5891 float mWallpaperXStep = -1;
5892 float mWallpaperYStep = -1;
5893
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005894 // Wallpaper windows: pixels offset based on above variables.
5895 int mXOffset;
5896 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005898 // This is set after IWindowSession.relayout() has been called at
5899 // least once for the window. It allows us to detect the situation
5900 // where we don't yet have a surface, but should have one soon, so
5901 // we can give the window focus before waiting for the relayout.
5902 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005904 // This is set after the Surface has been created but before the
5905 // window has been drawn. During this time the surface is hidden.
5906 boolean mDrawPending;
5907
5908 // This is set after the window has finished drawing for the first
5909 // time but before its surface is shown. The surface will be
5910 // displayed when the next layout is run.
5911 boolean mCommitDrawPending;
5912
5913 // This is set during the time after the window's drawing has been
5914 // committed, and before its surface is actually shown. It is used
5915 // to delay showing the surface until all windows in a token are ready
5916 // to be shown.
5917 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005919 // Set when the window has been shown in the screen the first time.
5920 boolean mHasDrawn;
5921
5922 // Currently running an exit animation?
5923 boolean mExiting;
5924
5925 // Currently on the mDestroySurface list?
5926 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005928 // Completely remove from window manager after exit animation?
5929 boolean mRemoveOnExit;
5930
5931 // Set when the orientation is changing and this window has not yet
5932 // been updated for the new orientation.
5933 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005935 // Is this window now (or just being) removed?
5936 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005937
Dianne Hackborn16064f92010-03-25 00:47:24 -07005938 // For debugging, this is the last information given to the surface flinger.
5939 boolean mSurfaceShown;
5940 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
5941 int mSurfaceLayer;
5942 float mSurfaceAlpha;
5943
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005944 // Input channel
5945 InputChannel mInputChannel;
5946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005947 WindowState(Session s, IWindow c, WindowToken token,
5948 WindowState attachedWindow, WindowManager.LayoutParams a,
5949 int viewVisibility) {
5950 mSession = s;
5951 mClient = c;
5952 mToken = token;
5953 mAttrs.copyFrom(a);
5954 mViewVisibility = viewVisibility;
5955 DeathRecipient deathRecipient = new DeathRecipient();
5956 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005957 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005958 TAG, "Window " + this + " client=" + c.asBinder()
5959 + " token=" + token + " (" + mAttrs.token + ")");
5960 try {
5961 c.asBinder().linkToDeath(deathRecipient, 0);
5962 } catch (RemoteException e) {
5963 mDeathRecipient = null;
5964 mAttachedWindow = null;
5965 mLayoutAttached = false;
5966 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005967 mIsWallpaper = false;
5968 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005969 mBaseLayer = 0;
5970 mSubLayer = 0;
5971 return;
5972 }
5973 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07005974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005975 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
5976 mAttrs.type <= LAST_SUB_WINDOW)) {
5977 // The multiplier here is to reserve space for multiple
5978 // windows in the same type layer.
5979 mBaseLayer = mPolicy.windowTypeToLayerLw(
5980 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
5981 + TYPE_LAYER_OFFSET;
5982 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
5983 mAttachedWindow = attachedWindow;
5984 mAttachedWindow.mChildWindows.add(this);
5985 mLayoutAttached = mAttrs.type !=
5986 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
5987 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
5988 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005989 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
5990 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005991 } else {
5992 // The multiplier here is to reserve space for multiple
5993 // windows in the same type layer.
5994 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
5995 * TYPE_LAYER_MULTIPLIER
5996 + TYPE_LAYER_OFFSET;
5997 mSubLayer = 0;
5998 mAttachedWindow = null;
5999 mLayoutAttached = false;
6000 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6001 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006002 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6003 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006004 }
6005
6006 WindowState appWin = this;
6007 while (appWin.mAttachedWindow != null) {
6008 appWin = mAttachedWindow;
6009 }
6010 WindowToken appToken = appWin.mToken;
6011 while (appToken.appWindowToken == null) {
6012 WindowToken parent = mTokenMap.get(appToken.token);
6013 if (parent == null || appToken == parent) {
6014 break;
6015 }
6016 appToken = parent;
6017 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006018 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006019 mAppToken = appToken.appWindowToken;
6020
6021 mSurface = null;
6022 mRequestedWidth = 0;
6023 mRequestedHeight = 0;
6024 mLastRequestedWidth = 0;
6025 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006026 mXOffset = 0;
6027 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006028 mLayer = 0;
6029 mAnimLayer = 0;
6030 mLastLayer = 0;
6031 }
6032
6033 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006034 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006035 TAG, "Attaching " + this + " token=" + mToken
6036 + ", list=" + mToken.windows);
6037 mSession.windowAddedLocked();
6038 }
6039
6040 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6041 mHaveFrame = true;
6042
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006043 final Rect container = mContainingFrame;
6044 container.set(pf);
6045
6046 final Rect display = mDisplayFrame;
6047 display.set(df);
6048
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006049 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006050 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006051 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6052 display.intersect(mCompatibleScreenFrame);
6053 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006054 }
6055
6056 final int pw = container.right - container.left;
6057 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006058
6059 int w,h;
6060 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6061 w = mAttrs.width < 0 ? pw : mAttrs.width;
6062 h = mAttrs.height< 0 ? ph : mAttrs.height;
6063 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006064 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6065 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006066 }
Romain Guy06882f82009-06-10 13:36:04 -07006067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006068 final Rect content = mContentFrame;
6069 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006071 final Rect visible = mVisibleFrame;
6072 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006074 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006075 final int fw = frame.width();
6076 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6079 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6080
6081 Gravity.apply(mAttrs.gravity, w, h, container,
6082 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6083 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6084
6085 //System.out.println("Out: " + mFrame);
6086
6087 // Now make sure the window fits in the overall display.
6088 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006090 // Make sure the content and visible frames are inside of the
6091 // final window frame.
6092 if (content.left < frame.left) content.left = frame.left;
6093 if (content.top < frame.top) content.top = frame.top;
6094 if (content.right > frame.right) content.right = frame.right;
6095 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6096 if (visible.left < frame.left) visible.left = frame.left;
6097 if (visible.top < frame.top) visible.top = frame.top;
6098 if (visible.right > frame.right) visible.right = frame.right;
6099 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 final Rect contentInsets = mContentInsets;
6102 contentInsets.left = content.left-frame.left;
6103 contentInsets.top = content.top-frame.top;
6104 contentInsets.right = frame.right-content.right;
6105 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006107 final Rect visibleInsets = mVisibleInsets;
6108 visibleInsets.left = visible.left-frame.left;
6109 visibleInsets.top = visible.top-frame.top;
6110 visibleInsets.right = frame.right-visible.right;
6111 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006112
Dianne Hackborn284ac932009-08-28 10:34:25 -07006113 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6114 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006115 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006116 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 if (localLOGV) {
6119 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6120 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006121 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 + mRequestedWidth + ", mRequestedheight="
6123 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6124 + "): frame=" + mFrame.toShortString()
6125 + " ci=" + contentInsets.toShortString()
6126 + " vi=" + visibleInsets.toShortString());
6127 //}
6128 }
6129 }
Romain Guy06882f82009-06-10 13:36:04 -07006130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006131 public Rect getFrameLw() {
6132 return mFrame;
6133 }
6134
6135 public Rect getShownFrameLw() {
6136 return mShownFrame;
6137 }
6138
6139 public Rect getDisplayFrameLw() {
6140 return mDisplayFrame;
6141 }
6142
6143 public Rect getContentFrameLw() {
6144 return mContentFrame;
6145 }
6146
6147 public Rect getVisibleFrameLw() {
6148 return mVisibleFrame;
6149 }
6150
6151 public boolean getGivenInsetsPendingLw() {
6152 return mGivenInsetsPending;
6153 }
6154
6155 public Rect getGivenContentInsetsLw() {
6156 return mGivenContentInsets;
6157 }
Romain Guy06882f82009-06-10 13:36:04 -07006158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006159 public Rect getGivenVisibleInsetsLw() {
6160 return mGivenVisibleInsets;
6161 }
Romain Guy06882f82009-06-10 13:36:04 -07006162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006163 public WindowManager.LayoutParams getAttrs() {
6164 return mAttrs;
6165 }
6166
6167 public int getSurfaceLayer() {
6168 return mLayer;
6169 }
Romain Guy06882f82009-06-10 13:36:04 -07006170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006171 public IApplicationToken getAppToken() {
6172 return mAppToken != null ? mAppToken.appToken : null;
6173 }
Jeff Brown349703e2010-06-22 01:27:15 -07006174
6175 public long getInputDispatchingTimeoutNanos() {
6176 return mAppToken != null
6177 ? mAppToken.inputDispatchingTimeoutNanos
6178 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6179 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006180
6181 public boolean hasAppShownWindows() {
6182 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6183 }
6184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006185 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006186 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 TAG, "Setting animation in " + this + ": " + anim);
6188 mAnimating = false;
6189 mLocalAnimating = false;
6190 mAnimation = anim;
6191 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6192 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6193 }
6194
6195 public void clearAnimation() {
6196 if (mAnimation != null) {
6197 mAnimating = true;
6198 mLocalAnimating = false;
6199 mAnimation = null;
6200 }
6201 }
Romain Guy06882f82009-06-10 13:36:04 -07006202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006203 Surface createSurfaceLocked() {
6204 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006205 mReportDestroySurface = false;
6206 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006207 mDrawPending = true;
6208 mCommitDrawPending = false;
6209 mReadyToShow = false;
6210 if (mAppToken != null) {
6211 mAppToken.allDrawn = false;
6212 }
6213
6214 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006215 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 flags |= Surface.PUSH_BUFFERS;
6217 }
6218
6219 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6220 flags |= Surface.SECURE;
6221 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006222 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006223 TAG, "Creating surface in session "
6224 + mSession.mSurfaceSession + " window " + this
6225 + " w=" + mFrame.width()
6226 + " h=" + mFrame.height() + " format="
6227 + mAttrs.format + " flags=" + flags);
6228
6229 int w = mFrame.width();
6230 int h = mFrame.height();
6231 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6232 // for a scaled surface, we always want the requested
6233 // size.
6234 w = mRequestedWidth;
6235 h = mRequestedHeight;
6236 }
6237
Romain Guy9825ec62009-10-01 00:58:09 -07006238 // Something is wrong and SurfaceFlinger will not like this,
6239 // try to revert to sane values
6240 if (w <= 0) w = 1;
6241 if (h <= 0) h = 1;
6242
Dianne Hackborn16064f92010-03-25 00:47:24 -07006243 mSurfaceShown = false;
6244 mSurfaceLayer = 0;
6245 mSurfaceAlpha = 1;
6246 mSurfaceX = 0;
6247 mSurfaceY = 0;
6248 mSurfaceW = w;
6249 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250 try {
6251 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006252 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006253 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006255 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006256 + mSurface + " IN SESSION "
6257 + mSession.mSurfaceSession
6258 + ": pid=" + mSession.mPid + " format="
6259 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006260 + Integer.toHexString(flags)
6261 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006262 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006263 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006264 reclaimSomeSurfaceMemoryLocked(this, "create");
6265 return null;
6266 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006267 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 return null;
6269 }
Romain Guy06882f82009-06-10 13:36:04 -07006270
Joe Onorato8a9b2202010-02-26 18:56:32 -08006271 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006272 TAG, "Got surface: " + mSurface
6273 + ", set left=" + mFrame.left + " top=" + mFrame.top
6274 + ", animLayer=" + mAnimLayer);
6275 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006276 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006277 if (SHOW_TRANSACTIONS) logSurface(this,
6278 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6279 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6280 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 }
6282 Surface.openTransaction();
6283 try {
6284 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006285 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006286 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006287 mSurface.setPosition(mSurfaceX, mSurfaceY);
6288 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006289 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006290 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006291 mSurface.hide();
6292 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006293 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 mSurface.setFlags(Surface.SURFACE_DITHER,
6295 Surface.SURFACE_DITHER);
6296 }
6297 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006298 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006299 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6300 }
6301 mLastHidden = true;
6302 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006303 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006304 Surface.closeTransaction();
6305 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006306 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006307 TAG, "Created surface " + this);
6308 }
6309 return mSurface;
6310 }
Romain Guy06882f82009-06-10 13:36:04 -07006311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006312 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 if (mAppToken != null && this == mAppToken.startingWindow) {
6314 mAppToken.startingDisplayed = false;
6315 }
Romain Guy06882f82009-06-10 13:36:04 -07006316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006317 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006318 mDrawPending = false;
6319 mCommitDrawPending = false;
6320 mReadyToShow = false;
6321
6322 int i = mChildWindows.size();
6323 while (i > 0) {
6324 i--;
6325 WindowState c = (WindowState)mChildWindows.get(i);
6326 c.mAttachedHidden = true;
Jeff Brown349703e2010-06-22 01:27:15 -07006327
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006328 mInputMonitor.windowIsBecomingInvisibleLw(c);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006329 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006330
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006331 if (mReportDestroySurface) {
6332 mReportDestroySurface = false;
6333 mSurfacePendingDestroy = true;
6334 try {
6335 mClient.dispatchGetNewSurface();
6336 // We'll really destroy on the next time around.
6337 return;
6338 } catch (RemoteException e) {
6339 }
6340 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006343 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006344 RuntimeException e = null;
6345 if (!HIDE_STACK_CRAWLS) {
6346 e = new RuntimeException();
6347 e.fillInStackTrace();
6348 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006349 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006350 + mSurface + ", session " + mSession, e);
6351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006353 RuntimeException e = null;
6354 if (!HIDE_STACK_CRAWLS) {
6355 e = new RuntimeException();
6356 e.fillInStackTrace();
6357 }
6358 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006360 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006361 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006362 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006363 + " surface " + mSurface + " session " + mSession
6364 + ": " + e.toString());
6365 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006366
Dianne Hackborn16064f92010-03-25 00:47:24 -07006367 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 }
6370 }
6371
6372 boolean finishDrawingLocked() {
6373 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006374 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006375 TAG, "finishDrawingLocked: " + mSurface);
6376 mCommitDrawPending = true;
6377 mDrawPending = false;
6378 return true;
6379 }
6380 return false;
6381 }
6382
6383 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006384 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006385 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006387 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006388 }
6389 mCommitDrawPending = false;
6390 mReadyToShow = true;
6391 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6392 final AppWindowToken atoken = mAppToken;
6393 if (atoken == null || atoken.allDrawn || starting) {
6394 performShowLocked();
6395 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006396 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 }
6398
6399 // This must be called while inside a transaction.
6400 boolean performShowLocked() {
6401 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006402 RuntimeException e = null;
6403 if (!HIDE_STACK_CRAWLS) {
6404 e = new RuntimeException();
6405 e.fillInStackTrace();
6406 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006407 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6409 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6410 }
6411 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006412 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6413 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006414 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 + " during animation: policyVis=" + mPolicyVisibility
6416 + " attHidden=" + mAttachedHidden
6417 + " tok.hiddenRequested="
6418 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006419 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006420 + (mAppToken != null ? mAppToken.hidden : false)
6421 + " animating=" + mAnimating
6422 + " tok animating="
6423 + (mAppToken != null ? mAppToken.animating : false));
6424 if (!showSurfaceRobustlyLocked(this)) {
6425 return false;
6426 }
6427 mLastAlpha = -1;
6428 mHasDrawn = true;
6429 mLastHidden = false;
6430 mReadyToShow = false;
6431 enableScreenIfNeededLocked();
6432
6433 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006435 int i = mChildWindows.size();
6436 while (i > 0) {
6437 i--;
6438 WindowState c = (WindowState)mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006439 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006441 if (c.mSurface != null) {
6442 c.performShowLocked();
6443 // It hadn't been shown, which means layout not
6444 // performed on it, so now we want to make sure to
6445 // do a layout. If called from within the transaction
6446 // loop, this will cause it to restart with a new
6447 // layout.
6448 mLayoutNeeded = true;
6449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006450 }
6451 }
Romain Guy06882f82009-06-10 13:36:04 -07006452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 if (mAttrs.type != TYPE_APPLICATION_STARTING
6454 && mAppToken != null) {
6455 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006456
Dianne Hackborn248b1882009-09-16 16:46:44 -07006457 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006458 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006459 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006461 // If this initial window is animating, stop it -- we
6462 // will do an animation to reveal it from behind the
6463 // starting window, so there is no need for it to also
6464 // be doing its own stuff.
6465 if (mAnimation != null) {
6466 mAnimation = null;
6467 // Make sure we clean up the animation.
6468 mAnimating = true;
6469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 mFinishedStarting.add(mAppToken);
6471 mH.sendEmptyMessage(H.FINISHED_STARTING);
6472 }
6473 mAppToken.updateReportedVisibilityLocked();
6474 }
6475 }
6476 return true;
6477 }
Romain Guy06882f82009-06-10 13:36:04 -07006478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006479 // This must be called while inside a transaction. Returns true if
6480 // there is more animation to run.
6481 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006482 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006485 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6486 mHasTransformation = true;
6487 mHasLocalTransformation = true;
6488 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006489 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 TAG, "Starting animation in " + this +
6491 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6492 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6493 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6494 mAnimation.setStartTime(currentTime);
6495 mLocalAnimating = true;
6496 mAnimating = true;
6497 }
6498 mTransformation.clear();
6499 final boolean more = mAnimation.getTransformation(
6500 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006501 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 TAG, "Stepped animation in " + this +
6503 ": more=" + more + ", xform=" + mTransformation);
6504 if (more) {
6505 // we're not done!
6506 return true;
6507 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006508 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006509 TAG, "Finished animation in " + this +
6510 " @ " + currentTime);
6511 mAnimation = null;
6512 //WindowManagerService.this.dump();
6513 }
6514 mHasLocalTransformation = false;
6515 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006516 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006517 // When our app token is animating, we kind-of pretend like
6518 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6519 // part of this check means that we will only do this if
6520 // our window is not currently exiting, or it is not
6521 // locally animating itself. The idea being that one that
6522 // is exiting and doing a local animation should be removed
6523 // once that animation is done.
6524 mAnimating = true;
6525 mHasTransformation = true;
6526 mTransformation.clear();
6527 return false;
6528 } else if (mHasTransformation) {
6529 // Little trick to get through the path below to act like
6530 // we have finished an animation.
6531 mAnimating = true;
6532 } else if (isAnimating()) {
6533 mAnimating = true;
6534 }
6535 } else if (mAnimation != null) {
6536 // If the display is frozen, and there is a pending animation,
6537 // clear it and make sure we run the cleanup code.
6538 mAnimating = true;
6539 mLocalAnimating = true;
6540 mAnimation = null;
6541 }
Romain Guy06882f82009-06-10 13:36:04 -07006542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006543 if (!mAnimating && !mLocalAnimating) {
6544 return false;
6545 }
6546
Joe Onorato8a9b2202010-02-26 18:56:32 -08006547 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 TAG, "Animation done in " + this + ": exiting=" + mExiting
6549 + ", reportedVisible="
6550 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006552 mAnimating = false;
6553 mLocalAnimating = false;
6554 mAnimation = null;
6555 mAnimLayer = mLayer;
6556 if (mIsImWindow) {
6557 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006558 } else if (mIsWallpaper) {
6559 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006560 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006561 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006562 + " anim layer: " + mAnimLayer);
6563 mHasTransformation = false;
6564 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006565 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6566 if (DEBUG_VISIBILITY) {
6567 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6568 + mPolicyVisibilityAfterAnim);
6569 }
6570 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6571 if (!mPolicyVisibility) {
6572 if (mCurrentFocus == this) {
6573 mFocusMayChange = true;
6574 }
6575 // Window is no longer visible -- make sure if we were waiting
6576 // for it to be displayed before enabling the display, that
6577 // we allow the display to be enabled now.
6578 enableScreenIfNeededLocked();
6579 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006581 mTransformation.clear();
6582 if (mHasDrawn
6583 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6584 && mAppToken != null
6585 && mAppToken.firstWindowDrawn
6586 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006587 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006588 + mToken + ": first real window done animating");
6589 mFinishedStarting.add(mAppToken);
6590 mH.sendEmptyMessage(H.FINISHED_STARTING);
6591 }
Romain Guy06882f82009-06-10 13:36:04 -07006592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 finishExit();
6594
6595 if (mAppToken != null) {
6596 mAppToken.updateReportedVisibilityLocked();
6597 }
6598
6599 return false;
6600 }
6601
6602 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006603 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006604 TAG, "finishExit in " + this
6605 + ": exiting=" + mExiting
6606 + " remove=" + mRemoveOnExit
6607 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 final int N = mChildWindows.size();
6610 for (int i=0; i<N; i++) {
6611 ((WindowState)mChildWindows.get(i)).finishExit();
6612 }
Romain Guy06882f82009-06-10 13:36:04 -07006613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006614 if (!mExiting) {
6615 return;
6616 }
Romain Guy06882f82009-06-10 13:36:04 -07006617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006618 if (isWindowAnimating()) {
6619 return;
6620 }
6621
Joe Onorato8a9b2202010-02-26 18:56:32 -08006622 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006623 TAG, "Exit animation finished in " + this
6624 + ": remove=" + mRemoveOnExit);
6625 if (mSurface != null) {
6626 mDestroySurface.add(this);
6627 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006628 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006629 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006630 try {
6631 mSurface.hide();
6632 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006633 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006634 }
6635 mLastHidden = true;
Jeff Brown349703e2010-06-22 01:27:15 -07006636
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006637 for (int i=0; i<N; i++) {
6638 mInputMonitor.windowIsBecomingInvisibleLw((WindowState)mChildWindows.get(i));
Jeff Brown349703e2010-06-22 01:27:15 -07006639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 }
6641 mExiting = false;
6642 if (mRemoveOnExit) {
6643 mPendingRemove.add(this);
6644 mRemoveOnExit = false;
6645 }
6646 }
Romain Guy06882f82009-06-10 13:36:04 -07006647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006648 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6649 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6650 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6651 if (dtdx < -.000001f || dtdx > .000001f) return false;
6652 if (dsdy < -.000001f || dsdy > .000001f) return false;
6653 return true;
6654 }
Romain Guy06882f82009-06-10 13:36:04 -07006655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 void computeShownFrameLocked() {
6657 final boolean selfTransformation = mHasLocalTransformation;
6658 Transformation attachedTransformation =
6659 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6660 ? mAttachedWindow.mTransformation : null;
6661 Transformation appTransformation =
6662 (mAppToken != null && mAppToken.hasTransformation)
6663 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006664
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006665 // Wallpapers are animated based on the "real" window they
6666 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006667 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006668 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006669 if (mWallpaperTarget.mHasLocalTransformation &&
6670 mWallpaperTarget.mAnimation != null &&
6671 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006672 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006673 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006674 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006675 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006676 }
6677 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006678 mWallpaperTarget.mAppToken.hasTransformation &&
6679 mWallpaperTarget.mAppToken.animation != null &&
6680 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006681 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006682 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006683 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006684 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006685 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006688 if (selfTransformation || attachedTransformation != null
6689 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006690 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006691 final Rect frame = mFrame;
6692 final float tmpFloats[] = mTmpFloats;
6693 final Matrix tmpMatrix = mTmpMatrix;
6694
6695 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006696 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006697 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006698 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006700 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006701 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006702 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 }
6704 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006705 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 }
6707
6708 // "convert" it into SurfaceFlinger's format
6709 // (a 2x2 matrix + an offset)
6710 // Here we must not transform the position of the surface
6711 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006712 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006714 tmpMatrix.getValues(tmpFloats);
6715 mDsDx = tmpFloats[Matrix.MSCALE_X];
6716 mDtDx = tmpFloats[Matrix.MSKEW_X];
6717 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6718 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006719 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6720 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006721 int w = frame.width();
6722 int h = frame.height();
6723 mShownFrame.set(x, y, x+w, y+h);
6724
6725 // Now set the alpha... but because our current hardware
6726 // can't do alpha transformation on a non-opaque surface,
6727 // turn it off if we are running an animation that is also
6728 // transforming since it is more important to have that
6729 // animation be smooth.
6730 mShownAlpha = mAlpha;
6731 if (!mLimitedAlphaCompositing
6732 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6733 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6734 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006735 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006736 if (selfTransformation) {
6737 mShownAlpha *= mTransformation.getAlpha();
6738 }
6739 if (attachedTransformation != null) {
6740 mShownAlpha *= attachedTransformation.getAlpha();
6741 }
6742 if (appTransformation != null) {
6743 mShownAlpha *= appTransformation.getAlpha();
6744 }
6745 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006746 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 }
Romain Guy06882f82009-06-10 13:36:04 -07006748
Joe Onorato8a9b2202010-02-26 18:56:32 -08006749 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 TAG, "Continuing animation in " + this +
6751 ": " + mShownFrame +
6752 ", alpha=" + mTransformation.getAlpha());
6753 return;
6754 }
Romain Guy06882f82009-06-10 13:36:04 -07006755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006756 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006757 if (mXOffset != 0 || mYOffset != 0) {
6758 mShownFrame.offset(mXOffset, mYOffset);
6759 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 mShownAlpha = mAlpha;
6761 mDsDx = 1;
6762 mDtDx = 0;
6763 mDsDy = 0;
6764 mDtDy = 1;
6765 }
Romain Guy06882f82009-06-10 13:36:04 -07006766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 /**
6768 * Is this window visible? It is not visible if there is no
6769 * surface, or we are in the process of running an exit animation
6770 * that will remove the surface, or its app token has been hidden.
6771 */
6772 public boolean isVisibleLw() {
6773 final AppWindowToken atoken = mAppToken;
6774 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6775 && (atoken == null || !atoken.hiddenRequested)
6776 && !mExiting && !mDestroying;
6777 }
6778
6779 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006780 * Like {@link #isVisibleLw}, but also counts a window that is currently
6781 * "hidden" behind the keyguard as visible. This allows us to apply
6782 * things like window flags that impact the keyguard.
6783 * XXX I am starting to think we need to have ANOTHER visibility flag
6784 * for this "hidden behind keyguard" state rather than overloading
6785 * mPolicyVisibility. Ungh.
6786 */
6787 public boolean isVisibleOrBehindKeyguardLw() {
6788 final AppWindowToken atoken = mAppToken;
6789 return mSurface != null && !mAttachedHidden
6790 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006791 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006792 && !mExiting && !mDestroying;
6793 }
6794
6795 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006796 * Is this window visible, ignoring its app token? It is not visible
6797 * if there is no surface, or we are in the process of running an exit animation
6798 * that will remove the surface.
6799 */
6800 public boolean isWinVisibleLw() {
6801 final AppWindowToken atoken = mAppToken;
6802 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6803 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6804 && !mExiting && !mDestroying;
6805 }
6806
6807 /**
6808 * The same as isVisible(), but follows the current hidden state of
6809 * the associated app token, not the pending requested hidden state.
6810 */
6811 boolean isVisibleNow() {
6812 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006813 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 }
6815
6816 /**
6817 * Same as isVisible(), but we also count it as visible between the
6818 * call to IWindowSession.add() and the first relayout().
6819 */
6820 boolean isVisibleOrAdding() {
6821 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006822 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6824 && mPolicyVisibility && !mAttachedHidden
6825 && (atoken == null || !atoken.hiddenRequested)
6826 && !mExiting && !mDestroying;
6827 }
6828
6829 /**
6830 * Is this window currently on-screen? It is on-screen either if it
6831 * is visible or it is currently running an animation before no longer
6832 * being visible.
6833 */
6834 boolean isOnScreen() {
6835 final AppWindowToken atoken = mAppToken;
6836 if (atoken != null) {
6837 return mSurface != null && mPolicyVisibility && !mDestroying
6838 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006839 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 } else {
6841 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006842 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 }
6844 }
Romain Guy06882f82009-06-10 13:36:04 -07006845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 /**
6847 * Like isOnScreen(), but we don't return true if the window is part
6848 * of a transition that has not yet been started.
6849 */
6850 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006851 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006852 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006853 return false;
6854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006855 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006856 final boolean animating = atoken != null
6857 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006859 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6860 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006861 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862 }
6863
6864 /** Is the window or its container currently animating? */
6865 boolean isAnimating() {
6866 final WindowState attached = mAttachedWindow;
6867 final AppWindowToken atoken = mAppToken;
6868 return mAnimation != null
6869 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006870 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 (atoken.animation != null
6872 || atoken.inPendingTransaction));
6873 }
6874
6875 /** Is this window currently animating? */
6876 boolean isWindowAnimating() {
6877 return mAnimation != null;
6878 }
6879
6880 /**
6881 * Like isOnScreen, but returns false if the surface hasn't yet
6882 * been drawn.
6883 */
6884 public boolean isDisplayedLw() {
6885 final AppWindowToken atoken = mAppToken;
6886 return mSurface != null && mPolicyVisibility && !mDestroying
6887 && !mDrawPending && !mCommitDrawPending
6888 && ((!mAttachedHidden &&
6889 (atoken == null || !atoken.hiddenRequested))
6890 || mAnimating);
6891 }
6892
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006893 /**
6894 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006895 * complete UI in to. Note that this returns true if the orientation
6896 * is changing even if the window hasn't redrawn because we don't want
6897 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006898 */
6899 public boolean isDrawnLw() {
6900 final AppWindowToken atoken = mAppToken;
6901 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006902 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006903 }
6904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6906 boolean shownFrame, boolean onlyOpaque) {
6907 if (mSurface == null) {
6908 return false;
6909 }
6910 if (mAppToken != null && !mAppToken.appFullscreen) {
6911 return false;
6912 }
6913 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6914 return false;
6915 }
6916 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006917
6918 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6919 return frame.left <= mCompatibleScreenFrame.left &&
6920 frame.top <= mCompatibleScreenFrame.top &&
6921 frame.right >= mCompatibleScreenFrame.right &&
6922 frame.bottom >= mCompatibleScreenFrame.bottom;
6923 } else {
6924 return frame.left <= 0 && frame.top <= 0
6925 && frame.right >= screenWidth
6926 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006928 }
Romain Guy06882f82009-06-10 13:36:04 -07006929
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006930 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006931 * Return true if the window is opaque and fully drawn. This indicates
6932 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006933 */
6934 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006935 return (mAttrs.format == PixelFormat.OPAQUE
6936 || mAttrs.type == TYPE_WALLPAPER)
6937 && mSurface != null && mAnimation == null
6938 && (mAppToken == null || mAppToken.animation == null)
6939 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006940 }
6941
6942 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6943 return
6944 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006945 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6946 // only if it's visible
6947 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006948 // and only if the application fills the compatible screen
6949 mFrame.left <= mCompatibleScreenFrame.left &&
6950 mFrame.top <= mCompatibleScreenFrame.top &&
6951 mFrame.right >= mCompatibleScreenFrame.right &&
6952 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006953 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006954 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006955 }
6956
6957 boolean isFullscreen(int screenWidth, int screenHeight) {
6958 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006959 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006960 }
6961
6962 void removeLocked() {
6963 if (mAttachedWindow != null) {
6964 mAttachedWindow.mChildWindows.remove(this);
6965 }
6966 destroySurfaceLocked();
6967 mSession.windowRemovedLocked();
6968 try {
6969 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
6970 } catch (RuntimeException e) {
6971 // Ignore if it has already been removed (usually because
6972 // we are doing this as part of processing a death note.)
6973 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006974
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006975 if (mInputChannel != null) {
6976 mInputManager.unregisterInputChannel(mInputChannel);
6977
6978 mInputChannel.dispose();
6979 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006980 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 }
6982
6983 private class DeathRecipient implements IBinder.DeathRecipient {
6984 public void binderDied() {
6985 try {
6986 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006987 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006988 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006989 if (win != null) {
6990 removeWindowLocked(mSession, win);
6991 }
6992 }
6993 } catch (IllegalArgumentException ex) {
6994 // This will happen if the window has already been
6995 // removed.
6996 }
6997 }
6998 }
6999
7000 /** Returns true if this window desires key events. */
7001 public final boolean canReceiveKeys() {
7002 return isVisibleOrAdding()
7003 && (mViewVisibility == View.VISIBLE)
7004 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7005 }
7006
7007 public boolean hasDrawnLw() {
7008 return mHasDrawn;
7009 }
7010
7011 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007012 return showLw(doAnimation, true);
7013 }
7014
7015 boolean showLw(boolean doAnimation, boolean requestAnim) {
7016 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7017 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007019 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007020 if (doAnimation) {
7021 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7022 + mPolicyVisibility + " mAnimation=" + mAnimation);
7023 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7024 doAnimation = false;
7025 } else if (mPolicyVisibility && mAnimation == null) {
7026 // Check for the case where we are currently visible and
7027 // not animating; we do not want to do animation at such a
7028 // point to become visible when we already are.
7029 doAnimation = false;
7030 }
7031 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007032 mPolicyVisibility = true;
7033 mPolicyVisibilityAfterAnim = true;
7034 if (doAnimation) {
7035 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7036 }
7037 if (requestAnim) {
7038 requestAnimationLocked(0);
7039 }
7040 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007041 }
7042
7043 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007044 return hideLw(doAnimation, true);
7045 }
7046
7047 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007048 if (doAnimation) {
7049 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7050 doAnimation = false;
7051 }
7052 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007053 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7054 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007055 if (!current) {
7056 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007058 if (doAnimation) {
7059 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7060 if (mAnimation == null) {
7061 doAnimation = false;
7062 }
7063 }
7064 if (doAnimation) {
7065 mPolicyVisibilityAfterAnim = false;
7066 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007067 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007068 mPolicyVisibilityAfterAnim = false;
7069 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007070 // Window is no longer visible -- make sure if we were waiting
7071 // for it to be displayed before enabling the display, that
7072 // we allow the display to be enabled now.
7073 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007074 if (mCurrentFocus == this) {
7075 mFocusMayChange = true;
7076 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007077 }
7078 if (requestAnim) {
7079 requestAnimationLocked(0);
7080 }
7081 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007082 }
7083
7084 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007085 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7086 pw.print(" mClient="); pw.println(mClient.asBinder());
7087 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7088 if (mAttachedWindow != null || mLayoutAttached) {
7089 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7090 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7091 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007092 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7093 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7094 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007095 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7096 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007097 }
7098 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7099 pw.print(" mSubLayer="); pw.print(mSubLayer);
7100 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7101 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7102 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7103 pw.print("="); pw.print(mAnimLayer);
7104 pw.print(" mLastLayer="); pw.println(mLastLayer);
7105 if (mSurface != null) {
7106 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007107 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7108 pw.print(" layer="); pw.print(mSurfaceLayer);
7109 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7110 pw.print(" rect=("); pw.print(mSurfaceX);
7111 pw.print(","); pw.print(mSurfaceY);
7112 pw.print(") "); pw.print(mSurfaceW);
7113 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007114 }
7115 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7116 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7117 if (mAppToken != null) {
7118 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7119 }
7120 if (mTargetAppToken != null) {
7121 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7122 }
7123 pw.print(prefix); pw.print("mViewVisibility=0x");
7124 pw.print(Integer.toHexString(mViewVisibility));
7125 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007126 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7127 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007128 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7129 pw.print(prefix); pw.print("mPolicyVisibility=");
7130 pw.print(mPolicyVisibility);
7131 pw.print(" mPolicyVisibilityAfterAnim=");
7132 pw.print(mPolicyVisibilityAfterAnim);
7133 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7134 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007135 if (!mRelayoutCalled) {
7136 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7137 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007138 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007139 pw.print(" h="); pw.print(mRequestedHeight);
7140 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007141 if (mXOffset != 0 || mYOffset != 0) {
7142 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7143 pw.print(" y="); pw.println(mYOffset);
7144 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007145 pw.print(prefix); pw.print("mGivenContentInsets=");
7146 mGivenContentInsets.printShortString(pw);
7147 pw.print(" mGivenVisibleInsets=");
7148 mGivenVisibleInsets.printShortString(pw);
7149 pw.println();
7150 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7151 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7152 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7153 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007154 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007155 pw.print(prefix); pw.print("mShownFrame=");
7156 mShownFrame.printShortString(pw);
7157 pw.print(" last="); mLastShownFrame.printShortString(pw);
7158 pw.println();
7159 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7160 pw.print(" last="); mLastFrame.printShortString(pw);
7161 pw.println();
7162 pw.print(prefix); pw.print("mContainingFrame=");
7163 mContainingFrame.printShortString(pw);
7164 pw.print(" mDisplayFrame=");
7165 mDisplayFrame.printShortString(pw);
7166 pw.println();
7167 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7168 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7169 pw.println();
7170 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7171 pw.print(" last="); mLastContentInsets.printShortString(pw);
7172 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7173 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7174 pw.println();
7175 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7176 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7177 pw.print(" mAlpha="); pw.print(mAlpha);
7178 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7179 }
7180 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7181 || mAnimation != null) {
7182 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7183 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7184 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7185 pw.print(" mAnimation="); pw.println(mAnimation);
7186 }
7187 if (mHasTransformation || mHasLocalTransformation) {
7188 pw.print(prefix); pw.print("XForm: has=");
7189 pw.print(mHasTransformation);
7190 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7191 pw.print(" "); mTransformation.printShortString(pw);
7192 pw.println();
7193 }
7194 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7195 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7196 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7197 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7198 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7199 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7200 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7201 pw.print(" mDestroying="); pw.print(mDestroying);
7202 pw.print(" mRemoved="); pw.println(mRemoved);
7203 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007204 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007205 pw.print(prefix); pw.print("mOrientationChanging=");
7206 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007207 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7208 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007209 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007210 if (mHScale != 1 || mVScale != 1) {
7211 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7212 pw.print(" mVScale="); pw.println(mVScale);
7213 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007214 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007215 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7216 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7217 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007218 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7219 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7220 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007222 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007223
7224 String makeInputChannelName() {
7225 return Integer.toHexString(System.identityHashCode(this))
7226 + " " + mAttrs.getTitle();
7227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228
7229 @Override
7230 public String toString() {
7231 return "Window{"
7232 + Integer.toHexString(System.identityHashCode(this))
7233 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7234 }
7235 }
Romain Guy06882f82009-06-10 13:36:04 -07007236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007237 // -------------------------------------------------------------
7238 // Window Token State
7239 // -------------------------------------------------------------
7240
7241 class WindowToken {
7242 // The actual token.
7243 final IBinder token;
7244
7245 // The type of window this token is for, as per WindowManager.LayoutParams.
7246 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 // Set if this token was explicitly added by a client, so should
7249 // not be removed when all windows are removed.
7250 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007251
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007252 // For printing.
7253 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 // If this is an AppWindowToken, this is non-null.
7256 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007258 // All of the windows associated with this token.
7259 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7260
7261 // Is key dispatching paused for this token?
7262 boolean paused = false;
7263
7264 // Should this token's windows be hidden?
7265 boolean hidden;
7266
7267 // Temporary for finding which tokens no longer have visible windows.
7268 boolean hasVisible;
7269
Dianne Hackborna8f60182009-09-01 19:01:50 -07007270 // Set to true when this token is in a pending transaction where it
7271 // will be shown.
7272 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007273
Dianne Hackborna8f60182009-09-01 19:01:50 -07007274 // Set to true when this token is in a pending transaction where it
7275 // will be hidden.
7276 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007277
Dianne Hackborna8f60182009-09-01 19:01:50 -07007278 // Set to true when this token is in a pending transaction where its
7279 // windows will be put to the bottom of the list.
7280 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007281
Dianne Hackborna8f60182009-09-01 19:01:50 -07007282 // Set to true when this token is in a pending transaction where its
7283 // windows will be put to the top of the list.
7284 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007286 WindowToken(IBinder _token, int type, boolean _explicit) {
7287 token = _token;
7288 windowType = type;
7289 explicit = _explicit;
7290 }
7291
7292 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007293 pw.print(prefix); pw.print("token="); pw.println(token);
7294 pw.print(prefix); pw.print("windows="); pw.println(windows);
7295 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7296 pw.print(" hidden="); pw.print(hidden);
7297 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007298 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7299 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7300 pw.print(" waitingToHide="); pw.print(waitingToHide);
7301 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7302 pw.print(" sendingToTop="); pw.println(sendingToTop);
7303 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 }
7305
7306 @Override
7307 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007308 if (stringName == null) {
7309 StringBuilder sb = new StringBuilder();
7310 sb.append("WindowToken{");
7311 sb.append(Integer.toHexString(System.identityHashCode(this)));
7312 sb.append(" token="); sb.append(token); sb.append('}');
7313 stringName = sb.toString();
7314 }
7315 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 }
7317 };
7318
7319 class AppWindowToken extends WindowToken {
7320 // Non-null only for application tokens.
7321 final IApplicationToken appToken;
7322
7323 // All of the windows and child windows that are included in this
7324 // application token. Note this list is NOT sorted!
7325 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7326
7327 int groupId = -1;
7328 boolean appFullscreen;
7329 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007330
7331 // The input dispatching timeout for this application token in nanoseconds.
7332 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 // These are used for determining when all windows associated with
7335 // an activity have been drawn, so they can be made visible together
7336 // at the same time.
7337 int lastTransactionSequence = mTransactionSequence-1;
7338 int numInterestingWindows;
7339 int numDrawnWindows;
7340 boolean inPendingTransaction;
7341 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 // Is this token going to be hidden in a little while? If so, it
7344 // won't be taken into account for setting the screen orientation.
7345 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 // Is this window's surface needed? This is almost like hidden, except
7348 // it will sometimes be true a little earlier: when the token has
7349 // been shown, but is still waiting for its app transition to execute
7350 // before making its windows shown.
7351 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353 // Have we told the window clients to hide themselves?
7354 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007356 // Last visibility state we reported to the app token.
7357 boolean reportedVisible;
7358
7359 // Set to true when the token has been removed from the window mgr.
7360 boolean removed;
7361
7362 // Have we been asked to have this token keep the screen frozen?
7363 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 boolean animating;
7366 Animation animation;
7367 boolean hasTransformation;
7368 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007370 // Offset to the window of all layers in the token, for use by
7371 // AppWindowToken animations.
7372 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007374 // Information about an application starting window if displayed.
7375 StartingData startingData;
7376 WindowState startingWindow;
7377 View startingView;
7378 boolean startingDisplayed;
7379 boolean startingMoved;
7380 boolean firstWindowDrawn;
7381
7382 AppWindowToken(IApplicationToken _token) {
7383 super(_token.asBinder(),
7384 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7385 appWindowToken = this;
7386 appToken = _token;
7387 }
Romain Guy06882f82009-06-10 13:36:04 -07007388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007389 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007390 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007391 TAG, "Setting animation in " + this + ": " + anim);
7392 animation = anim;
7393 animating = false;
7394 anim.restrictDuration(MAX_ANIMATION_DURATION);
7395 anim.scaleCurrentDuration(mTransitionAnimationScale);
7396 int zorder = anim.getZAdjustment();
7397 int adj = 0;
7398 if (zorder == Animation.ZORDER_TOP) {
7399 adj = TYPE_LAYER_OFFSET;
7400 } else if (zorder == Animation.ZORDER_BOTTOM) {
7401 adj = -TYPE_LAYER_OFFSET;
7402 }
Romain Guy06882f82009-06-10 13:36:04 -07007403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 if (animLayerAdjustment != adj) {
7405 animLayerAdjustment = adj;
7406 updateLayers();
7407 }
7408 }
Romain Guy06882f82009-06-10 13:36:04 -07007409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 public void setDummyAnimation() {
7411 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007412 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 TAG, "Setting dummy animation in " + this);
7414 animation = sDummyAnimation;
7415 }
7416 }
7417
7418 public void clearAnimation() {
7419 if (animation != null) {
7420 animation = null;
7421 animating = true;
7422 }
7423 }
Romain Guy06882f82009-06-10 13:36:04 -07007424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007425 void updateLayers() {
7426 final int N = allAppWindows.size();
7427 final int adj = animLayerAdjustment;
7428 for (int i=0; i<N; i++) {
7429 WindowState w = allAppWindows.get(i);
7430 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007431 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 + w.mAnimLayer);
7433 if (w == mInputMethodTarget) {
7434 setInputMethodAnimLayerAdjustment(adj);
7435 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007436 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007437 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007438 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007439 }
7440 }
Romain Guy06882f82009-06-10 13:36:04 -07007441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 void sendAppVisibilityToClients() {
7443 final int N = allAppWindows.size();
7444 for (int i=0; i<N; i++) {
7445 WindowState win = allAppWindows.get(i);
7446 if (win == startingWindow && clientHidden) {
7447 // Don't hide the starting window.
7448 continue;
7449 }
7450 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007451 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 "Setting visibility of " + win + ": " + (!clientHidden));
7453 win.mClient.dispatchAppVisibility(!clientHidden);
7454 } catch (RemoteException e) {
7455 }
7456 }
7457 }
Romain Guy06882f82009-06-10 13:36:04 -07007458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007459 void showAllWindowsLocked() {
7460 final int NW = allAppWindows.size();
7461 for (int i=0; i<NW; i++) {
7462 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007463 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 "performing show on: " + w);
7465 w.performShowLocked();
7466 }
7467 }
Romain Guy06882f82009-06-10 13:36:04 -07007468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007469 // This must be called while inside a transaction.
7470 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007471 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007472 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 if (animation == sDummyAnimation) {
7475 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007476 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 // when it is really time to animate, this will be set to
7478 // a real animation and the next call will execute normally.
7479 return false;
7480 }
Romain Guy06882f82009-06-10 13:36:04 -07007481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007482 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7483 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007484 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007485 TAG, "Starting animation in " + this +
7486 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7487 + " scale=" + mTransitionAnimationScale
7488 + " allDrawn=" + allDrawn + " animating=" + animating);
7489 animation.initialize(dw, dh, dw, dh);
7490 animation.setStartTime(currentTime);
7491 animating = true;
7492 }
7493 transformation.clear();
7494 final boolean more = animation.getTransformation(
7495 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007496 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 TAG, "Stepped animation in " + this +
7498 ": more=" + more + ", xform=" + transformation);
7499 if (more) {
7500 // we're done!
7501 hasTransformation = true;
7502 return true;
7503 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007504 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 TAG, "Finished animation in " + this +
7506 " @ " + currentTime);
7507 animation = null;
7508 }
7509 } else if (animation != null) {
7510 // If the display is frozen, and there is a pending animation,
7511 // clear it and make sure we run the cleanup code.
7512 animating = true;
7513 animation = null;
7514 }
7515
7516 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007518 if (!animating) {
7519 return false;
7520 }
7521
7522 clearAnimation();
7523 animating = false;
7524 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7525 moveInputMethodWindowsIfNeededLocked(true);
7526 }
Romain Guy06882f82009-06-10 13:36:04 -07007527
Joe Onorato8a9b2202010-02-26 18:56:32 -08007528 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007529 TAG, "Animation done in " + this
7530 + ": reportedVisible=" + reportedVisible);
7531
7532 transformation.clear();
7533 if (animLayerAdjustment != 0) {
7534 animLayerAdjustment = 0;
7535 updateLayers();
7536 }
Romain Guy06882f82009-06-10 13:36:04 -07007537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007538 final int N = windows.size();
7539 for (int i=0; i<N; i++) {
7540 ((WindowState)windows.get(i)).finishExit();
7541 }
7542 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007544 return false;
7545 }
7546
7547 void updateReportedVisibilityLocked() {
7548 if (appToken == null) {
7549 return;
7550 }
Romain Guy06882f82009-06-10 13:36:04 -07007551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007552 int numInteresting = 0;
7553 int numVisible = 0;
7554 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007555
Joe Onorato8a9b2202010-02-26 18:56:32 -08007556 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 final int N = allAppWindows.size();
7558 for (int i=0; i<N; i++) {
7559 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007560 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007561 || win.mViewVisibility != View.VISIBLE
7562 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 continue;
7564 }
7565 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007566 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007567 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007568 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007569 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007570 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007571 + " pv=" + win.mPolicyVisibility
7572 + " dp=" + win.mDrawPending
7573 + " cdp=" + win.mCommitDrawPending
7574 + " ah=" + win.mAttachedHidden
7575 + " th="
7576 + (win.mAppToken != null
7577 ? win.mAppToken.hiddenRequested : false)
7578 + " a=" + win.mAnimating);
7579 }
7580 }
7581 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007582 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007583 if (!win.isAnimating()) {
7584 numVisible++;
7585 }
7586 nowGone = false;
7587 } else if (win.isAnimating()) {
7588 nowGone = false;
7589 }
7590 }
Romain Guy06882f82009-06-10 13:36:04 -07007591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007593 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 + numInteresting + " visible=" + numVisible);
7595 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007596 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 TAG, "Visibility changed in " + this
7598 + ": vis=" + nowVisible);
7599 reportedVisible = nowVisible;
7600 Message m = mH.obtainMessage(
7601 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7602 nowVisible ? 1 : 0,
7603 nowGone ? 1 : 0,
7604 this);
7605 mH.sendMessage(m);
7606 }
7607 }
Romain Guy06882f82009-06-10 13:36:04 -07007608
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007609 WindowState findMainWindow() {
7610 int j = windows.size();
7611 while (j > 0) {
7612 j--;
7613 WindowState win = windows.get(j);
7614 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7615 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7616 return win;
7617 }
7618 }
7619 return null;
7620 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 void dump(PrintWriter pw, String prefix) {
7623 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007624 if (appToken != null) {
7625 pw.print(prefix); pw.println("app=true");
7626 }
7627 if (allAppWindows.size() > 0) {
7628 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7629 }
7630 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007631 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007632 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7633 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7634 pw.print(" clientHidden="); pw.print(clientHidden);
7635 pw.print(" willBeHidden="); pw.print(willBeHidden);
7636 pw.print(" reportedVisible="); pw.println(reportedVisible);
7637 if (paused || freezingScreen) {
7638 pw.print(prefix); pw.print("paused="); pw.print(paused);
7639 pw.print(" freezingScreen="); pw.println(freezingScreen);
7640 }
7641 if (numInterestingWindows != 0 || numDrawnWindows != 0
7642 || inPendingTransaction || allDrawn) {
7643 pw.print(prefix); pw.print("numInterestingWindows=");
7644 pw.print(numInterestingWindows);
7645 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7646 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7647 pw.print(" allDrawn="); pw.println(allDrawn);
7648 }
7649 if (animating || animation != null) {
7650 pw.print(prefix); pw.print("animating="); pw.print(animating);
7651 pw.print(" animation="); pw.println(animation);
7652 }
7653 if (animLayerAdjustment != 0) {
7654 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7655 }
7656 if (hasTransformation) {
7657 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7658 pw.print(" transformation="); transformation.printShortString(pw);
7659 pw.println();
7660 }
7661 if (startingData != null || removed || firstWindowDrawn) {
7662 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7663 pw.print(" removed="); pw.print(removed);
7664 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7665 }
7666 if (startingWindow != null || startingView != null
7667 || startingDisplayed || startingMoved) {
7668 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7669 pw.print(" startingView="); pw.print(startingView);
7670 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7671 pw.print(" startingMoved"); pw.println(startingMoved);
7672 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007673 }
7674
7675 @Override
7676 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007677 if (stringName == null) {
7678 StringBuilder sb = new StringBuilder();
7679 sb.append("AppWindowToken{");
7680 sb.append(Integer.toHexString(System.identityHashCode(this)));
7681 sb.append(" token="); sb.append(token); sb.append('}');
7682 stringName = sb.toString();
7683 }
7684 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 }
7686 }
Romain Guy06882f82009-06-10 13:36:04 -07007687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007688 // -------------------------------------------------------------
7689 // DummyAnimation
7690 // -------------------------------------------------------------
7691
7692 // This is an animation that does nothing: it just immediately finishes
7693 // itself every time it is called. It is used as a stub animation in cases
7694 // where we want to synchronize multiple things that may be animating.
7695 static final class DummyAnimation extends Animation {
7696 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7697 return false;
7698 }
7699 }
7700 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 // -------------------------------------------------------------
7703 // Async Handler
7704 // -------------------------------------------------------------
7705
7706 static final class StartingData {
7707 final String pkg;
7708 final int theme;
7709 final CharSequence nonLocalizedLabel;
7710 final int labelRes;
7711 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007713 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7714 int _labelRes, int _icon) {
7715 pkg = _pkg;
7716 theme = _theme;
7717 nonLocalizedLabel = _nonLocalizedLabel;
7718 labelRes = _labelRes;
7719 icon = _icon;
7720 }
7721 }
7722
7723 private final class H extends Handler {
7724 public static final int REPORT_FOCUS_CHANGE = 2;
7725 public static final int REPORT_LOSING_FOCUS = 3;
7726 public static final int ANIMATE = 4;
7727 public static final int ADD_STARTING = 5;
7728 public static final int REMOVE_STARTING = 6;
7729 public static final int FINISHED_STARTING = 7;
7730 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007731 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7732 public static final int HOLD_SCREEN_CHANGED = 12;
7733 public static final int APP_TRANSITION_TIMEOUT = 13;
7734 public static final int PERSIST_ANIMATION_SCALE = 14;
7735 public static final int FORCE_GC = 15;
7736 public static final int ENABLE_SCREEN = 16;
7737 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007738 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007739 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007741 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007743 public H() {
7744 }
Romain Guy06882f82009-06-10 13:36:04 -07007745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007746 @Override
7747 public void handleMessage(Message msg) {
7748 switch (msg.what) {
7749 case REPORT_FOCUS_CHANGE: {
7750 WindowState lastFocus;
7751 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 synchronized(mWindowMap) {
7754 lastFocus = mLastFocus;
7755 newFocus = mCurrentFocus;
7756 if (lastFocus == newFocus) {
7757 // Focus is not changing, so nothing to do.
7758 return;
7759 }
7760 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007761 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007762 // + " to " + newFocus);
7763 if (newFocus != null && lastFocus != null
7764 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007765 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007766 mLosingFocus.add(lastFocus);
7767 lastFocus = null;
7768 }
7769 }
7770
7771 if (lastFocus != newFocus) {
7772 //System.out.println("Changing focus from " + lastFocus
7773 // + " to " + newFocus);
7774 if (newFocus != null) {
7775 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007776 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7778 } catch (RemoteException e) {
7779 // Ignore if process has died.
7780 }
7781 }
7782
7783 if (lastFocus != null) {
7784 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007785 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007786 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7787 } catch (RemoteException e) {
7788 // Ignore if process has died.
7789 }
7790 }
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007791 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007792 }
7793 } break;
7794
7795 case REPORT_LOSING_FOCUS: {
7796 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007798 synchronized(mWindowMap) {
7799 losers = mLosingFocus;
7800 mLosingFocus = new ArrayList<WindowState>();
7801 }
7802
7803 final int N = losers.size();
7804 for (int i=0; i<N; i++) {
7805 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007806 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7808 } catch (RemoteException e) {
7809 // Ignore if process has died.
7810 }
7811 }
7812 } break;
7813
7814 case ANIMATE: {
7815 synchronized(mWindowMap) {
7816 mAnimationPending = false;
7817 performLayoutAndPlaceSurfacesLocked();
7818 }
7819 } break;
7820
7821 case ADD_STARTING: {
7822 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7823 final StartingData sd = wtoken.startingData;
7824
7825 if (sd == null) {
7826 // Animation has been canceled... do nothing.
7827 return;
7828 }
Romain Guy06882f82009-06-10 13:36:04 -07007829
Joe Onorato8a9b2202010-02-26 18:56:32 -08007830 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007831 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 View view = null;
7834 try {
7835 view = mPolicy.addStartingWindow(
7836 wtoken.token, sd.pkg,
7837 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7838 sd.icon);
7839 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007840 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007841 }
7842
7843 if (view != null) {
7844 boolean abort = false;
7845
7846 synchronized(mWindowMap) {
7847 if (wtoken.removed || wtoken.startingData == null) {
7848 // If the window was successfully added, then
7849 // we need to remove it.
7850 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007851 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007852 "Aborted starting " + wtoken
7853 + ": removed=" + wtoken.removed
7854 + " startingData=" + wtoken.startingData);
7855 wtoken.startingWindow = null;
7856 wtoken.startingData = null;
7857 abort = true;
7858 }
7859 } else {
7860 wtoken.startingView = view;
7861 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007862 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007863 "Added starting " + wtoken
7864 + ": startingWindow="
7865 + wtoken.startingWindow + " startingView="
7866 + wtoken.startingView);
7867 }
7868
7869 if (abort) {
7870 try {
7871 mPolicy.removeStartingWindow(wtoken.token, view);
7872 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007873 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007874 }
7875 }
7876 }
7877 } break;
7878
7879 case REMOVE_STARTING: {
7880 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7881 IBinder token = null;
7882 View view = null;
7883 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007884 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 + wtoken + ": startingWindow="
7886 + wtoken.startingWindow + " startingView="
7887 + wtoken.startingView);
7888 if (wtoken.startingWindow != null) {
7889 view = wtoken.startingView;
7890 token = wtoken.token;
7891 wtoken.startingData = null;
7892 wtoken.startingView = null;
7893 wtoken.startingWindow = null;
7894 }
7895 }
7896 if (view != null) {
7897 try {
7898 mPolicy.removeStartingWindow(token, view);
7899 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007900 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 }
7902 }
7903 } break;
7904
7905 case FINISHED_STARTING: {
7906 IBinder token = null;
7907 View view = null;
7908 while (true) {
7909 synchronized (mWindowMap) {
7910 final int N = mFinishedStarting.size();
7911 if (N <= 0) {
7912 break;
7913 }
7914 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7915
Joe Onorato8a9b2202010-02-26 18:56:32 -08007916 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007917 "Finished starting " + wtoken
7918 + ": startingWindow=" + wtoken.startingWindow
7919 + " startingView=" + wtoken.startingView);
7920
7921 if (wtoken.startingWindow == null) {
7922 continue;
7923 }
7924
7925 view = wtoken.startingView;
7926 token = wtoken.token;
7927 wtoken.startingData = null;
7928 wtoken.startingView = null;
7929 wtoken.startingWindow = null;
7930 }
7931
7932 try {
7933 mPolicy.removeStartingWindow(token, view);
7934 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007935 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 }
7937 }
7938 } break;
7939
7940 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7941 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7942
7943 boolean nowVisible = msg.arg1 != 0;
7944 boolean nowGone = msg.arg2 != 0;
7945
7946 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007947 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007948 TAG, "Reporting visible in " + wtoken
7949 + " visible=" + nowVisible
7950 + " gone=" + nowGone);
7951 if (nowVisible) {
7952 wtoken.appToken.windowsVisible();
7953 } else {
7954 wtoken.appToken.windowsGone();
7955 }
7956 } catch (RemoteException ex) {
7957 }
7958 } break;
Romain Guy06882f82009-06-10 13:36:04 -07007959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007960 case WINDOW_FREEZE_TIMEOUT: {
7961 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007962 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007963 int i = mWindows.size();
7964 while (i > 0) {
7965 i--;
7966 WindowState w = (WindowState)mWindows.get(i);
7967 if (w.mOrientationChanging) {
7968 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007969 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007970 }
7971 }
7972 performLayoutAndPlaceSurfacesLocked();
7973 }
7974 break;
7975 }
Romain Guy06882f82009-06-10 13:36:04 -07007976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 case HOLD_SCREEN_CHANGED: {
7978 Session oldHold;
7979 Session newHold;
7980 synchronized (mWindowMap) {
7981 oldHold = mLastReportedHold;
7982 newHold = (Session)msg.obj;
7983 mLastReportedHold = newHold;
7984 }
Romain Guy06882f82009-06-10 13:36:04 -07007985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007986 if (oldHold != newHold) {
7987 try {
7988 if (oldHold != null) {
7989 mBatteryStats.noteStopWakelock(oldHold.mUid,
7990 "window",
7991 BatteryStats.WAKE_TYPE_WINDOW);
7992 }
7993 if (newHold != null) {
7994 mBatteryStats.noteStartWakelock(newHold.mUid,
7995 "window",
7996 BatteryStats.WAKE_TYPE_WINDOW);
7997 }
7998 } catch (RemoteException e) {
7999 }
8000 }
8001 break;
8002 }
Romain Guy06882f82009-06-10 13:36:04 -07008003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 case APP_TRANSITION_TIMEOUT: {
8005 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008006 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008007 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008008 "*** APP TRANSITION TIMEOUT");
8009 mAppTransitionReady = true;
8010 mAppTransitionTimeout = true;
8011 performLayoutAndPlaceSurfacesLocked();
8012 }
8013 }
8014 break;
8015 }
Romain Guy06882f82009-06-10 13:36:04 -07008016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008017 case PERSIST_ANIMATION_SCALE: {
8018 Settings.System.putFloat(mContext.getContentResolver(),
8019 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8020 Settings.System.putFloat(mContext.getContentResolver(),
8021 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8022 break;
8023 }
Romain Guy06882f82009-06-10 13:36:04 -07008024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 case FORCE_GC: {
8026 synchronized(mWindowMap) {
8027 if (mAnimationPending) {
8028 // If we are animating, don't do the gc now but
8029 // delay a bit so we don't interrupt the animation.
8030 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8031 2000);
8032 return;
8033 }
8034 // If we are currently rotating the display, it will
8035 // schedule a new message when done.
8036 if (mDisplayFrozen) {
8037 return;
8038 }
8039 mFreezeGcPending = 0;
8040 }
8041 Runtime.getRuntime().gc();
8042 break;
8043 }
Romain Guy06882f82009-06-10 13:36:04 -07008044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008045 case ENABLE_SCREEN: {
8046 performEnableScreen();
8047 break;
8048 }
Romain Guy06882f82009-06-10 13:36:04 -07008049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 case APP_FREEZE_TIMEOUT: {
8051 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008052 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008053 int i = mAppTokens.size();
8054 while (i > 0) {
8055 i--;
8056 AppWindowToken tok = mAppTokens.get(i);
8057 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008058 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008059 unsetAppFreezingScreenLocked(tok, true, true);
8060 }
8061 }
8062 }
8063 break;
8064 }
Romain Guy06882f82009-06-10 13:36:04 -07008065
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008066 case SEND_NEW_CONFIGURATION: {
8067 removeMessages(SEND_NEW_CONFIGURATION);
8068 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008069 break;
8070 }
Romain Guy06882f82009-06-10 13:36:04 -07008071
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008072 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008073 if (mWindowsChanged) {
8074 synchronized (mWindowMap) {
8075 mWindowsChanged = false;
8076 }
8077 notifyWindowsChanged();
8078 }
8079 break;
8080 }
8081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008082 }
8083 }
8084 }
8085
8086 // -------------------------------------------------------------
8087 // IWindowManager API
8088 // -------------------------------------------------------------
8089
8090 public IWindowSession openSession(IInputMethodClient client,
8091 IInputContext inputContext) {
8092 if (client == null) throw new IllegalArgumentException("null client");
8093 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008094 Session session = new Session(client, inputContext);
8095 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008096 }
8097
8098 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8099 synchronized (mWindowMap) {
8100 // The focus for the client is the window immediately below
8101 // where we would place the input method window.
8102 int idx = findDesiredInputMethodWindowIndexLocked(false);
8103 WindowState imFocus;
8104 if (idx > 0) {
8105 imFocus = (WindowState)mWindows.get(idx-1);
8106 if (imFocus != null) {
8107 if (imFocus.mSession.mClient != null &&
8108 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8109 return true;
8110 }
8111 }
8112 }
8113 }
8114 return false;
8115 }
Romain Guy06882f82009-06-10 13:36:04 -07008116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008117 // -------------------------------------------------------------
8118 // Internals
8119 // -------------------------------------------------------------
8120
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008121 final WindowState windowForClientLocked(Session session, IWindow client,
8122 boolean throwOnError) {
8123 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008124 }
Romain Guy06882f82009-06-10 13:36:04 -07008125
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008126 final WindowState windowForClientLocked(Session session, IBinder client,
8127 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008128 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008129 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008130 TAG, "Looking up client " + client + ": " + win);
8131 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008132 RuntimeException ex = new IllegalArgumentException(
8133 "Requested window " + client + " does not exist");
8134 if (throwOnError) {
8135 throw ex;
8136 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008137 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008138 return null;
8139 }
8140 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008141 RuntimeException ex = new IllegalArgumentException(
8142 "Requested window " + client + " is in session " +
8143 win.mSession + ", not " + session);
8144 if (throwOnError) {
8145 throw ex;
8146 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008147 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148 return null;
8149 }
8150
8151 return win;
8152 }
8153
Dianne Hackborna8f60182009-09-01 19:01:50 -07008154 final void rebuildAppWindowListLocked() {
8155 int NW = mWindows.size();
8156 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008157 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008158 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008159
Dianne Hackborna8f60182009-09-01 19:01:50 -07008160 // First remove all existing app windows.
8161 i=0;
8162 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008163 WindowState w = (WindowState)mWindows.get(i);
8164 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008165 WindowState win = (WindowState)mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008166 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008167 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008168 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008169 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008170 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008171 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008172 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8173 && lastWallpaper == i-1) {
8174 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008175 }
8176 i++;
8177 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008178
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008179 // The wallpaper window(s) typically live at the bottom of the stack,
8180 // so skip them before adding app tokens.
8181 lastWallpaper++;
8182 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008183
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008184 // First add all of the exiting app tokens... these are no longer
8185 // in the main app list, but still have windows shown. We put them
8186 // in the back because now that the animation is over we no longer
8187 // will care about them.
8188 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008189 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008190 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8191 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008192
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008193 // And add in the still active app tokens in Z order.
8194 NT = mAppTokens.size();
8195 for (int j=0; j<NT; j++) {
8196 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008197 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008198
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008199 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008200 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008201 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008202 + " windows but added " + i);
8203 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008204 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008206 private final void assignLayersLocked() {
8207 int N = mWindows.size();
8208 int curBaseLayer = 0;
8209 int curLayer = 0;
8210 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 for (i=0; i<N; i++) {
8213 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008214 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8215 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008216 curLayer += WINDOW_LAYER_MULTIPLIER;
8217 w.mLayer = curLayer;
8218 } else {
8219 curBaseLayer = curLayer = w.mBaseLayer;
8220 w.mLayer = curLayer;
8221 }
8222 if (w.mTargetAppToken != null) {
8223 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8224 } else if (w.mAppToken != null) {
8225 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8226 } else {
8227 w.mAnimLayer = w.mLayer;
8228 }
8229 if (w.mIsImWindow) {
8230 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008231 } else if (w.mIsWallpaper) {
8232 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008233 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008234 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008235 + w.mAnimLayer);
8236 //System.out.println(
8237 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8238 }
8239 }
8240
8241 private boolean mInLayout = false;
8242 private final void performLayoutAndPlaceSurfacesLocked() {
8243 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008244 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008245 throw new RuntimeException("Recursive call!");
8246 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008247 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008248 return;
8249 }
8250
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008251 if (mWaitingForConfig) {
8252 // Our configuration has changed (most likely rotation), but we
8253 // don't yet have the complete configuration to report to
8254 // applications. Don't do any window layout until we have it.
8255 return;
8256 }
8257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008258 boolean recoveringMemory = false;
8259 if (mForceRemoves != null) {
8260 recoveringMemory = true;
8261 // Wait a little it for things to settle down, and off we go.
8262 for (int i=0; i<mForceRemoves.size(); i++) {
8263 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008264 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008265 removeWindowInnerLocked(ws.mSession, ws);
8266 }
8267 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008268 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008269 Object tmp = new Object();
8270 synchronized (tmp) {
8271 try {
8272 tmp.wait(250);
8273 } catch (InterruptedException e) {
8274 }
8275 }
8276 }
Romain Guy06882f82009-06-10 13:36:04 -07008277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008278 mInLayout = true;
8279 try {
8280 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008282 int i = mPendingRemove.size()-1;
8283 if (i >= 0) {
8284 while (i >= 0) {
8285 WindowState w = mPendingRemove.get(i);
8286 removeWindowInnerLocked(w.mSession, w);
8287 i--;
8288 }
8289 mPendingRemove.clear();
8290
8291 mInLayout = false;
8292 assignLayersLocked();
8293 mLayoutNeeded = true;
8294 performLayoutAndPlaceSurfacesLocked();
8295
8296 } else {
8297 mInLayout = false;
8298 if (mLayoutNeeded) {
8299 requestAnimationLocked(0);
8300 }
8301 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008302 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008303 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8304 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008305 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008306 } catch (RuntimeException e) {
8307 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008308 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008309 }
8310 }
8311
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008312 private final int performLayoutLockedInner() {
8313 if (!mLayoutNeeded) {
8314 return 0;
8315 }
8316
8317 mLayoutNeeded = false;
8318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008319 final int dw = mDisplay.getWidth();
8320 final int dh = mDisplay.getHeight();
8321
8322 final int N = mWindows.size();
8323 int i;
8324
Joe Onorato8a9b2202010-02-26 18:56:32 -08008325 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008326 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8327
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008328 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008329
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008330 int seq = mLayoutSeq+1;
8331 if (seq < 0) seq = 0;
8332 mLayoutSeq = seq;
8333
8334 // First perform layout of any root windows (not attached
8335 // to another window).
8336 int topAttached = -1;
8337 for (i = N-1; i >= 0; i--) {
8338 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008339
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008340 // Don't do layout of a window if it is not visible, or
8341 // soon won't be visible, to avoid wasting time and funky
8342 // changes while a window is animating away.
8343 final AppWindowToken atoken = win.mAppToken;
8344 final boolean gone = win.mViewVisibility == View.GONE
8345 || !win.mRelayoutCalled
8346 || win.mRootToken.hidden
8347 || (atoken != null && atoken.hiddenRequested)
8348 || win.mAttachedHidden
8349 || win.mExiting || win.mDestroying;
8350
8351 if (!win.mLayoutAttached) {
8352 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8353 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8354 + " mLayoutAttached=" + win.mLayoutAttached);
8355 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8356 + win.mViewVisibility + " mRelayoutCalled="
8357 + win.mRelayoutCalled + " hidden="
8358 + win.mRootToken.hidden + " hiddenRequested="
8359 + (atoken != null && atoken.hiddenRequested)
8360 + " mAttachedHidden=" + win.mAttachedHidden);
8361 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008362
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008363 // If this view is GONE, then skip it -- keep the current
8364 // frame, and let the caller know so they can ignore it
8365 // if they want. (We do the normal layout for INVISIBLE
8366 // windows, since that means "perform layout as normal,
8367 // just don't display").
8368 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008369 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008370 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8371 win.mLayoutSeq = seq;
8372 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8373 + win.mFrame + " mContainingFrame="
8374 + win.mContainingFrame + " mDisplayFrame="
8375 + win.mDisplayFrame);
8376 } else {
8377 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008378 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008379 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008380 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008381
8382 // Now perform layout of attached windows, which usually
8383 // depend on the position of the window they are attached to.
8384 // XXX does not deal with windows that are attached to windows
8385 // that are themselves attached.
8386 for (i = topAttached; i >= 0; i--) {
8387 WindowState win = (WindowState) mWindows.get(i);
8388
8389 // If this view is GONE, then skip it -- keep the current
8390 // frame, and let the caller know so they can ignore it
8391 // if they want. (We do the normal layout for INVISIBLE
8392 // windows, since that means "perform layout as normal,
8393 // just don't display").
8394 if (win.mLayoutAttached) {
8395 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8396 + " mHaveFrame=" + win.mHaveFrame
8397 + " mViewVisibility=" + win.mViewVisibility
8398 + " mRelayoutCalled=" + win.mRelayoutCalled);
8399 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8400 || !win.mHaveFrame) {
8401 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8402 win.mLayoutSeq = seq;
8403 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8404 + win.mFrame + " mContainingFrame="
8405 + win.mContainingFrame + " mDisplayFrame="
8406 + win.mDisplayFrame);
8407 }
8408 }
8409 }
Jeff Brown349703e2010-06-22 01:27:15 -07008410
8411 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008412 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008413
8414 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 }
Romain Guy06882f82009-06-10 13:36:04 -07008416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417 private final void performLayoutAndPlaceSurfacesLockedInner(
8418 boolean recoveringMemory) {
8419 final long currentTime = SystemClock.uptimeMillis();
8420 final int dw = mDisplay.getWidth();
8421 final int dh = mDisplay.getHeight();
8422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008423 int i;
8424
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008425 if (mFocusMayChange) {
8426 mFocusMayChange = false;
8427 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8428 }
8429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008430 if (mFxSession == null) {
8431 mFxSession = new SurfaceSession();
8432 }
Romain Guy06882f82009-06-10 13:36:04 -07008433
Joe Onorato8a9b2202010-02-26 18:56:32 -08008434 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008435
8436 // Initialize state of exiting tokens.
8437 for (i=mExitingTokens.size()-1; i>=0; i--) {
8438 mExitingTokens.get(i).hasVisible = false;
8439 }
8440
8441 // Initialize state of exiting applications.
8442 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8443 mExitingAppTokens.get(i).hasVisible = false;
8444 }
8445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008446 boolean orientationChangeComplete = true;
8447 Session holdScreen = null;
8448 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008449 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008450 boolean focusDisplayed = false;
8451 boolean animating = false;
8452
8453 Surface.openTransaction();
8454 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008455 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008456 int repeats = 0;
8457 int changes = 0;
8458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008459 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008460 repeats++;
8461 if (repeats > 6) {
8462 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8463 mLayoutNeeded = false;
8464 break;
8465 }
8466
8467 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8468 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8469 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8470 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8471 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8472 assignLayersLocked();
8473 mLayoutNeeded = true;
8474 }
8475 }
8476 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8477 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8478 if (updateOrientationFromAppTokensLocked()) {
8479 mLayoutNeeded = true;
8480 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8481 }
8482 }
8483 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8484 mLayoutNeeded = true;
8485 }
8486 }
8487
8488 // FIRST LOOP: Perform a layout, if needed.
8489 if (repeats < 4) {
8490 changes = performLayoutLockedInner();
8491 if (changes != 0) {
8492 continue;
8493 }
8494 } else {
8495 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8496 changes = 0;
8497 }
8498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008499 final int transactionSequence = ++mTransactionSequence;
8500
8501 // Update animations of all applications, including those
8502 // associated with exiting/removed apps
8503 boolean tokensAnimating = false;
8504 final int NAT = mAppTokens.size();
8505 for (i=0; i<NAT; i++) {
8506 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8507 tokensAnimating = true;
8508 }
8509 }
8510 final int NEAT = mExitingAppTokens.size();
8511 for (i=0; i<NEAT; i++) {
8512 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8513 tokensAnimating = true;
8514 }
8515 }
8516
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008517 // SECOND LOOP: Execute animations and update visibility of windows.
8518
Joe Onorato8a9b2202010-02-26 18:56:32 -08008519 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008520 + transactionSequence + " tokensAnimating="
8521 + tokensAnimating);
8522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008524
8525 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008526 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008527 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008528
8529 mPolicy.beginAnimationLw(dw, dh);
8530
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008531 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008533 for (i=N-1; i>=0; i--) {
8534 WindowState w = (WindowState)mWindows.get(i);
8535
8536 final WindowManager.LayoutParams attrs = w.mAttrs;
8537
8538 if (w.mSurface != null) {
8539 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008540 if (w.commitFinishDrawingLocked(currentTime)) {
8541 if ((w.mAttrs.flags
8542 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008543 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008544 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008545 wallpaperMayChange = true;
8546 }
8547 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008548
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008549 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008550 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8551 animating = true;
8552 //w.dump(" ");
8553 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008554 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8555 wallpaperMayChange = true;
8556 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008557
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008558 if (mPolicy.doesForceHide(w, attrs)) {
8559 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008560 if (DEBUG_VISIBILITY) Slog.v(TAG,
8561 "Animation done that could impact force hide: "
8562 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008563 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008564 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008565 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8566 forceHiding = true;
8567 }
8568 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8569 boolean changed;
8570 if (forceHiding) {
8571 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008572 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8573 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008574 } else {
8575 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008576 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8577 "Now policy shown: " + w);
8578 if (changed) {
8579 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008580 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008581 // Assume we will need to animate. If
8582 // we don't (because the wallpaper will
8583 // stay with the lock screen), then we will
8584 // clean up later.
8585 Animation a = mPolicy.createForceHideEnterAnimation();
8586 if (a != null) {
8587 w.setAnimation(a);
8588 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008589 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008590 if (mCurrentFocus == null ||
8591 mCurrentFocus.mLayer < w.mLayer) {
8592 // We are showing on to of the current
8593 // focus, so re-evaluate focus to make
8594 // sure it is correct.
8595 mFocusMayChange = true;
8596 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008597 }
8598 }
8599 if (changed && (attrs.flags
8600 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8601 wallpaperMayChange = true;
8602 }
8603 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008605 mPolicy.animatingWindowLw(w, attrs);
8606 }
8607
8608 final AppWindowToken atoken = w.mAppToken;
8609 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8610 if (atoken.lastTransactionSequence != transactionSequence) {
8611 atoken.lastTransactionSequence = transactionSequence;
8612 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8613 atoken.startingDisplayed = false;
8614 }
8615 if ((w.isOnScreen() || w.mAttrs.type
8616 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8617 && !w.mExiting && !w.mDestroying) {
8618 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008619 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008620 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008621 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008622 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008623 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008624 + " pv=" + w.mPolicyVisibility
8625 + " dp=" + w.mDrawPending
8626 + " cdp=" + w.mCommitDrawPending
8627 + " ah=" + w.mAttachedHidden
8628 + " th=" + atoken.hiddenRequested
8629 + " a=" + w.mAnimating);
8630 }
8631 }
8632 if (w != atoken.startingWindow) {
8633 if (!atoken.freezingScreen || !w.mAppFreezing) {
8634 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008635 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008636 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008637 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 "tokenMayBeDrawn: " + atoken
8639 + " freezingScreen=" + atoken.freezingScreen
8640 + " mAppFreezing=" + w.mAppFreezing);
8641 tokenMayBeDrawn = true;
8642 }
8643 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008644 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008645 atoken.startingDisplayed = true;
8646 }
8647 }
8648 } else if (w.mReadyToShow) {
8649 w.performShowLocked();
8650 }
8651 }
8652
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008653 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654
8655 if (tokenMayBeDrawn) {
8656 // See if any windows have been drawn, so they (and others
8657 // associated with them) can now be shown.
8658 final int NT = mTokenList.size();
8659 for (i=0; i<NT; i++) {
8660 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8661 if (wtoken == null) {
8662 continue;
8663 }
8664 if (wtoken.freezingScreen) {
8665 int numInteresting = wtoken.numInterestingWindows;
8666 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008667 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 "allDrawn: " + wtoken
8669 + " interesting=" + numInteresting
8670 + " drawn=" + wtoken.numDrawnWindows);
8671 wtoken.showAllWindowsLocked();
8672 unsetAppFreezingScreenLocked(wtoken, false, true);
8673 orientationChangeComplete = true;
8674 }
8675 } else if (!wtoken.allDrawn) {
8676 int numInteresting = wtoken.numInterestingWindows;
8677 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008678 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008679 "allDrawn: " + wtoken
8680 + " interesting=" + numInteresting
8681 + " drawn=" + wtoken.numDrawnWindows);
8682 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008683 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008684
8685 // We can now show all of the drawn windows!
8686 if (!mOpeningApps.contains(wtoken)) {
8687 wtoken.showAllWindowsLocked();
8688 }
8689 }
8690 }
8691 }
8692 }
8693
8694 // If we are ready to perform an app transition, check through
8695 // all of the app tokens to be shown and see if they are ready
8696 // to go.
8697 if (mAppTransitionReady) {
8698 int NN = mOpeningApps.size();
8699 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008700 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008701 "Checking " + NN + " opening apps (frozen="
8702 + mDisplayFrozen + " timeout="
8703 + mAppTransitionTimeout + ")...");
8704 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8705 // If the display isn't frozen, wait to do anything until
8706 // all of the apps are ready. Otherwise just go because
8707 // we'll unfreeze the display when everyone is ready.
8708 for (i=0; i<NN && goodToGo; i++) {
8709 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008710 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008711 "Check opening app" + wtoken + ": allDrawn="
8712 + wtoken.allDrawn + " startingDisplayed="
8713 + wtoken.startingDisplayed);
8714 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8715 && !wtoken.startingMoved) {
8716 goodToGo = false;
8717 }
8718 }
8719 }
8720 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008721 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008722 int transit = mNextAppTransition;
8723 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008724 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008725 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008726 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008727 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008728 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008729 mAppTransitionTimeout = false;
8730 mStartingIconInTransition = false;
8731 mSkipAppTransitionAnimation = false;
8732
8733 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8734
Dianne Hackborna8f60182009-09-01 19:01:50 -07008735 // If there are applications waiting to come to the
8736 // top of the stack, now is the time to move their windows.
8737 // (Note that we don't do apps going to the bottom
8738 // here -- we want to keep their windows in the old
8739 // Z-order until the animation completes.)
8740 if (mToTopApps.size() > 0) {
8741 NN = mAppTokens.size();
8742 for (i=0; i<NN; i++) {
8743 AppWindowToken wtoken = mAppTokens.get(i);
8744 if (wtoken.sendingToTop) {
8745 wtoken.sendingToTop = false;
8746 moveAppWindowsLocked(wtoken, NN, false);
8747 }
8748 }
8749 mToTopApps.clear();
8750 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008751
Dianne Hackborn25994b42009-09-04 14:21:19 -07008752 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008753
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008754 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008755 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008756
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008757 // The top-most window will supply the layout params,
8758 // and we will determine it below.
8759 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008760 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008761 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008762
Joe Onorato8a9b2202010-02-26 18:56:32 -08008763 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008764 "New wallpaper target=" + mWallpaperTarget
8765 + ", lower target=" + mLowerWallpaperTarget
8766 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008767 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008768 // Do a first pass through the tokens for two
8769 // things:
8770 // (1) Determine if both the closing and opening
8771 // app token sets are wallpaper targets, in which
8772 // case special animations are needed
8773 // (since the wallpaper needs to stay static
8774 // behind them).
8775 // (2) Find the layout params of the top-most
8776 // application window in the tokens, which is
8777 // what will control the animation theme.
8778 final int NC = mClosingApps.size();
8779 NN = NC + mOpeningApps.size();
8780 for (i=0; i<NN; i++) {
8781 AppWindowToken wtoken;
8782 int mode;
8783 if (i < NC) {
8784 wtoken = mClosingApps.get(i);
8785 mode = 1;
8786 } else {
8787 wtoken = mOpeningApps.get(i-NC);
8788 mode = 2;
8789 }
8790 if (mLowerWallpaperTarget != null) {
8791 if (mLowerWallpaperTarget.mAppToken == wtoken
8792 || mUpperWallpaperTarget.mAppToken == wtoken) {
8793 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008794 }
8795 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008796 if (wtoken.appFullscreen) {
8797 WindowState ws = wtoken.findMainWindow();
8798 if (ws != null) {
8799 // If this is a compatibility mode
8800 // window, we will always use its anim.
8801 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8802 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008803 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008804 bestAnimLayer = Integer.MAX_VALUE;
8805 } else if (ws.mLayer > bestAnimLayer) {
8806 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008807 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008808 bestAnimLayer = ws.mLayer;
8809 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008810 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008811 }
8812 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008813
Dianne Hackborn25994b42009-09-04 14:21:19 -07008814 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008815 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008816 "Wallpaper animation!");
8817 switch (transit) {
8818 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8819 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8820 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8821 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8822 break;
8823 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8824 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8825 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8826 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8827 break;
8828 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008829 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008830 "New transit: " + transit);
8831 } else if (oldWallpaper != null) {
8832 // We are transitioning from an activity with
8833 // a wallpaper to one without.
8834 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008835 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008836 "New transit away from wallpaper: " + transit);
8837 } else if (mWallpaperTarget != null) {
8838 // We are transitioning from an activity without
8839 // a wallpaper to now showing the wallpaper
8840 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008841 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008842 "New transit into wallpaper: " + transit);
8843 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008844
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008845 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8846 mLastEnterAnimToken = animToken;
8847 mLastEnterAnimParams = animLp;
8848 } else if (mLastEnterAnimParams != null) {
8849 animLp = mLastEnterAnimParams;
8850 mLastEnterAnimToken = null;
8851 mLastEnterAnimParams = null;
8852 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008853
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008854 // If all closing windows are obscured, then there is
8855 // no need to do an animation. This is the case, for
8856 // example, when this transition is being done behind
8857 // the lock screen.
8858 if (!mPolicy.allowAppAnimationsLw()) {
8859 animLp = null;
8860 }
8861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008862 NN = mOpeningApps.size();
8863 for (i=0; i<NN; i++) {
8864 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008865 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866 "Now opening app" + wtoken);
8867 wtoken.reportedVisible = false;
8868 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008869 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008870 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008871 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008872 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008873 wtoken.showAllWindowsLocked();
8874 }
8875 NN = mClosingApps.size();
8876 for (i=0; i<NN; i++) {
8877 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008878 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008879 "Now closing app" + wtoken);
8880 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008881 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008882 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008883 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008884 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 // Force the allDrawn flag, because we want to start
8886 // this guy's animations regardless of whether it's
8887 // gotten drawn.
8888 wtoken.allDrawn = true;
8889 }
8890
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008891 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008893 mOpeningApps.clear();
8894 mClosingApps.clear();
8895
8896 // This has changed the visibility of windows, so perform
8897 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008898 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008899 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008900 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8901 assignLayersLocked();
8902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008903 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008904 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008905 }
8906 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008907
Dianne Hackborn16064f92010-03-25 00:47:24 -07008908 int adjResult = 0;
8909
Dianne Hackborna8f60182009-09-01 19:01:50 -07008910 if (!animating && mAppTransitionRunning) {
8911 // We have finished the animation of an app transition. To do
8912 // this, we have delayed a lot of operations like showing and
8913 // hiding apps, moving apps in Z-order, etc. The app token list
8914 // reflects the correct Z-order, but the window list may now
8915 // be out of sync with it. So here we will just rebuild the
8916 // entire app window list. Fun!
8917 mAppTransitionRunning = false;
8918 // Clear information about apps that were moving.
8919 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008920
Dianne Hackborna8f60182009-09-01 19:01:50 -07008921 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008922 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008923 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008924 moveInputMethodWindowsIfNeededLocked(false);
8925 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008926 // Since the window list has been rebuilt, focus might
8927 // have to be recomputed since the actual order of windows
8928 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008929 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008930 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008931
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008932 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008933 // At this point, there was a window with a wallpaper that
8934 // was force hiding other windows behind it, but now it
8935 // is going away. This may be simple -- just animate
8936 // away the wallpaper and its window -- or it may be
8937 // hard -- the wallpaper now needs to be shown behind
8938 // something that was hidden.
8939 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008940 if (mLowerWallpaperTarget != null
8941 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008942 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008943 "wallpaperForceHiding changed with lower="
8944 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008945 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008946 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
8947 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
8948 if (mLowerWallpaperTarget.mAppToken.hidden) {
8949 // The lower target has become hidden before we
8950 // actually started the animation... let's completely
8951 // re-evaluate everything.
8952 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008953 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008954 }
8955 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07008956 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008957 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008958 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008959 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008960 + " NEW: " + mWallpaperTarget
8961 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008962 if (mLowerWallpaperTarget == null) {
8963 // Whoops, we don't need a special wallpaper animation.
8964 // Clear them out.
8965 forceHiding = false;
8966 for (i=N-1; i>=0; i--) {
8967 WindowState w = (WindowState)mWindows.get(i);
8968 if (w.mSurface != null) {
8969 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07008970 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008971 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008972 forceHiding = true;
8973 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8974 if (!w.mAnimating) {
8975 // We set the animation above so it
8976 // is not yet running.
8977 w.clearAnimation();
8978 }
8979 }
8980 }
8981 }
8982 }
8983 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008984
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008985 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008986 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008987 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07008988 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008989 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008990
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008991 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008992 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008993 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008994 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008995 assignLayersLocked();
8996 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008997 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008998 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008999 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009000 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009001
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009002 if (mFocusMayChange) {
9003 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009004 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009005 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009006 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009007 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009008 }
9009
9010 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009011 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009012 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009013
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009014 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9015 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009016
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009017 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009018
9019 // THIRD LOOP: Update the surfaces of all windows.
9020
9021 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9022
9023 boolean obscured = false;
9024 boolean blurring = false;
9025 boolean dimming = false;
9026 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009027 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009028 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009029
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009030 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009032 for (i=N-1; i>=0; i--) {
9033 WindowState w = (WindowState)mWindows.get(i);
9034
9035 boolean displayed = false;
9036 final WindowManager.LayoutParams attrs = w.mAttrs;
9037 final int attrFlags = attrs.flags;
9038
9039 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009040 // XXX NOTE: The logic here could be improved. We have
9041 // the decision about whether to resize a window separated
9042 // from whether to hide the surface. This can cause us to
9043 // resize a surface even if we are going to hide it. You
9044 // can see this by (1) holding device in landscape mode on
9045 // home screen; (2) tapping browser icon (device will rotate
9046 // to landscape; (3) tap home. The wallpaper will be resized
9047 // in step 2 but then immediately hidden, causing us to
9048 // have to resize and then redraw it again in step 3. It
9049 // would be nice to figure out how to avoid this, but it is
9050 // difficult because we do need to resize surfaces in some
9051 // cases while they are hidden such as when first showing a
9052 // window.
9053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009054 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009055 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009056 TAG, "Placing surface #" + i + " " + w.mSurface
9057 + ": new=" + w.mShownFrame + ", old="
9058 + w.mLastShownFrame);
9059
9060 boolean resize;
9061 int width, height;
9062 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9063 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9064 w.mLastRequestedHeight != w.mRequestedHeight;
9065 // for a scaled surface, we just want to use
9066 // the requested size.
9067 width = w.mRequestedWidth;
9068 height = w.mRequestedHeight;
9069 w.mLastRequestedWidth = width;
9070 w.mLastRequestedHeight = height;
9071 w.mLastShownFrame.set(w.mShownFrame);
9072 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009073 if (SHOW_TRANSACTIONS) logSurface(w,
9074 "POS " + w.mShownFrame.left
9075 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009076 w.mSurfaceX = w.mShownFrame.left;
9077 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009078 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9079 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009080 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009081 if (!recoveringMemory) {
9082 reclaimSomeSurfaceMemoryLocked(w, "position");
9083 }
9084 }
9085 } else {
9086 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9087 width = w.mShownFrame.width();
9088 height = w.mShownFrame.height();
9089 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009090 }
9091
9092 if (resize) {
9093 if (width < 1) width = 1;
9094 if (height < 1) height = 1;
9095 if (w.mSurface != null) {
9096 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009097 if (SHOW_TRANSACTIONS) logSurface(w,
9098 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009099 + w.mShownFrame.top + " SIZE "
9100 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009101 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009102 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009103 w.mSurfaceW = width;
9104 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009105 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009106 w.mSurfaceX = w.mShownFrame.left;
9107 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009108 w.mSurface.setPosition(w.mShownFrame.left,
9109 w.mShownFrame.top);
9110 } catch (RuntimeException e) {
9111 // If something goes wrong with the surface (such
9112 // as running out of memory), don't take down the
9113 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009114 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009115 + "size=(" + width + "x" + height
9116 + "), pos=(" + w.mShownFrame.left
9117 + "," + w.mShownFrame.top + ")", e);
9118 if (!recoveringMemory) {
9119 reclaimSomeSurfaceMemoryLocked(w, "size");
9120 }
9121 }
9122 }
9123 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009124 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009125 w.mContentInsetsChanged =
9126 !w.mLastContentInsets.equals(w.mContentInsets);
9127 w.mVisibleInsetsChanged =
9128 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009129 boolean configChanged =
9130 w.mConfiguration != mCurConfiguration
9131 && (w.mConfiguration == null
9132 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009133 if (DEBUG_CONFIGURATION && configChanged) {
9134 Slog.v(TAG, "Win " + w + " config changed: "
9135 + mCurConfiguration);
9136 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009137 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009138 + ": configChanged=" + configChanged
9139 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009140 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009142 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009143 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009144 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 w.mLastFrame.set(w.mFrame);
9146 w.mLastContentInsets.set(w.mContentInsets);
9147 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009148 // If the screen is currently frozen, then keep
9149 // it frozen until this window draws at its new
9150 // orientation.
9151 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009152 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009153 "Resizing while display frozen: " + w);
9154 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009155 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009156 mWindowsFreezingScreen = true;
9157 // XXX should probably keep timeout from
9158 // when we first froze the display.
9159 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9160 mH.sendMessageDelayed(mH.obtainMessage(
9161 H.WINDOW_FREEZE_TIMEOUT), 2000);
9162 }
9163 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009164 // If the orientation is changing, then we need to
9165 // hold off on unfreezing the display until this
9166 // window has been redrawn; to do that, we need
9167 // to go through the process of getting informed
9168 // by the application when it has finished drawing.
9169 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009170 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 "Orientation start waiting for draw in "
9172 + w + ", surface " + w.mSurface);
9173 w.mDrawPending = true;
9174 w.mCommitDrawPending = false;
9175 w.mReadyToShow = false;
9176 if (w.mAppToken != null) {
9177 w.mAppToken.allDrawn = false;
9178 }
9179 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009180 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009181 "Resizing window " + w + " to " + w.mFrame);
9182 mResizingWindows.add(w);
9183 } else if (w.mOrientationChanging) {
9184 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009185 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009186 "Orientation not waiting for draw in "
9187 + w + ", surface " + w.mSurface);
9188 w.mOrientationChanging = false;
9189 }
9190 }
9191 }
9192
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009193 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009194 if (!w.mLastHidden) {
9195 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009196 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9197 + w.mRootToken.waitingToShow + " polvis="
9198 + w.mPolicyVisibility + " atthid="
9199 + w.mAttachedHidden + " tokhid="
9200 + w.mRootToken.hidden + " vis="
9201 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009202 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009203 if (SHOW_TRANSACTIONS) logSurface(w,
9204 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009206 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009207 try {
9208 w.mSurface.hide();
9209 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009210 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 }
9212 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009213 mInputMonitor.windowIsBecomingInvisibleLw(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009214 }
9215 // If we are waiting for this window to handle an
9216 // orientation change, well, it is hidden, so
9217 // doesn't really matter. Note that this does
9218 // introduce a potential glitch if the window
9219 // becomes unhidden before it has drawn for the
9220 // new orientation.
9221 if (w.mOrientationChanging) {
9222 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009223 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009224 "Orientation change skips hidden " + w);
9225 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 } else if (w.mLastLayer != w.mAnimLayer
9227 || w.mLastAlpha != w.mShownAlpha
9228 || w.mLastDsDx != w.mDsDx
9229 || w.mLastDtDx != w.mDtDx
9230 || w.mLastDsDy != w.mDsDy
9231 || w.mLastDtDy != w.mDtDy
9232 || w.mLastHScale != w.mHScale
9233 || w.mLastVScale != w.mVScale
9234 || w.mLastHidden) {
9235 displayed = true;
9236 w.mLastAlpha = w.mShownAlpha;
9237 w.mLastLayer = w.mAnimLayer;
9238 w.mLastDsDx = w.mDsDx;
9239 w.mLastDtDx = w.mDtDx;
9240 w.mLastDsDy = w.mDsDy;
9241 w.mLastDtDy = w.mDtDy;
9242 w.mLastHScale = w.mHScale;
9243 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009244 if (SHOW_TRANSACTIONS) logSurface(w,
9245 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009246 + " matrix=[" + (w.mDsDx*w.mHScale)
9247 + "," + (w.mDtDx*w.mVScale)
9248 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009249 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009250 if (w.mSurface != null) {
9251 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009252 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009254 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009255 w.mSurface.setLayer(w.mAnimLayer);
9256 w.mSurface.setMatrix(
9257 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9258 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9259 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009260 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009261 if (!recoveringMemory) {
9262 reclaimSomeSurfaceMemoryLocked(w, "update");
9263 }
9264 }
9265 }
9266
9267 if (w.mLastHidden && !w.mDrawPending
9268 && !w.mCommitDrawPending
9269 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009270 if (SHOW_TRANSACTIONS) logSurface(w,
9271 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009272 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009273 + " during relayout");
9274 if (showSurfaceRobustlyLocked(w)) {
9275 w.mHasDrawn = true;
9276 w.mLastHidden = false;
9277 } else {
9278 w.mOrientationChanging = false;
9279 }
9280 }
9281 if (w.mSurface != null) {
9282 w.mToken.hasVisible = true;
9283 }
9284 } else {
9285 displayed = true;
9286 }
9287
9288 if (displayed) {
9289 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009290 if (attrs.width == LayoutParams.MATCH_PARENT
9291 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009292 covered = true;
9293 }
9294 }
9295 if (w.mOrientationChanging) {
9296 if (w.mDrawPending || w.mCommitDrawPending) {
9297 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009298 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009299 "Orientation continue waiting for draw in " + w);
9300 } else {
9301 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009302 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009303 "Orientation change complete in " + w);
9304 }
9305 }
9306 w.mToken.hasVisible = true;
9307 }
9308 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009309 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009310 "Orientation change skips hidden " + w);
9311 w.mOrientationChanging = false;
9312 }
9313
9314 final boolean canBeSeen = w.isDisplayedLw();
9315
9316 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9317 focusDisplayed = true;
9318 }
9319
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009320 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009323 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009324 if (w.mSurface != null) {
9325 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9326 holdScreen = w.mSession;
9327 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009328 if (!syswin && w.mAttrs.screenBrightness >= 0
9329 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009330 screenBrightness = w.mAttrs.screenBrightness;
9331 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009332 if (!syswin && w.mAttrs.buttonBrightness >= 0
9333 && buttonBrightness < 0) {
9334 buttonBrightness = w.mAttrs.buttonBrightness;
9335 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009336 if (canBeSeen
9337 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9338 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9339 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009340 syswin = true;
9341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009343
Dianne Hackborn25994b42009-09-04 14:21:19 -07009344 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9345 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009346 // This window completely covers everything behind it,
9347 // so we want to leave all of them as unblurred (for
9348 // performance reasons).
9349 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009350 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009351 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009352 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009353 obscured = true;
9354 if (mBackgroundFillerSurface == null) {
9355 try {
9356 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009357 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009358 0, dw, dh,
9359 PixelFormat.OPAQUE,
9360 Surface.FX_SURFACE_NORMAL);
9361 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009362 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009363 }
9364 }
9365 try {
9366 mBackgroundFillerSurface.setPosition(0, 0);
9367 mBackgroundFillerSurface.setSize(dw, dh);
9368 // Using the same layer as Dim because they will never be shown at the
9369 // same time.
9370 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9371 mBackgroundFillerSurface.show();
9372 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009373 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009374 }
9375 backgroundFillerShown = true;
9376 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009377 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009378 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009379 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009380 + ": blurring=" + blurring
9381 + " obscured=" + obscured
9382 + " displayed=" + displayed);
9383 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9384 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009385 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009386 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009387 if (mDimAnimator == null) {
9388 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009389 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009390 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009391 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393 }
9394 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9395 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009396 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009397 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009399 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009400 + mBlurSurface + ": CREATE");
9401 try {
Romain Guy06882f82009-06-10 13:36:04 -07009402 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009403 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 -1, 16, 16,
9405 PixelFormat.OPAQUE,
9406 Surface.FX_SURFACE_BLUR);
9407 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009408 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009409 }
9410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009412 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9413 + mBlurSurface + ": pos=(0,0) (" +
9414 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009415 mBlurSurface.setPosition(0, 0);
9416 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009417 mBlurSurface.setLayer(w.mAnimLayer-2);
9418 if (!mBlurShown) {
9419 try {
9420 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9421 + mBlurSurface + ": SHOW");
9422 mBlurSurface.show();
9423 } catch (RuntimeException e) {
9424 Slog.w(TAG, "Failure showing blur surface", e);
9425 }
9426 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 }
9428 }
9429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009430 }
9431 }
9432 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009433
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009434 if (obscuredChanged && mWallpaperTarget == w) {
9435 // This is the wallpaper target and its obscured state
9436 // changed... make sure the current wallaper's visibility
9437 // has been updated accordingly.
9438 updateWallpaperVisibilityLocked();
9439 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009440 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009441
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009442 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9443 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009444 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009445 try {
9446 mBackgroundFillerSurface.hide();
9447 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009448 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009449 }
9450 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009451
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009452 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009453 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9454 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009455 }
Romain Guy06882f82009-06-10 13:36:04 -07009456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009457 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009458 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009459 + ": HIDE");
9460 try {
9461 mBlurSurface.hide();
9462 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009463 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009464 }
9465 mBlurShown = false;
9466 }
9467
Joe Onorato8a9b2202010-02-26 18:56:32 -08009468 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009470 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009471 }
9472
9473 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009474
Joe Onorato8a9b2202010-02-26 18:56:32 -08009475 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 "With display frozen, orientationChangeComplete="
9477 + orientationChangeComplete);
9478 if (orientationChangeComplete) {
9479 if (mWindowsFreezingScreen) {
9480 mWindowsFreezingScreen = false;
9481 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9482 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009483 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009484 }
Romain Guy06882f82009-06-10 13:36:04 -07009485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009486 i = mResizingWindows.size();
9487 if (i > 0) {
9488 do {
9489 i--;
9490 WindowState win = mResizingWindows.get(i);
9491 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009492 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9493 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009494 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009495 boolean configChanged =
9496 win.mConfiguration != mCurConfiguration
9497 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009498 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9499 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9500 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009501 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009502 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009503 + " / " + mCurConfiguration + " / 0x"
9504 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009505 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009506 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009507 win.mClient.resized(win.mFrame.width(),
9508 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009509 win.mLastVisibleInsets, win.mDrawPending,
9510 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009511 win.mContentInsetsChanged = false;
9512 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009513 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514 } catch (RemoteException e) {
9515 win.mOrientationChanging = false;
9516 }
9517 } while (i > 0);
9518 mResizingWindows.clear();
9519 }
Romain Guy06882f82009-06-10 13:36:04 -07009520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009521 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009522 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 i = mDestroySurface.size();
9524 if (i > 0) {
9525 do {
9526 i--;
9527 WindowState win = mDestroySurface.get(i);
9528 win.mDestroying = false;
9529 if (mInputMethodWindow == win) {
9530 mInputMethodWindow = null;
9531 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009532 if (win == mWallpaperTarget) {
9533 wallpaperDestroyed = true;
9534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009535 win.destroySurfaceLocked();
9536 } while (i > 0);
9537 mDestroySurface.clear();
9538 }
9539
9540 // Time to remove any exiting tokens?
9541 for (i=mExitingTokens.size()-1; i>=0; i--) {
9542 WindowToken token = mExitingTokens.get(i);
9543 if (!token.hasVisible) {
9544 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009545 if (token.windowType == TYPE_WALLPAPER) {
9546 mWallpaperTokens.remove(token);
9547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009548 }
9549 }
9550
9551 // Time to remove any exiting applications?
9552 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9553 AppWindowToken token = mExitingAppTokens.get(i);
9554 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009555 // Make sure there is no animation running on this token,
9556 // so any windows associated with it will be removed as
9557 // soon as their animations are complete
9558 token.animation = null;
9559 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009560 mAppTokens.remove(token);
9561 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009562 if (mLastEnterAnimToken == token) {
9563 mLastEnterAnimToken = null;
9564 mLastEnterAnimParams = null;
9565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009566 }
9567 }
9568
Dianne Hackborna8f60182009-09-01 19:01:50 -07009569 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009570
Dianne Hackborna8f60182009-09-01 19:01:50 -07009571 if (!animating && mAppTransitionRunning) {
9572 // We have finished the animation of an app transition. To do
9573 // this, we have delayed a lot of operations like showing and
9574 // hiding apps, moving apps in Z-order, etc. The app token list
9575 // reflects the correct Z-order, but the window list may now
9576 // be out of sync with it. So here we will just rebuild the
9577 // entire app window list. Fun!
9578 mAppTransitionRunning = false;
9579 needRelayout = true;
9580 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009581 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009582 // Clear information about apps that were moving.
9583 mToBottomApps.clear();
9584 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 if (focusDisplayed) {
9587 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9588 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009589 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009590 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009591 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009592 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009593 requestAnimationLocked(0);
9594 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009595 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9596 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009597
9598 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9599 + " holdScreen=" + holdScreen);
9600 if (!mDisplayFrozen) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009601 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009602 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9603 mPowerManager.setScreenBrightnessOverride(-1);
9604 } else {
9605 mPowerManager.setScreenBrightnessOverride((int)
9606 (screenBrightness * Power.BRIGHTNESS_ON));
9607 }
9608 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9609 mPowerManager.setButtonBrightnessOverride(-1);
9610 } else {
9611 mPowerManager.setButtonBrightnessOverride((int)
9612 (buttonBrightness * Power.BRIGHTNESS_ON));
9613 }
9614 if (holdScreen != mHoldingScreenOn) {
9615 mHoldingScreenOn = holdScreen;
9616 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9617 mH.sendMessage(m);
9618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009620
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009621 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009622 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009623 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9624 LocalPowerManager.BUTTON_EVENT, true);
9625 mTurnOnScreen = false;
9626 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009627
9628 // Check to see if we are now in a state where the screen should
9629 // be enabled, because the window obscured flags have changed.
9630 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009631 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009632
9633 /**
9634 * Must be called with the main window manager lock held.
9635 */
9636 void setHoldScreenLocked(boolean holding) {
9637 boolean state = mHoldingScreenWakeLock.isHeld();
9638 if (holding != state) {
9639 if (holding) {
9640 mHoldingScreenWakeLock.acquire();
9641 } else {
9642 mPolicy.screenOnStoppedLw();
9643 mHoldingScreenWakeLock.release();
9644 }
9645 }
9646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009647
9648 void requestAnimationLocked(long delay) {
9649 if (!mAnimationPending) {
9650 mAnimationPending = true;
9651 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9652 }
9653 }
Romain Guy06882f82009-06-10 13:36:04 -07009654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009655 /**
9656 * Have the surface flinger show a surface, robustly dealing with
9657 * error conditions. In particular, if there is not enough memory
9658 * to show the surface, then we will try to get rid of other surfaces
9659 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009660 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 * @return Returns true if the surface was successfully shown.
9662 */
9663 boolean showSurfaceRobustlyLocked(WindowState win) {
9664 try {
9665 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009666 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009667 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009668 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009669 if (DEBUG_VISIBILITY) Slog.v(TAG,
9670 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009671 win.mTurnOnScreen = false;
9672 mTurnOnScreen = true;
9673 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009674 }
9675 return true;
9676 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009677 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009678 }
Romain Guy06882f82009-06-10 13:36:04 -07009679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009680 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009682 return false;
9683 }
Romain Guy06882f82009-06-10 13:36:04 -07009684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9686 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009687
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009688 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009689 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009691 if (mForceRemoves == null) {
9692 mForceRemoves = new ArrayList<WindowState>();
9693 }
Romain Guy06882f82009-06-10 13:36:04 -07009694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009695 long callingIdentity = Binder.clearCallingIdentity();
9696 try {
9697 // There was some problem... first, do a sanity check of the
9698 // window list to make sure we haven't left any dangling surfaces
9699 // around.
9700 int N = mWindows.size();
9701 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009702 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009703 for (int i=0; i<N; i++) {
9704 WindowState ws = (WindowState)mWindows.get(i);
9705 if (ws.mSurface != null) {
9706 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009707 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009708 + ws + " surface=" + ws.mSurface
9709 + " token=" + win.mToken
9710 + " pid=" + ws.mSession.mPid
9711 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009712 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009713 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009714 ws.mSurface = null;
9715 mForceRemoves.add(ws);
9716 i--;
9717 N--;
9718 leakedSurface = true;
9719 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009720 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009721 + ws + " surface=" + ws.mSurface
9722 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009723 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009724 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009725 ws.mSurface = null;
9726 leakedSurface = true;
9727 }
9728 }
9729 }
Romain Guy06882f82009-06-10 13:36:04 -07009730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009731 boolean killedApps = false;
9732 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009733 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009734 SparseIntArray pidCandidates = new SparseIntArray();
9735 for (int i=0; i<N; i++) {
9736 WindowState ws = (WindowState)mWindows.get(i);
9737 if (ws.mSurface != null) {
9738 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9739 }
9740 }
9741 if (pidCandidates.size() > 0) {
9742 int[] pids = new int[pidCandidates.size()];
9743 for (int i=0; i<pids.length; i++) {
9744 pids[i] = pidCandidates.keyAt(i);
9745 }
9746 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009747 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009748 killedApps = true;
9749 }
9750 } catch (RemoteException e) {
9751 }
9752 }
9753 }
Romain Guy06882f82009-06-10 13:36:04 -07009754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 if (leakedSurface || killedApps) {
9756 // We managed to reclaim some memory, so get rid of the trouble
9757 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009758 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009759 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009760 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009761 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009762 win.mSurface = null;
9763 }
Romain Guy06882f82009-06-10 13:36:04 -07009764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 try {
9766 win.mClient.dispatchGetNewSurface();
9767 } catch (RemoteException e) {
9768 }
9769 }
9770 } finally {
9771 Binder.restoreCallingIdentity(callingIdentity);
9772 }
9773 }
Romain Guy06882f82009-06-10 13:36:04 -07009774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 private boolean updateFocusedWindowLocked(int mode) {
9776 WindowState newFocus = computeFocusedWindowLocked();
9777 if (mCurrentFocus != newFocus) {
9778 // This check makes sure that we don't already have the focus
9779 // change message pending.
9780 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9781 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009782 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009783 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9784 final WindowState oldFocus = mCurrentFocus;
9785 mCurrentFocus = newFocus;
9786 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 final WindowState imWindow = mInputMethodWindow;
9789 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009790 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009792 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9793 mLayoutNeeded = true;
9794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9796 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009797 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9798 // Client will do the layout, but we need to assign layers
9799 // for handleNewWindowLocked() below.
9800 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801 }
9802 }
Jeff Brown349703e2010-06-22 01:27:15 -07009803
9804 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9805 // If we defer assigning layers, then the caller is responsible for
9806 // doing this part.
9807 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009809 return true;
9810 }
9811 return false;
9812 }
Jeff Brown349703e2010-06-22 01:27:15 -07009813
9814 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009815 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009816 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009817
9818 private WindowState computeFocusedWindowLocked() {
9819 WindowState result = null;
9820 WindowState win;
9821
9822 int i = mWindows.size() - 1;
9823 int nextAppIndex = mAppTokens.size()-1;
9824 WindowToken nextApp = nextAppIndex >= 0
9825 ? mAppTokens.get(nextAppIndex) : null;
9826
9827 while (i >= 0) {
9828 win = (WindowState)mWindows.get(i);
9829
Joe Onorato8a9b2202010-02-26 18:56:32 -08009830 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009831 TAG, "Looking for focus: " + i
9832 + " = " + win
9833 + ", flags=" + win.mAttrs.flags
9834 + ", canReceive=" + win.canReceiveKeys());
9835
9836 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009838 // If this window's application has been removed, just skip it.
9839 if (thisApp != null && thisApp.removed) {
9840 i--;
9841 continue;
9842 }
Romain Guy06882f82009-06-10 13:36:04 -07009843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009844 // If there is a focused app, don't allow focus to go to any
9845 // windows below it. If this is an application window, step
9846 // through the app tokens until we find its app.
9847 if (thisApp != null && nextApp != null && thisApp != nextApp
9848 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9849 int origAppIndex = nextAppIndex;
9850 while (nextAppIndex > 0) {
9851 if (nextApp == mFocusedApp) {
9852 // Whoops, we are below the focused app... no focus
9853 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009854 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009855 TAG, "Reached focused app: " + mFocusedApp);
9856 return null;
9857 }
9858 nextAppIndex--;
9859 nextApp = mAppTokens.get(nextAppIndex);
9860 if (nextApp == thisApp) {
9861 break;
9862 }
9863 }
9864 if (thisApp != nextApp) {
9865 // Uh oh, the app token doesn't exist! This shouldn't
9866 // happen, but if it does we can get totally hosed...
9867 // so restart at the original app.
9868 nextAppIndex = origAppIndex;
9869 nextApp = mAppTokens.get(nextAppIndex);
9870 }
9871 }
9872
9873 // Dispatch to this window if it is wants key events.
9874 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009875 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009876 TAG, "Found focus @ " + i + " = " + win);
9877 result = win;
9878 break;
9879 }
9880
9881 i--;
9882 }
9883
9884 return result;
9885 }
9886
9887 private void startFreezingDisplayLocked() {
9888 if (mDisplayFrozen) {
9889 return;
9890 }
Romain Guy06882f82009-06-10 13:36:04 -07009891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009894 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009895 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896 if (mFreezeGcPending != 0) {
9897 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009898 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 mH.removeMessages(H.FORCE_GC);
9900 Runtime.getRuntime().gc();
9901 mFreezeGcPending = now;
9902 }
9903 } else {
9904 mFreezeGcPending = now;
9905 }
Romain Guy06882f82009-06-10 13:36:04 -07009906
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009907 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
9908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009910
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009911 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009912
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009913 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9914 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009915 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009916 mAppTransitionReady = true;
9917 }
Romain Guy06882f82009-06-10 13:36:04 -07009918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009919 if (PROFILE_ORIENTATION) {
9920 File file = new File("/data/system/frozen");
9921 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9922 }
9923 Surface.freezeDisplay(0);
9924 }
Romain Guy06882f82009-06-10 13:36:04 -07009925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009926 private void stopFreezingDisplayLocked() {
9927 if (!mDisplayFrozen) {
9928 return;
9929 }
Romain Guy06882f82009-06-10 13:36:04 -07009930
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009931 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9932 return;
9933 }
9934
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009935 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
9936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937 mDisplayFrozen = false;
9938 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9939 if (PROFILE_ORIENTATION) {
9940 Debug.stopMethodTracing();
9941 }
9942 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009943
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009944 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009945
Christopher Tateb696aee2010-04-02 19:08:30 -07009946 // While the display is frozen we don't re-compute the orientation
9947 // to avoid inconsistent states. However, something interesting
9948 // could have actually changed during that time so re-evaluate it
9949 // now to catch that.
9950 if (updateOrientationFromAppTokensLocked()) {
9951 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9952 }
9953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009954 // A little kludge: a lot could have happened while the
9955 // display was frozen, so now that we are coming back we
9956 // do a gc so that any remote references the system
9957 // processes holds on others can be released if they are
9958 // no longer needed.
9959 mH.removeMessages(H.FORCE_GC);
9960 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9961 2000);
Romain Guy06882f82009-06-10 13:36:04 -07009962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 mScreenFrozenLock.release();
9964 }
Romain Guy06882f82009-06-10 13:36:04 -07009965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009966 @Override
9967 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
9968 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
9969 != PackageManager.PERMISSION_GRANTED) {
9970 pw.println("Permission Denial: can't dump WindowManager from from pid="
9971 + Binder.getCallingPid()
9972 + ", uid=" + Binder.getCallingUid());
9973 return;
9974 }
Romain Guy06882f82009-06-10 13:36:04 -07009975
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009976 pw.println("Input Dispatcher State:");
9977 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -08009978 pw.println(" ");
9979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009980 synchronized(mWindowMap) {
9981 pw.println("Current Window Manager state:");
9982 for (int i=mWindows.size()-1; i>=0; i--) {
9983 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009984 pw.print(" Window #"); pw.print(i); pw.print(' ');
9985 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 w.dump(pw, " ");
9987 }
9988 if (mInputMethodDialogs.size() > 0) {
9989 pw.println(" ");
9990 pw.println(" Input method dialogs:");
9991 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
9992 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009993 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009994 }
9995 }
9996 if (mPendingRemove.size() > 0) {
9997 pw.println(" ");
9998 pw.println(" Remove pending for:");
9999 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10000 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010001 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10002 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 w.dump(pw, " ");
10004 }
10005 }
10006 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10007 pw.println(" ");
10008 pw.println(" Windows force removing:");
10009 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10010 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010011 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10012 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010013 w.dump(pw, " ");
10014 }
10015 }
10016 if (mDestroySurface.size() > 0) {
10017 pw.println(" ");
10018 pw.println(" Windows waiting to destroy their surface:");
10019 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10020 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010021 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10022 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010023 w.dump(pw, " ");
10024 }
10025 }
10026 if (mLosingFocus.size() > 0) {
10027 pw.println(" ");
10028 pw.println(" Windows losing focus:");
10029 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10030 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010031 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10032 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 w.dump(pw, " ");
10034 }
10035 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010036 if (mResizingWindows.size() > 0) {
10037 pw.println(" ");
10038 pw.println(" Windows waiting to resize:");
10039 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10040 WindowState w = mResizingWindows.get(i);
10041 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10042 pw.print(w); pw.println(":");
10043 w.dump(pw, " ");
10044 }
10045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 if (mSessions.size() > 0) {
10047 pw.println(" ");
10048 pw.println(" All active sessions:");
10049 Iterator<Session> it = mSessions.iterator();
10050 while (it.hasNext()) {
10051 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010052 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010053 s.dump(pw, " ");
10054 }
10055 }
10056 if (mTokenMap.size() > 0) {
10057 pw.println(" ");
10058 pw.println(" All tokens:");
10059 Iterator<WindowToken> it = mTokenMap.values().iterator();
10060 while (it.hasNext()) {
10061 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010062 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 token.dump(pw, " ");
10064 }
10065 }
10066 if (mTokenList.size() > 0) {
10067 pw.println(" ");
10068 pw.println(" Window token list:");
10069 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010070 pw.print(" #"); pw.print(i); pw.print(": ");
10071 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010072 }
10073 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010074 if (mWallpaperTokens.size() > 0) {
10075 pw.println(" ");
10076 pw.println(" Wallpaper tokens:");
10077 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10078 WindowToken token = mWallpaperTokens.get(i);
10079 pw.print(" Wallpaper #"); pw.print(i);
10080 pw.print(' '); pw.print(token); pw.println(':');
10081 token.dump(pw, " ");
10082 }
10083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010084 if (mAppTokens.size() > 0) {
10085 pw.println(" ");
10086 pw.println(" Application tokens in Z order:");
10087 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010088 pw.print(" App #"); pw.print(i); pw.print(": ");
10089 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010090 }
10091 }
10092 if (mFinishedStarting.size() > 0) {
10093 pw.println(" ");
10094 pw.println(" Finishing start of application tokens:");
10095 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10096 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010097 pw.print(" Finished Starting #"); pw.print(i);
10098 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010099 token.dump(pw, " ");
10100 }
10101 }
10102 if (mExitingTokens.size() > 0) {
10103 pw.println(" ");
10104 pw.println(" Exiting tokens:");
10105 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10106 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010107 pw.print(" Exiting #"); pw.print(i);
10108 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010109 token.dump(pw, " ");
10110 }
10111 }
10112 if (mExitingAppTokens.size() > 0) {
10113 pw.println(" ");
10114 pw.println(" Exiting application tokens:");
10115 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10116 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010117 pw.print(" Exiting App #"); pw.print(i);
10118 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010119 token.dump(pw, " ");
10120 }
10121 }
10122 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010123 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10124 pw.print(" mLastFocus="); pw.println(mLastFocus);
10125 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10126 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10127 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010128 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010129 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10130 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10131 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10132 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010133 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10134 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10135 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010136 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10137 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10138 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10139 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010140 if (mDimAnimator != null) {
10141 mDimAnimator.printTo(pw);
10142 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010143 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010144 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010145 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010146 pw.print(mInputMethodAnimLayerAdjustment);
10147 pw.print(" mWallpaperAnimLayerAdjustment=");
10148 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010149 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10150 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010151 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10152 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010153 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10154 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010155 pw.print(" mRotation="); pw.print(mRotation);
10156 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10157 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10158 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10159 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10160 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10161 pw.print(" mNextAppTransition=0x");
10162 pw.print(Integer.toHexString(mNextAppTransition));
10163 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010164 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010165 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010166 if (mNextAppTransitionPackage != null) {
10167 pw.print(" mNextAppTransitionPackage=");
10168 pw.print(mNextAppTransitionPackage);
10169 pw.print(", mNextAppTransitionEnter=0x");
10170 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10171 pw.print(", mNextAppTransitionExit=0x");
10172 pw.print(Integer.toHexString(mNextAppTransitionExit));
10173 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010174 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10175 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010176 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10177 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10178 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10179 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010180 if (mOpeningApps.size() > 0) {
10181 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10182 }
10183 if (mClosingApps.size() > 0) {
10184 pw.print(" mClosingApps="); pw.println(mClosingApps);
10185 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010186 if (mToTopApps.size() > 0) {
10187 pw.print(" mToTopApps="); pw.println(mToTopApps);
10188 }
10189 if (mToBottomApps.size() > 0) {
10190 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10191 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010192 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10193 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010194 }
10195 }
10196
Jeff Brown349703e2010-06-22 01:27:15 -070010197 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010198 public void monitor() {
10199 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010200 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010201 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010202
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010203 /**
10204 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010205 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010206 */
10207 private static class DimAnimator {
10208 Surface mDimSurface;
10209 boolean mDimShown = false;
10210 float mDimCurrentAlpha;
10211 float mDimTargetAlpha;
10212 float mDimDeltaPerMs;
10213 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010214
10215 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010216
10217 DimAnimator (SurfaceSession session) {
10218 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010219 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010220 + mDimSurface + ": CREATE");
10221 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010222 mDimSurface = new Surface(session, 0,
10223 "DimSurface",
10224 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010225 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010226 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010227 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010228 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010229 }
10230 }
10231 }
10232
10233 /**
10234 * Show the dim surface.
10235 */
10236 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010237 if (!mDimShown) {
10238 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10239 dw + "x" + dh + ")");
10240 mDimShown = true;
10241 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010242 mLastDimWidth = dw;
10243 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010244 mDimSurface.setPosition(0, 0);
10245 mDimSurface.setSize(dw, dh);
10246 mDimSurface.show();
10247 } catch (RuntimeException e) {
10248 Slog.w(TAG, "Failure showing dim surface", e);
10249 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010250 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10251 mLastDimWidth = dw;
10252 mLastDimHeight = dh;
10253 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010254 }
10255 }
10256
10257 /**
10258 * Set's the dim surface's layer and update dim parameters that will be used in
10259 * {@link updateSurface} after all windows are examined.
10260 */
10261 void updateParameters(WindowState w, long currentTime) {
10262 mDimSurface.setLayer(w.mAnimLayer-1);
10263
10264 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010265 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010266 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010267 if (mDimTargetAlpha != target) {
10268 // If the desired dim level has changed, then
10269 // start an animation to it.
10270 mLastDimAnimTime = currentTime;
10271 long duration = (w.mAnimating && w.mAnimation != null)
10272 ? w.mAnimation.computeDurationHint()
10273 : DEFAULT_DIM_DURATION;
10274 if (target > mDimTargetAlpha) {
10275 // This is happening behind the activity UI,
10276 // so we can make it run a little longer to
10277 // give a stronger impression without disrupting
10278 // the user.
10279 duration *= DIM_DURATION_MULTIPLIER;
10280 }
10281 if (duration < 1) {
10282 // Don't divide by zero
10283 duration = 1;
10284 }
10285 mDimTargetAlpha = target;
10286 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10287 }
10288 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010289
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010290 /**
10291 * Updating the surface's alpha. Returns true if the animation continues, or returns
10292 * false when the animation is finished and the dim surface is hidden.
10293 */
10294 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10295 if (!dimming) {
10296 if (mDimTargetAlpha != 0) {
10297 mLastDimAnimTime = currentTime;
10298 mDimTargetAlpha = 0;
10299 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10300 }
10301 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010302
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010303 boolean animating = false;
10304 if (mLastDimAnimTime != 0) {
10305 mDimCurrentAlpha += mDimDeltaPerMs
10306 * (currentTime-mLastDimAnimTime);
10307 boolean more = true;
10308 if (displayFrozen) {
10309 // If the display is frozen, there is no reason to animate.
10310 more = false;
10311 } else if (mDimDeltaPerMs > 0) {
10312 if (mDimCurrentAlpha > mDimTargetAlpha) {
10313 more = false;
10314 }
10315 } else if (mDimDeltaPerMs < 0) {
10316 if (mDimCurrentAlpha < mDimTargetAlpha) {
10317 more = false;
10318 }
10319 } else {
10320 more = false;
10321 }
10322
10323 // Do we need to continue animating?
10324 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010325 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010326 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10327 mLastDimAnimTime = currentTime;
10328 mDimSurface.setAlpha(mDimCurrentAlpha);
10329 animating = true;
10330 } else {
10331 mDimCurrentAlpha = mDimTargetAlpha;
10332 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010333 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010334 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10335 mDimSurface.setAlpha(mDimCurrentAlpha);
10336 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010337 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010338 + ": HIDE");
10339 try {
10340 mDimSurface.hide();
10341 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010342 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010343 }
10344 mDimShown = false;
10345 }
10346 }
10347 }
10348 return animating;
10349 }
10350
10351 public void printTo(PrintWriter pw) {
10352 pw.print(" mDimShown="); pw.print(mDimShown);
10353 pw.print(" current="); pw.print(mDimCurrentAlpha);
10354 pw.print(" target="); pw.print(mDimTargetAlpha);
10355 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10356 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10357 }
10358 }
10359
10360 /**
10361 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10362 * This is used for opening/closing transition for apps in compatible mode.
10363 */
10364 private static class FadeInOutAnimation extends Animation {
10365 int mWidth;
10366 boolean mFadeIn;
10367
10368 public FadeInOutAnimation(boolean fadeIn) {
10369 setInterpolator(new AccelerateInterpolator());
10370 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10371 mFadeIn = fadeIn;
10372 }
10373
10374 @Override
10375 protected void applyTransformation(float interpolatedTime, Transformation t) {
10376 float x = interpolatedTime;
10377 if (!mFadeIn) {
10378 x = 1.0f - x; // reverse the interpolation for fade out
10379 }
10380 if (x < 0.5) {
10381 // move the window out of the screen.
10382 t.getMatrix().setTranslate(mWidth, 0);
10383 } else {
10384 t.getMatrix().setTranslate(0, 0);// show
10385 t.setAlpha((x - 0.5f) * 2);
10386 }
10387 }
10388
10389 @Override
10390 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10391 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10392 mWidth = width;
10393 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010394
10395 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010396 public int getZAdjustment() {
10397 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010398 }
10399 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010400}