blob: d666523ce5d2a7d23114c9f4f94bc9235383e760 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.am.BatteryStatsService;
52
53import android.Manifest;
54import android.app.ActivityManagerNative;
55import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070056import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070057import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070059import android.content.Intent;
60import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.pm.ActivityInfo;
62import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.content.res.Configuration;
65import android.graphics.Matrix;
66import android.graphics.PixelFormat;
67import android.graphics.Rect;
68import android.graphics.Region;
69import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070075import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.LocalPowerManager;
77import android.os.Looper;
78import android.os.Message;
79import android.os.Parcel;
80import android.os.ParcelFileDescriptor;
81import android.os.Power;
82import android.os.PowerManager;
83import android.os.Process;
84import android.os.RemoteException;
85import android.os.ServiceManager;
86import android.os.SystemClock;
87import android.os.SystemProperties;
88import android.os.TokenWatcher;
89import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070090import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070092import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080093import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.SparseIntArray;
95import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -0700106import android.view.InputEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700107import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.KeyEvent;
109import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110import android.view.Surface;
111import android.view.SurfaceSession;
112import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700113import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.ViewTreeObserver;
115import android.view.WindowManager;
116import android.view.WindowManagerImpl;
117import android.view.WindowManagerPolicy;
118import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700119import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120import android.view.animation.Animation;
121import android.view.animation.AnimationUtils;
122import android.view.animation.Transformation;
123
124import java.io.BufferedWriter;
125import java.io.File;
126import java.io.FileDescriptor;
127import java.io.IOException;
128import java.io.OutputStream;
129import java.io.OutputStreamWriter;
130import java.io.PrintWriter;
131import java.io.StringWriter;
132import java.net.Socket;
133import java.util.ArrayList;
134import java.util.HashMap;
135import java.util.HashSet;
136import java.util.Iterator;
137import java.util.List;
138
139/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700140public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700141 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 static final String TAG = "WindowManager";
143 static final boolean DEBUG = false;
144 static final boolean DEBUG_FOCUS = false;
145 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800146 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800147 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 static final boolean DEBUG_LAYERS = false;
149 static final boolean DEBUG_INPUT = false;
150 static final boolean DEBUG_INPUT_METHOD = false;
151 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700152 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700154 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_APP_TRANSITIONS = false;
156 static final boolean DEBUG_STARTING_WINDOW = false;
157 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700158 static final boolean DEBUG_WALLPAPER = false;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700159 static final boolean DEBUG_FREEZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700161 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700162 static final boolean MEASURE_LATENCY = false;
163 static private LatencyTimer lt;
164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean PROFILE_ORIENTATION = false;
166 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700167 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** How much to multiply the policy's type layer, to reserve room
170 * for multiple windows of the same type and Z-ordering adjustment
171 * with TYPE_LAYER_OFFSET. */
172 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
175 * or below others in the same layer. */
176 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to increment the layer for each window, to reserve room
179 * for effect surfaces between them.
180 */
181 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** The maximum length we will accept for a loaded animation duration:
184 * this is 10 seconds.
185 */
186 static final int MAX_ANIMATION_DURATION = 10*1000;
187
188 /** Amount of time (in milliseconds) to animate the dim surface from one
189 * value to another, when no window animation is driving it.
190 */
191 static final int DEFAULT_DIM_DURATION = 200;
192
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700193 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
194 * compatible windows.
195 */
196 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 /** Adjustment to time to perform a dim, to make it more dramatic.
199 */
200 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700201
202 // Maximum number of milliseconds to wait for input event injection.
203 // FIXME is this value reasonable?
204 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700205
206 // Default input dispatching timeout in nanoseconds.
207 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 static final int UPDATE_FOCUS_NORMAL = 0;
210 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
211 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
212 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700215 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216
217 /**
218 * Condition waited on by {@link #reenableKeyguard} to know the call to
219 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500220 * This is set to true only if mKeyguardTokenWatcher.acquired() has
221 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500223 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224
Jim Miller284b62e2010-06-08 14:27:42 -0700225 private static final int ALLOW_DISABLE_YES = 1;
226 private static final int ALLOW_DISABLE_NO = 0;
227 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
228 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
229
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
231 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700233 if (shouldAllowDisableKeyguard()) {
234 mPolicy.enableKeyguard(false);
235 mKeyguardDisabled = true;
236 } else {
237 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 }
240 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700241 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500242 synchronized (mKeyguardTokenWatcher) {
243 mKeyguardDisabled = false;
244 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 }
246 }
247 };
248
Jim Miller284b62e2010-06-08 14:27:42 -0700249 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
250 @Override
251 public void onReceive(Context context, Intent intent) {
252 mPolicy.enableKeyguard(true);
253 synchronized(mKeyguardTokenWatcher) {
254 // lazily evaluate this next time we're asked to disable keyguard
255 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
256 mKeyguardDisabled = false;
257 }
258 }
259 };
260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 final Context mContext;
262
263 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
268
269 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 /**
274 * All currently active sessions with clients.
275 */
276 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * Mapping from an IWindow IBinder to the server's Window object.
280 * This is also used as the lock for all of our state.
281 */
282 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
283
284 /**
285 * Mapping from a token IBinder to a WindowToken object.
286 */
287 final HashMap<IBinder, WindowToken> mTokenMap =
288 new HashMap<IBinder, WindowToken>();
289
290 /**
291 * The same tokens as mTokenMap, stored in a list for efficient iteration
292 * over them.
293 */
294 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 /**
297 * Window tokens that are in the process of exiting, but still
298 * on screen for animations.
299 */
300 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
301
302 /**
303 * Z-ordered (bottom-most first) list of all application tokens, for
304 * controlling the ordering of windows in different applications. This
305 * contains WindowToken objects.
306 */
307 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
308
309 /**
310 * Application tokens that are in the process of exiting, but still
311 * on screen for animations.
312 */
313 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
314
315 /**
316 * List of window tokens that have finished starting their application,
317 * and now need to have the policy remove their windows.
318 */
319 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
320
321 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700322 * This was the app token that was used to retrieve the last enter
323 * animation. It will be used for the next exit animation.
324 */
325 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800326
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700327 /**
328 * These were the layout params used to retrieve the last enter animation.
329 * They will be used for the next exit animation.
330 */
331 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800332
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700333 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 * Z-ordered (bottom-most first) list of all Window objects.
335 */
Jeff Browne33348b2010-07-15 23:54:05 -0700336 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337
338 /**
339 * Windows that are being resized. Used so we can tell the client about
340 * the resize after closing the transaction in which we resized the
341 * underlying surface.
342 */
343 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
344
345 /**
346 * Windows whose animations have ended and now must be removed.
347 */
348 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
349
350 /**
351 * Windows whose surface should be destroyed.
352 */
353 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
354
355 /**
356 * Windows that have lost input focus and are waiting for the new
357 * focus window to be displayed before they are told about this.
358 */
359 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
360
361 /**
362 * This is set when we have run out of memory, and will either be an empty
363 * list or contain windows that need to be force removed.
364 */
365 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700370 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 Surface mBlurSurface;
372 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 final float[] mTmpFloats = new float[9];
377
378 boolean mSafeMode;
379 boolean mDisplayEnabled = false;
380 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700381 int mInitialDisplayWidth = 0;
382 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 int mRotation = 0;
384 int mRequestedRotation = 0;
385 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700386 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 ArrayList<IRotationWatcher> mRotationWatchers
388 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 boolean mLayoutNeeded = true;
391 boolean mAnimationPending = false;
392 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800393 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 boolean mWindowsFreezingScreen = false;
395 long mFreezeGcPending = 0;
396 int mAppsFreezingScreen = 0;
397
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800398 int mLayoutSeq = 0;
399
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800400 // State while inside of layoutAndPlaceSurfacesLocked().
401 boolean mFocusMayChange;
402
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800403 Configuration mCurConfiguration = new Configuration();
404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 // This is held as long as we have the screen frozen, to give us time to
406 // perform a rotation animation when turning off shows the lock screen which
407 // changes the orientation.
408 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 // State management of app transitions. When we are preparing for a
411 // transition, mNextAppTransition will be the kind of transition to
412 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
413 // mOpeningApps and mClosingApps are the lists of tokens that will be
414 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700415 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700416 String mNextAppTransitionPackage;
417 int mNextAppTransitionEnter;
418 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700420 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 boolean mAppTransitionTimeout = false;
422 boolean mStartingIconInTransition = false;
423 boolean mSkipAppTransitionAnimation = false;
424 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
425 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700426 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
427 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 H mH = new H();
432
433 WindowState mCurrentFocus = null;
434 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 // This just indicates the window the input method is on top of, not
437 // necessarily the window its input is going to.
438 WindowState mInputMethodTarget = null;
439 WindowState mUpcomingInputMethodTarget = null;
440 boolean mInputMethodTargetWaitingAnim;
441 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 WindowState mInputMethodWindow = null;
444 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
445
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700446 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800447
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700448 // If non-null, this is the currently visible window that is associated
449 // with the wallpaper.
450 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700451 // If non-null, we are in the middle of animating from one wallpaper target
452 // to another, and this is the lower one in Z-order.
453 WindowState mLowerWallpaperTarget = null;
454 // If non-null, we are in the middle of animating from one wallpaper target
455 // to another, and this is the higher one in Z-order.
456 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700457 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700458 float mLastWallpaperX = -1;
459 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800460 float mLastWallpaperXStep = -1;
461 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700462 // This is set when we are waiting for a wallpaper to tell us it is done
463 // changing its scroll position.
464 WindowState mWaitingOnWallpaper;
465 // The last time we had a timeout when waiting for a wallpaper.
466 long mLastWallpaperTimeoutTime;
467 // We give a wallpaper up to 150ms to finish scrolling.
468 static final long WALLPAPER_TIMEOUT = 150;
469 // Time we wait after a timeout before trying to wait again.
470 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 AppWindowToken mFocusedApp = null;
473
474 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 float mWindowAnimationScale = 1.0f;
477 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700478
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700479 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480
481 // Who is holding the screen on.
482 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700483 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700484
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700485 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 /**
488 * Whether the UI is currently running in touch mode (not showing
489 * navigational focus because the user is directly pressing the screen).
490 */
491 boolean mInTouchMode = false;
492
493 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700494 private ArrayList<WindowChangeListener> mWindowChangeListeners =
495 new ArrayList<WindowChangeListener>();
496 private boolean mWindowsChanged = false;
497
498 public interface WindowChangeListener {
499 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700500 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502
Dianne Hackbornc485a602009-03-24 22:39:49 -0700503 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700504 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700505
506 // The frame use to limit the size of the app running in compatibility mode.
507 Rect mCompatibleScreenFrame = new Rect();
508 // The surface used to fill the outer rim of the app running in compatibility mode.
509 Surface mBackgroundFillerSurface = null;
510 boolean mBackgroundFillerShown = false;
511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 public static WindowManagerService main(Context context,
513 PowerManagerService pm, boolean haveInputMethods) {
514 WMThread thr = new WMThread(context, pm, haveInputMethods);
515 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 synchronized (thr) {
518 while (thr.mService == null) {
519 try {
520 thr.wait();
521 } catch (InterruptedException e) {
522 }
523 }
524 }
Romain Guy06882f82009-06-10 13:36:04 -0700525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 return thr.mService;
527 }
Romain Guy06882f82009-06-10 13:36:04 -0700528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 static class WMThread extends Thread {
530 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 private final Context mContext;
533 private final PowerManagerService mPM;
534 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 public WMThread(Context context, PowerManagerService pm,
537 boolean haveInputMethods) {
538 super("WindowManager");
539 mContext = context;
540 mPM = pm;
541 mHaveInputMethods = haveInputMethods;
542 }
Romain Guy06882f82009-06-10 13:36:04 -0700543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 public void run() {
545 Looper.prepare();
546 WindowManagerService s = new WindowManagerService(mContext, mPM,
547 mHaveInputMethods);
548 android.os.Process.setThreadPriority(
549 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700550 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 synchronized (this) {
553 mService = s;
554 notifyAll();
555 }
Romain Guy06882f82009-06-10 13:36:04 -0700556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 Looper.loop();
558 }
559 }
560
561 static class PolicyThread extends Thread {
562 private final WindowManagerPolicy mPolicy;
563 private final WindowManagerService mService;
564 private final Context mContext;
565 private final PowerManagerService mPM;
566 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 public PolicyThread(WindowManagerPolicy policy,
569 WindowManagerService service, Context context,
570 PowerManagerService pm) {
571 super("WindowManagerPolicy");
572 mPolicy = policy;
573 mService = service;
574 mContext = context;
575 mPM = pm;
576 }
Romain Guy06882f82009-06-10 13:36:04 -0700577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 public void run() {
579 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800580 WindowManagerPolicyThread.set(this, Looper.myLooper());
581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800583 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 android.os.Process.setThreadPriority(
585 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700586 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 synchronized (this) {
590 mRunning = true;
591 notifyAll();
592 }
Romain Guy06882f82009-06-10 13:36:04 -0700593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 Looper.loop();
595 }
596 }
597
598 private WindowManagerService(Context context, PowerManagerService pm,
599 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700600 if (MEASURE_LATENCY) {
601 lt = new LatencyTimer(100, 1000);
602 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 mContext = context;
605 mHaveInputMethods = haveInputMethods;
606 mLimitedAlphaCompositing = context.getResources().getBoolean(
607 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 mPowerManager = pm;
610 mPowerManager.setPolicy(mPolicy);
611 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
612 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
613 "SCREEN_FROZEN");
614 mScreenFrozenLock.setReferenceCounted(false);
615
616 mActivityManager = ActivityManagerNative.getDefault();
617 mBatteryStats = BatteryStatsService.getService();
618
619 // Get persisted window scale setting
620 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
621 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
622 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
623 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700624
Jim Miller284b62e2010-06-08 14:27:42 -0700625 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
626 IntentFilter filter = new IntentFilter();
627 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
628 mContext.registerReceiver(mBroadcastReceiver, filter);
629
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700630 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
631 "KEEP_SCREEN_ON_FLAG");
632 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633
Jeff Browne33348b2010-07-15 23:54:05 -0700634 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
637 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 synchronized (thr) {
640 while (!thr.mRunning) {
641 try {
642 thr.wait();
643 } catch (InterruptedException e) {
644 }
645 }
646 }
Romain Guy06882f82009-06-10 13:36:04 -0700647
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700648 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 // Add ourself to the Watchdog monitors.
651 Watchdog.getInstance().addMonitor(this);
652 }
653
654 @Override
655 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
656 throws RemoteException {
657 try {
658 return super.onTransact(code, data, reply, flags);
659 } catch (RuntimeException e) {
660 // The window manager only throws security exceptions, so let's
661 // log all others.
662 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800663 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 }
665 throw e;
666 }
667 }
668
Jeff Browne33348b2010-07-15 23:54:05 -0700669 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800671 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 TAG, "Adding window " + window + " at "
673 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
674 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700675 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 }
677
Jeff Browne33348b2010-07-15 23:54:05 -0700678 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800680 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 TAG, "Adding window " + window + " at "
682 + i + " of " + mWindows.size() + " (before " + pos + ")");
683 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700684 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 }
686
687 //This method finds out the index of a window that has the same app token as
688 //win. used for z ordering the windows in mWindows
689 private int findIdxBasedOnAppTokens(WindowState win) {
690 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700691 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 int jmax = localmWindows.size();
693 if(jmax == 0) {
694 return -1;
695 }
696 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700697 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 if(wentry.mAppToken == win.mAppToken) {
699 return j;
700 }
701 }
702 return -1;
703 }
Romain Guy06882f82009-06-10 13:36:04 -0700704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
706 final IWindow client = win.mClient;
707 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700708 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 final int N = localmWindows.size();
711 final WindowState attached = win.mAttachedWindow;
712 int i;
713 if (attached == null) {
714 int tokenWindowsPos = token.windows.size();
715 if (token.appWindowToken != null) {
716 int index = tokenWindowsPos-1;
717 if (index >= 0) {
718 // If this application has existing windows, we
719 // simply place the new window on top of them... but
720 // keep the starting window on top.
721 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
722 // Base windows go behind everything else.
723 placeWindowBefore(token.windows.get(0), win);
724 tokenWindowsPos = 0;
725 } else {
726 AppWindowToken atoken = win.mAppToken;
727 if (atoken != null &&
728 token.windows.get(index) == atoken.startingWindow) {
729 placeWindowBefore(token.windows.get(index), win);
730 tokenWindowsPos--;
731 } else {
732 int newIdx = findIdxBasedOnAppTokens(win);
733 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700734 //there is a window above this one associated with the same
735 //apptoken note that the window could be a floating window
736 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800738 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700739 TAG, "Adding window " + win + " at "
740 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700742 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 }
745 }
746 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800747 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 TAG, "Figuring out where to add app window "
749 + client.asBinder() + " (token=" + token + ")");
750 // Figure out where the window should go, based on the
751 // order of applications.
752 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700753 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 for (i=NA-1; i>=0; i--) {
755 AppWindowToken t = mAppTokens.get(i);
756 if (t == token) {
757 i--;
758 break;
759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800760
Dianne Hackborna8f60182009-09-01 19:01:50 -0700761 // We haven't reached the token yet; if this token
762 // is not going to the bottom and has windows, we can
763 // use it as an anchor for when we do reach the token.
764 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 pos = t.windows.get(0);
766 }
767 }
768 // We now know the index into the apps. If we found
769 // an app window above, that gives us the position; else
770 // we need to look some more.
771 if (pos != null) {
772 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700773 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 if (atoken != null) {
775 final int NC = atoken.windows.size();
776 if (NC > 0) {
777 WindowState bottom = atoken.windows.get(0);
778 if (bottom.mSubLayer < 0) {
779 pos = bottom;
780 }
781 }
782 }
783 placeWindowBefore(pos, win);
784 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700785 // Continue looking down until we find the first
786 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 while (i >= 0) {
788 AppWindowToken t = mAppTokens.get(i);
789 final int NW = t.windows.size();
790 if (NW > 0) {
791 pos = t.windows.get(NW-1);
792 break;
793 }
794 i--;
795 }
796 if (pos != null) {
797 // Move in front of any windows attached to this
798 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700799 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 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++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700814 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 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--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700831 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 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) {
Jeff Browne33348b2010-07-15 23:54:05 -0700914 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 final int N = localmWindows.size();
916 WindowState w = null;
917 int i = N;
918 while (i > 0) {
919 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700920 w = 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) {
Jeff Browne33348b2010-07-15 23:54:05 -0700935 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 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) {
Jeff Browne33348b2010-07-15 23:54:05 -0700965 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 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--;
Jeff Browne33348b2010-07-15 23:54:05 -07001070 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 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--;
Jeff Browne33348b2010-07-15 23:54:05 -07001096 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 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()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001148 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 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
Jeff Browne33348b2010-07-15 23:54:05 -07001192 ? 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) {
Jeff Browne33348b2010-07-15 23:54:05 -07001199 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 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) {
Jeff Browne33348b2010-07-15 23:54:05 -07001208 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 break;
1210 }
1211 pos++;
1212 }
1213 pos++;
1214 // Now there should be no more input method windows above.
1215 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001216 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 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.
Jeff Browne33348b2010-07-15 23:54:05 -07001304 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001305 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--;
Jeff Browne33348b2010-07-15 23:54:05 -07001314 w = 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) {
Jeff Browne33348b2010-07-15 23:54:05 -07001485 WindowState wb = 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.
Jeff Browne33348b2010-07-15 23:54:05 -07001509 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001510 }
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
Jeff Browne33348b2010-07-15 23:54:05 -07001568 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 continue;
1570 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001571
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001572 // The window didn't match... the current wallpaper window,
1573 // wherever it is, is in the wrong place, so make sure it is
1574 // not in the list.
1575 int oldIndex = localmWindows.indexOf(wallpaper);
1576 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001577 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001578 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001579 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001580 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001581 if (oldIndex < foundI) {
1582 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001583 }
1584 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001585
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001586 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001587 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001588 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001589 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001590
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001591 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001592 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001593 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001594 }
1595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001596
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001597 return changed;
1598 }
1599
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001600 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001601 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001602 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001603 mWallpaperAnimLayerAdjustment = adj;
1604 int curTokenIndex = mWallpaperTokens.size();
1605 while (curTokenIndex > 0) {
1606 curTokenIndex--;
1607 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1608 int curWallpaperIndex = token.windows.size();
1609 while (curWallpaperIndex > 0) {
1610 curWallpaperIndex--;
1611 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1612 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001613 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001614 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001615 }
1616 }
1617 }
1618
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001619 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1620 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001621 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001622 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001624 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001625 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1626 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1627 changed = wallpaperWin.mXOffset != offset;
1628 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001629 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001630 + wallpaperWin + " x: " + offset);
1631 wallpaperWin.mXOffset = offset;
1632 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001635 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001636 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001637 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001638
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001639 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001640 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001641 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1642 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1643 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001644 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001645 + wallpaperWin + " y: " + offset);
1646 changed = true;
1647 wallpaperWin.mYOffset = offset;
1648 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001649 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001651 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001652 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001654
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001655 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001656 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001657 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001658 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1659 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001661 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001662 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001663 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001664 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1665 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001666 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001667 if (mWaitingOnWallpaper != null) {
1668 long start = SystemClock.uptimeMillis();
1669 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1670 < start) {
1671 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001672 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001673 "Waiting for offset complete...");
1674 mWindowMap.wait(WALLPAPER_TIMEOUT);
1675 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001676 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 if ((start+WALLPAPER_TIMEOUT)
1679 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001680 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001681 + wallpaperWin);
1682 mLastWallpaperTimeoutTime = start;
1683 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001684 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001685 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001686 }
1687 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001688 } catch (RemoteException e) {
1689 }
1690 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001691
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001692 return changed;
1693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001694
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001695 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001696 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001697 if (mWaitingOnWallpaper != null &&
1698 mWaitingOnWallpaper.mClient.asBinder() == window) {
1699 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001700 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001701 }
1702 }
1703 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001704
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001705 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001706 final int dw = mDisplay.getWidth();
1707 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001709 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001710
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001711 WindowState target = mWallpaperTarget;
1712 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001713 if (target.mWallpaperX >= 0) {
1714 mLastWallpaperX = target.mWallpaperX;
1715 } else if (changingTarget.mWallpaperX >= 0) {
1716 mLastWallpaperX = changingTarget.mWallpaperX;
1717 }
1718 if (target.mWallpaperY >= 0) {
1719 mLastWallpaperY = target.mWallpaperY;
1720 } else if (changingTarget.mWallpaperY >= 0) {
1721 mLastWallpaperY = changingTarget.mWallpaperY;
1722 }
1723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001724
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001725 int curTokenIndex = mWallpaperTokens.size();
1726 while (curTokenIndex > 0) {
1727 curTokenIndex--;
1728 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1729 int curWallpaperIndex = token.windows.size();
1730 while (curWallpaperIndex > 0) {
1731 curWallpaperIndex--;
1732 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1733 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1734 wallpaper.computeShownFrameLocked();
1735 changed = true;
1736 // We only want to be synchronous with one wallpaper.
1737 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001738 }
1739 }
1740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001742 return changed;
1743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001744
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001745 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001746 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001747 final int dw = mDisplay.getWidth();
1748 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001749
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001750 int curTokenIndex = mWallpaperTokens.size();
1751 while (curTokenIndex > 0) {
1752 curTokenIndex--;
1753 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001754 if (token.hidden == visible) {
1755 token.hidden = !visible;
1756 // Need to do a layout to ensure the wallpaper now has the
1757 // correct size.
1758 mLayoutNeeded = true;
1759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001760
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001761 int curWallpaperIndex = token.windows.size();
1762 while (curWallpaperIndex > 0) {
1763 curWallpaperIndex--;
1764 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1765 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001766 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001768
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001769 if (wallpaper.mWallpaperVisible != visible) {
1770 wallpaper.mWallpaperVisible = visible;
1771 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001772 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001773 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001774 + ": " + visible);
1775 wallpaper.mClient.dispatchAppVisibility(visible);
1776 } catch (RemoteException e) {
1777 }
1778 }
1779 }
1780 }
1781 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 public int addWindow(Session session, IWindow client,
1784 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001785 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 int res = mPolicy.checkAddPermission(attrs);
1787 if (res != WindowManagerImpl.ADD_OKAY) {
1788 return res;
1789 }
Romain Guy06882f82009-06-10 13:36:04 -07001790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 boolean reportNewConfig = false;
1792 WindowState attachedWindow = null;
1793 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 synchronized(mWindowMap) {
1796 // Instantiating a Display requires talking with the simulator,
1797 // so don't do it until we know the system is mostly up and
1798 // running.
1799 if (mDisplay == null) {
1800 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1801 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001802 mInitialDisplayWidth = mDisplay.getWidth();
1803 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001804 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 reportNewConfig = true;
1806 }
Romain Guy06882f82009-06-10 13:36:04 -07001807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1811 }
1812
1813 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001814 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001816 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 + attrs.token + ". Aborting.");
1818 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1819 }
1820 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1821 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001822 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 + attrs.token + ". Aborting.");
1824 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1825 }
1826 }
1827
1828 boolean addToken = false;
1829 WindowToken token = mTokenMap.get(attrs.token);
1830 if (token == null) {
1831 if (attrs.type >= FIRST_APPLICATION_WINDOW
1832 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 + attrs.token + ". Aborting.");
1835 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1836 }
1837 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001838 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 + attrs.token + ". Aborting.");
1840 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1841 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001842 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001843 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001844 + attrs.token + ". Aborting.");
1845 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 token = new WindowToken(attrs.token, -1, false);
1848 addToken = true;
1849 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1850 && attrs.type <= LAST_APPLICATION_WINDOW) {
1851 AppWindowToken atoken = token.appWindowToken;
1852 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001853 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 + token + ". Aborting.");
1855 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1856 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001857 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 + token + ". Aborting.");
1859 return WindowManagerImpl.ADD_APP_EXITING;
1860 }
1861 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1862 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1865 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1866 }
1867 } else if (attrs.type == TYPE_INPUT_METHOD) {
1868 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 + attrs.token + ". Aborting.");
1871 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1872 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001873 } else if (attrs.type == TYPE_WALLPAPER) {
1874 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001875 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001876 + attrs.token + ". Aborting.");
1877 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 }
1880
1881 win = new WindowState(session, client, token,
1882 attachedWindow, attrs, viewVisibility);
1883 if (win.mDeathRecipient == null) {
1884 // Client has apparently died, so there is no reason to
1885 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001886 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 + " that is dead, aborting.");
1888 return WindowManagerImpl.ADD_APP_EXITING;
1889 }
1890
1891 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 res = mPolicy.prepareAddWindowLw(win, attrs);
1894 if (res != WindowManagerImpl.ADD_OKAY) {
1895 return res;
1896 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001897
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001898 if (outInputChannel != null) {
1899 String name = win.makeInputChannelName();
1900 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1901 win.mInputChannel = inputChannels[0];
1902 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1903
1904 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001906
1907 // From now on, no exceptions or errors allowed!
1908
1909 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 if (addToken) {
1914 mTokenMap.put(attrs.token, token);
1915 mTokenList.add(token);
1916 }
1917 win.attach();
1918 mWindowMap.put(client.asBinder(), win);
1919
1920 if (attrs.type == TYPE_APPLICATION_STARTING &&
1921 token.appWindowToken != null) {
1922 token.appWindowToken.startingWindow = win;
1923 }
1924
1925 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 if (attrs.type == TYPE_INPUT_METHOD) {
1928 mInputMethodWindow = win;
1929 addInputMethodWindowToListLocked(win);
1930 imMayMove = false;
1931 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1932 mInputMethodDialogs.add(win);
1933 addWindowToListInOrderLocked(win, true);
1934 adjustInputMethodDialogsLocked();
1935 imMayMove = false;
1936 } else {
1937 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001938 if (attrs.type == TYPE_WALLPAPER) {
1939 mLastWallpaperTimeoutTime = 0;
1940 adjustWallpaperWindowsLocked();
1941 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001942 adjustWallpaperWindowsLocked();
1943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 }
Romain Guy06882f82009-06-10 13:36:04 -07001945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 if (mInTouchMode) {
1951 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1952 }
1953 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1954 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1955 }
Romain Guy06882f82009-06-10 13:36:04 -07001956
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001957 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001959 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1960 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 imMayMove = false;
1962 }
1963 }
Romain Guy06882f82009-06-10 13:36:04 -07001964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001966 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 }
Romain Guy06882f82009-06-10 13:36:04 -07001968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 assignLayersLocked();
1970 // Don't do layout here, the window must call
1971 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 //dump();
1974
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001975 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001976 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001977 }
Jeff Brown349703e2010-06-22 01:27:15 -07001978
Joe Onorato8a9b2202010-02-26 18:56:32 -08001979 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 TAG, "New client " + client.asBinder()
1981 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001982
1983 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1984 reportNewConfig = true;
1985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 }
1987
1988 // sendNewConfiguration() checks caller permissions so we must call it with
1989 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1990 // identity anyway, so it's safe to just clear & restore around this whole
1991 // block.
1992 final long origId = Binder.clearCallingIdentity();
1993 if (reportNewConfig) {
1994 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 }
1996 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 return res;
1999 }
Romain Guy06882f82009-06-10 13:36:04 -07002000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 public void removeWindow(Session session, IWindow client) {
2002 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002003 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 if (win == null) {
2005 return;
2006 }
2007 removeWindowLocked(session, win);
2008 }
2009 }
Romain Guy06882f82009-06-10 13:36:04 -07002010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 public void removeWindowLocked(Session session, WindowState win) {
2012
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 TAG, "Remove " + win + " client="
2015 + Integer.toHexString(System.identityHashCode(
2016 win.mClient.asBinder()))
2017 + ", surface=" + win.mSurface);
2018
2019 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002020
2021 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002022
Joe Onorato8a9b2202010-02-26 18:56:32 -08002023 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2025 + " mExiting=" + win.mExiting
2026 + " isAnimating=" + win.isAnimating()
2027 + " app-animation="
2028 + (win.mAppToken != null ? win.mAppToken.animation : null)
2029 + " inPendingTransaction="
2030 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2031 + " mDisplayFrozen=" + mDisplayFrozen);
2032 // Visibility of the removed window. Will be used later to update orientation later on.
2033 boolean wasVisible = false;
2034 // First, see if we need to run an animation. If we do, we have
2035 // to hold off on removing the window until the animation is done.
2036 // If the display is frozen, just remove immediately, since the
2037 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002038 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 // If we are not currently running the exit animation, we
2040 // need to see about starting one.
2041 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2044 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2045 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2046 }
2047 // Try starting an animation.
2048 if (applyAnimationLocked(win, transit, false)) {
2049 win.mExiting = true;
2050 }
2051 }
2052 if (win.mExiting || win.isAnimating()) {
2053 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002054 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002055 win.mExiting = true;
2056 win.mRemoveOnExit = true;
2057 mLayoutNeeded = true;
2058 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2059 performLayoutAndPlaceSurfacesLocked();
2060 if (win.mAppToken != null) {
2061 win.mAppToken.updateReportedVisibilityLocked();
2062 }
2063 //dump();
2064 Binder.restoreCallingIdentity(origId);
2065 return;
2066 }
2067 }
2068
2069 removeWindowInnerLocked(session, win);
2070 // Removing a visible window will effect the computed orientation
2071 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002072 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002073 != mForcedAppOrientation
2074 && updateOrientationFromAppTokensLocked()) {
2075 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 }
2077 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2078 Binder.restoreCallingIdentity(origId);
2079 }
Romain Guy06882f82009-06-10 13:36:04 -07002080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 if (mInputMethodTarget == win) {
2085 moveInputMethodWindowsIfNeededLocked(false);
2086 }
Romain Guy06882f82009-06-10 13:36:04 -07002087
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002088 if (false) {
2089 RuntimeException e = new RuntimeException("here");
2090 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002091 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 mPolicy.removeWindowLw(win);
2095 win.removeLocked();
2096
2097 mWindowMap.remove(win.mClient.asBinder());
2098 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002099 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002100 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101
2102 if (mInputMethodWindow == win) {
2103 mInputMethodWindow = null;
2104 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2105 mInputMethodDialogs.remove(win);
2106 }
Romain Guy06882f82009-06-10 13:36:04 -07002107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002108 final WindowToken token = win.mToken;
2109 final AppWindowToken atoken = win.mAppToken;
2110 token.windows.remove(win);
2111 if (atoken != null) {
2112 atoken.allAppWindows.remove(win);
2113 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002114 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 TAG, "**** Removing window " + win + ": count="
2116 + token.windows.size());
2117 if (token.windows.size() == 0) {
2118 if (!token.explicit) {
2119 mTokenMap.remove(token.token);
2120 mTokenList.remove(token);
2121 } else if (atoken != null) {
2122 atoken.firstWindowDrawn = false;
2123 }
2124 }
2125
2126 if (atoken != null) {
2127 if (atoken.startingWindow == win) {
2128 atoken.startingWindow = null;
2129 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2130 // If this is the last window and we had requested a starting
2131 // transition window, well there is no point now.
2132 atoken.startingData = null;
2133 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2134 // If this is the last window except for a starting transition
2135 // window, we need to get rid of the starting transition.
2136 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002137 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 + ": no more real windows");
2139 }
2140 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2141 mH.sendMessage(m);
2142 }
2143 }
Romain Guy06882f82009-06-10 13:36:04 -07002144
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002145 if (win.mAttrs.type == TYPE_WALLPAPER) {
2146 mLastWallpaperTimeoutTime = 0;
2147 adjustWallpaperWindowsLocked();
2148 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002149 adjustWallpaperWindowsLocked();
2150 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 if (!mInLayout) {
2153 assignLayersLocked();
2154 mLayoutNeeded = true;
2155 performLayoutAndPlaceSurfacesLocked();
2156 if (win.mAppToken != null) {
2157 win.mAppToken.updateReportedVisibilityLocked();
2158 }
2159 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002160
2161 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 }
2163
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002164 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2165 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2166 + ": " + msg + " / " + w.mAttrs.getTitle();
2167 if (where != null) {
2168 Slog.i(TAG, str, where);
2169 } else {
2170 Slog.i(TAG, str);
2171 }
2172 }
2173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2175 long origId = Binder.clearCallingIdentity();
2176 try {
2177 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002178 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002180 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 Surface.openTransaction();
2182 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002183 if (SHOW_TRANSACTIONS) logSurface(w,
2184 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 w.mSurface.setTransparentRegionHint(region);
2186 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002187 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 Surface.closeTransaction();
2189 }
2190 }
2191 }
2192 } finally {
2193 Binder.restoreCallingIdentity(origId);
2194 }
2195 }
2196
2197 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002198 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 Rect visibleInsets) {
2200 long origId = Binder.clearCallingIdentity();
2201 try {
2202 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002203 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 if (w != null) {
2205 w.mGivenInsetsPending = false;
2206 w.mGivenContentInsets.set(contentInsets);
2207 w.mGivenVisibleInsets.set(visibleInsets);
2208 w.mTouchableInsets = touchableInsets;
2209 mLayoutNeeded = true;
2210 performLayoutAndPlaceSurfacesLocked();
2211 }
2212 }
2213 } finally {
2214 Binder.restoreCallingIdentity(origId);
2215 }
2216 }
Romain Guy06882f82009-06-10 13:36:04 -07002217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 public void getWindowDisplayFrame(Session session, IWindow client,
2219 Rect outDisplayFrame) {
2220 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002221 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 if (win == null) {
2223 outDisplayFrame.setEmpty();
2224 return;
2225 }
2226 outDisplayFrame.set(win.mDisplayFrame);
2227 }
2228 }
2229
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002230 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2231 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002232 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2233 window.mWallpaperX = x;
2234 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002235 window.mWallpaperXStep = xStep;
2236 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002237 if (updateWallpaperOffsetLocked(window, true)) {
2238 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002239 }
2240 }
2241 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002242
Dianne Hackborn75804932009-10-20 20:15:20 -07002243 void wallpaperCommandComplete(IBinder window, Bundle result) {
2244 synchronized (mWindowMap) {
2245 if (mWaitingOnWallpaper != null &&
2246 mWaitingOnWallpaper.mClient.asBinder() == window) {
2247 mWaitingOnWallpaper = null;
2248 mWindowMap.notifyAll();
2249 }
2250 }
2251 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002252
Dianne Hackborn75804932009-10-20 20:15:20 -07002253 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2254 String action, int x, int y, int z, Bundle extras, boolean sync) {
2255 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2256 || window == mUpperWallpaperTarget) {
2257 boolean doWait = sync;
2258 int curTokenIndex = mWallpaperTokens.size();
2259 while (curTokenIndex > 0) {
2260 curTokenIndex--;
2261 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2262 int curWallpaperIndex = token.windows.size();
2263 while (curWallpaperIndex > 0) {
2264 curWallpaperIndex--;
2265 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2266 try {
2267 wallpaper.mClient.dispatchWallpaperCommand(action,
2268 x, y, z, extras, sync);
2269 // We only want to be synchronous with one wallpaper.
2270 sync = false;
2271 } catch (RemoteException e) {
2272 }
2273 }
2274 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002275
Dianne Hackborn75804932009-10-20 20:15:20 -07002276 if (doWait) {
2277 // XXX Need to wait for result.
2278 }
2279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002280
Dianne Hackborn75804932009-10-20 20:15:20 -07002281 return null;
2282 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 public int relayoutWindow(Session session, IWindow client,
2285 WindowManager.LayoutParams attrs, int requestedWidth,
2286 int requestedHeight, int viewVisibility, boolean insetsPending,
2287 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002288 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 boolean displayed = false;
2290 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002291 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002295 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 if (win == null) {
2297 return 0;
2298 }
2299 win.mRequestedWidth = requestedWidth;
2300 win.mRequestedHeight = requestedHeight;
2301
2302 if (attrs != null) {
2303 mPolicy.adjustWindowParamsLw(attrs);
2304 }
Romain Guy06882f82009-06-10 13:36:04 -07002305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 int attrChanges = 0;
2307 int flagChanges = 0;
2308 if (attrs != null) {
2309 flagChanges = win.mAttrs.flags ^= attrs.flags;
2310 attrChanges = win.mAttrs.copyFrom(attrs);
2311 }
2312
Joe Onorato8a9b2202010-02-26 18:56:32 -08002313 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314
2315 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2316 win.mAlpha = attrs.alpha;
2317 }
2318
2319 final boolean scaledWindow =
2320 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2321
2322 if (scaledWindow) {
2323 // requested{Width|Height} Surface's physical size
2324 // attrs.{width|height} Size on screen
2325 win.mHScale = (attrs.width != requestedWidth) ?
2326 (attrs.width / (float)requestedWidth) : 1.0f;
2327 win.mVScale = (attrs.height != requestedHeight) ?
2328 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002329 } else {
2330 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 }
2332
2333 boolean imMayMove = (flagChanges&(
2334 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2335 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 boolean focusMayChange = win.mViewVisibility != viewVisibility
2338 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2339 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002340
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002341 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2342 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 win.mRelayoutCalled = true;
2345 final int oldVisibility = win.mViewVisibility;
2346 win.mViewVisibility = viewVisibility;
2347 if (viewVisibility == View.VISIBLE &&
2348 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2349 displayed = !win.isVisibleLw();
2350 if (win.mExiting) {
2351 win.mExiting = false;
2352 win.mAnimation = null;
2353 }
2354 if (win.mDestroying) {
2355 win.mDestroying = false;
2356 mDestroySurface.remove(win);
2357 }
2358 if (oldVisibility == View.GONE) {
2359 win.mEnterAnimationPending = true;
2360 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002361 if (displayed) {
2362 if (win.mSurface != null && !win.mDrawPending
2363 && !win.mCommitDrawPending && !mDisplayFrozen
2364 && mPolicy.isScreenOn()) {
2365 applyEnterAnimationLocked(win);
2366 }
2367 if ((win.mAttrs.flags
2368 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2369 if (DEBUG_VISIBILITY) Slog.v(TAG,
2370 "Relayout window turning screen on: " + win);
2371 win.mTurnOnScreen = true;
2372 }
2373 int diff = 0;
2374 if (win.mConfiguration != mCurConfiguration
2375 && (win.mConfiguration == null
2376 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2377 win.mConfiguration = mCurConfiguration;
2378 if (DEBUG_CONFIGURATION) {
2379 Slog.i(TAG, "Window " + win + " visible with new config: "
2380 + win.mConfiguration + " / 0x"
2381 + Integer.toHexString(diff));
2382 }
2383 outConfig.setTo(mCurConfiguration);
2384 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2387 // To change the format, we need to re-build the surface.
2388 win.destroySurfaceLocked();
2389 displayed = true;
2390 }
2391 try {
2392 Surface surface = win.createSurfaceLocked();
2393 if (surface != null) {
2394 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002395 win.mReportDestroySurface = false;
2396 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002397 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002398 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002400 // For some reason there isn't a surface. Clear the
2401 // caller's object so they see the same state.
2402 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 }
2404 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002405 mInputMonitor.updateInputWindowsLw();
2406
Joe Onorato8a9b2202010-02-26 18:56:32 -08002407 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002408 + client + " (" + win.mAttrs.getTitle() + ")",
2409 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 Binder.restoreCallingIdentity(origId);
2411 return 0;
2412 }
2413 if (displayed) {
2414 focusMayChange = true;
2415 }
2416 if (win.mAttrs.type == TYPE_INPUT_METHOD
2417 && mInputMethodWindow == null) {
2418 mInputMethodWindow = win;
2419 imMayMove = true;
2420 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002421 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2422 && win.mAppToken != null
2423 && win.mAppToken.startingWindow != null) {
2424 // Special handling of starting window over the base
2425 // window of the app: propagate lock screen flags to it,
2426 // to provide the correct semantics while starting.
2427 final int mask =
2428 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002429 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2430 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002431 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2432 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002434 } else {
2435 win.mEnterAnimationPending = false;
2436 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002437 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002438 + ": mExiting=" + win.mExiting
2439 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 // If we are not currently running the exit animation, we
2441 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002442 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 // Try starting an animation; if there isn't one, we
2444 // can destroy the surface right away.
2445 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2446 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2447 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2448 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002449 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002451 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 } else if (win.isAnimating()) {
2454 // Currently in a hide animation... turn this into
2455 // an exit.
2456 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002457 } else if (win == mWallpaperTarget) {
2458 // If the wallpaper is currently behind this
2459 // window, we need to change both of them inside
2460 // of a transaction to avoid artifacts.
2461 win.mExiting = true;
2462 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 } else {
2464 if (mInputMethodWindow == win) {
2465 mInputMethodWindow = null;
2466 }
2467 win.destroySurfaceLocked();
2468 }
2469 }
2470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002471
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002472 if (win.mSurface == null || (win.getAttrs().flags
2473 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2474 || win.mSurfacePendingDestroy) {
2475 // We are being called from a local process, which
2476 // means outSurface holds its current surface. Ensure the
2477 // surface object is cleared, but we don't want it actually
2478 // destroyed at this point.
2479 win.mSurfacePendingDestroy = false;
2480 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002481 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002482 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002483 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002484 "Keeping surface, will report destroy: " + win);
2485 win.mReportDestroySurface = true;
2486 outSurface.copyFrom(win.mSurface);
2487 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 }
2489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 if (focusMayChange) {
2491 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2492 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 imMayMove = false;
2494 }
2495 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2496 }
Romain Guy06882f82009-06-10 13:36:04 -07002497
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002498 // updateFocusedWindowLocked() already assigned layers so we only need to
2499 // reassign them at this point if the IM window state gets shuffled
2500 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002503 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2504 // Little hack here -- we -should- be able to rely on the
2505 // function to return true if the IME has moved and needs
2506 // its layer recomputed. However, if the IME was hidden
2507 // and isn't actually moved in the list, its layer may be
2508 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 assignLayers = true;
2510 }
2511 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002512 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002513 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002514 assignLayers = true;
2515 }
2516 }
Romain Guy06882f82009-06-10 13:36:04 -07002517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 mLayoutNeeded = true;
2519 win.mGivenInsetsPending = insetsPending;
2520 if (assignLayers) {
2521 assignLayersLocked();
2522 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002523 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002525 if (displayed && win.mIsWallpaper) {
2526 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002527 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 if (win.mAppToken != null) {
2530 win.mAppToken.updateReportedVisibilityLocked();
2531 }
2532 outFrame.set(win.mFrame);
2533 outContentInsets.set(win.mContentInsets);
2534 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002535 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002537 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 + ", requestedHeight=" + requestedHeight
2539 + ", viewVisibility=" + viewVisibility
2540 + "\nRelayout returning frame=" + outFrame
2541 + ", surface=" + outSurface);
2542
Joe Onorato8a9b2202010-02-26 18:56:32 -08002543 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2545
2546 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002547
2548 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 }
2550
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002551 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 sendNewConfiguration();
2553 }
Romain Guy06882f82009-06-10 13:36:04 -07002554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2558 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2559 }
2560
2561 public void finishDrawingWindow(Session session, IWindow client) {
2562 final long origId = Binder.clearCallingIdentity();
2563 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002564 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002566 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2567 adjustWallpaperWindowsLocked();
2568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 mLayoutNeeded = true;
2570 performLayoutAndPlaceSurfacesLocked();
2571 }
2572 }
2573 Binder.restoreCallingIdentity(origId);
2574 }
2575
2576 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002577 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 + (lp != null ? lp.packageName : null)
2579 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2580 if (lp != null && lp.windowAnimations != 0) {
2581 // If this is a system resource, don't try to load it from the
2582 // application resources. It is nice to avoid loading application
2583 // resources if we can.
2584 String packageName = lp.packageName != null ? lp.packageName : "android";
2585 int resId = lp.windowAnimations;
2586 if ((resId&0xFF000000) == 0x01000000) {
2587 packageName = "android";
2588 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002589 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 + packageName);
2591 return AttributeCache.instance().get(packageName, resId,
2592 com.android.internal.R.styleable.WindowAnimation);
2593 }
2594 return null;
2595 }
Romain Guy06882f82009-06-10 13:36:04 -07002596
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002597 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002598 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002599 + packageName + " resId=0x" + Integer.toHexString(resId));
2600 if (packageName != null) {
2601 if ((resId&0xFF000000) == 0x01000000) {
2602 packageName = "android";
2603 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002604 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002605 + packageName);
2606 return AttributeCache.instance().get(packageName, resId,
2607 com.android.internal.R.styleable.WindowAnimation);
2608 }
2609 return null;
2610 }
2611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 private void applyEnterAnimationLocked(WindowState win) {
2613 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2614 if (win.mEnterAnimationPending) {
2615 win.mEnterAnimationPending = false;
2616 transit = WindowManagerPolicy.TRANSIT_ENTER;
2617 }
2618
2619 applyAnimationLocked(win, transit, true);
2620 }
2621
2622 private boolean applyAnimationLocked(WindowState win,
2623 int transit, boolean isEntrance) {
2624 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2625 // If we are trying to apply an animation, but already running
2626 // an animation of the same type, then just leave that one alone.
2627 return true;
2628 }
Romain Guy06882f82009-06-10 13:36:04 -07002629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002630 // Only apply an animation if the display isn't frozen. If it is
2631 // frozen, there is no reason to animate and it can cause strange
2632 // artifacts when we unfreeze the display if some different animation
2633 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002634 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 int anim = mPolicy.selectAnimationLw(win, transit);
2636 int attr = -1;
2637 Animation a = null;
2638 if (anim != 0) {
2639 a = AnimationUtils.loadAnimation(mContext, anim);
2640 } else {
2641 switch (transit) {
2642 case WindowManagerPolicy.TRANSIT_ENTER:
2643 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2644 break;
2645 case WindowManagerPolicy.TRANSIT_EXIT:
2646 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2647 break;
2648 case WindowManagerPolicy.TRANSIT_SHOW:
2649 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2650 break;
2651 case WindowManagerPolicy.TRANSIT_HIDE:
2652 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2653 break;
2654 }
2655 if (attr >= 0) {
2656 a = loadAnimation(win.mAttrs, attr);
2657 }
2658 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002659 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2661 + " mAnimation=" + win.mAnimation
2662 + " isEntrance=" + isEntrance);
2663 if (a != null) {
2664 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002665 RuntimeException e = null;
2666 if (!HIDE_STACK_CRAWLS) {
2667 e = new RuntimeException();
2668 e.fillInStackTrace();
2669 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002670 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 }
2672 win.setAnimation(a);
2673 win.mAnimationIsEntrance = isEntrance;
2674 }
2675 } else {
2676 win.clearAnimation();
2677 }
2678
2679 return win.mAnimation != null;
2680 }
2681
2682 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2683 int anim = 0;
2684 Context context = mContext;
2685 if (animAttr >= 0) {
2686 AttributeCache.Entry ent = getCachedAnimations(lp);
2687 if (ent != null) {
2688 context = ent.context;
2689 anim = ent.array.getResourceId(animAttr, 0);
2690 }
2691 }
2692 if (anim != 0) {
2693 return AnimationUtils.loadAnimation(context, anim);
2694 }
2695 return null;
2696 }
Romain Guy06882f82009-06-10 13:36:04 -07002697
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002698 private Animation loadAnimation(String packageName, int resId) {
2699 int anim = 0;
2700 Context context = mContext;
2701 if (resId >= 0) {
2702 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2703 if (ent != null) {
2704 context = ent.context;
2705 anim = resId;
2706 }
2707 }
2708 if (anim != 0) {
2709 return AnimationUtils.loadAnimation(context, anim);
2710 }
2711 return null;
2712 }
2713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714 private boolean applyAnimationLocked(AppWindowToken wtoken,
2715 WindowManager.LayoutParams lp, int transit, boolean enter) {
2716 // Only apply an animation if the display isn't frozen. If it is
2717 // frozen, there is no reason to animate and it can cause strange
2718 // artifacts when we unfreeze the display if some different animation
2719 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002720 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002721 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002722 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002723 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002724 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002725 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002726 } else if (mNextAppTransitionPackage != null) {
2727 a = loadAnimation(mNextAppTransitionPackage, enter ?
2728 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002729 } else {
2730 int animAttr = 0;
2731 switch (transit) {
2732 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2733 animAttr = enter
2734 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2735 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2736 break;
2737 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2738 animAttr = enter
2739 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2740 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2741 break;
2742 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2743 animAttr = enter
2744 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2745 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2746 break;
2747 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2748 animAttr = enter
2749 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2750 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2751 break;
2752 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2753 animAttr = enter
2754 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2755 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2756 break;
2757 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2758 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002759 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002760 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2761 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002762 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002763 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002764 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2765 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002766 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002767 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002768 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002769 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2770 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2771 break;
2772 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2773 animAttr = enter
2774 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2775 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2776 break;
2777 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2778 animAttr = enter
2779 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2780 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002781 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002782 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002783 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002784 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002785 + " anim=" + a
2786 + " animAttr=0x" + Integer.toHexString(animAttr)
2787 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 if (a != null) {
2790 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002791 RuntimeException e = null;
2792 if (!HIDE_STACK_CRAWLS) {
2793 e = new RuntimeException();
2794 e.fillInStackTrace();
2795 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002796 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 }
2798 wtoken.setAnimation(a);
2799 }
2800 } else {
2801 wtoken.clearAnimation();
2802 }
2803
2804 return wtoken.animation != null;
2805 }
2806
2807 // -------------------------------------------------------------
2808 // Application Window Tokens
2809 // -------------------------------------------------------------
2810
2811 public void validateAppTokens(List tokens) {
2812 int v = tokens.size()-1;
2813 int m = mAppTokens.size()-1;
2814 while (v >= 0 && m >= 0) {
2815 AppWindowToken wtoken = mAppTokens.get(m);
2816 if (wtoken.removed) {
2817 m--;
2818 continue;
2819 }
2820 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002821 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2823 }
2824 v--;
2825 m--;
2826 }
2827 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002828 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 v--;
2830 }
2831 while (m >= 0) {
2832 AppWindowToken wtoken = mAppTokens.get(m);
2833 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002834 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 }
2836 m--;
2837 }
2838 }
2839
2840 boolean checkCallingPermission(String permission, String func) {
2841 // Quick check: if the calling permission is me, it's all okay.
2842 if (Binder.getCallingPid() == Process.myPid()) {
2843 return true;
2844 }
Romain Guy06882f82009-06-10 13:36:04 -07002845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 if (mContext.checkCallingPermission(permission)
2847 == PackageManager.PERMISSION_GRANTED) {
2848 return true;
2849 }
2850 String msg = "Permission Denial: " + func + " from pid="
2851 + Binder.getCallingPid()
2852 + ", uid=" + Binder.getCallingUid()
2853 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002854 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 return false;
2856 }
Romain Guy06882f82009-06-10 13:36:04 -07002857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 AppWindowToken findAppWindowToken(IBinder token) {
2859 WindowToken wtoken = mTokenMap.get(token);
2860 if (wtoken == null) {
2861 return null;
2862 }
2863 return wtoken.appWindowToken;
2864 }
Romain Guy06882f82009-06-10 13:36:04 -07002865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 public void addWindowToken(IBinder token, int type) {
2867 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2868 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002869 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 }
Romain Guy06882f82009-06-10 13:36:04 -07002871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 synchronized(mWindowMap) {
2873 WindowToken wtoken = mTokenMap.get(token);
2874 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002875 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 return;
2877 }
2878 wtoken = new WindowToken(token, type, true);
2879 mTokenMap.put(token, wtoken);
2880 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002881 if (type == TYPE_WALLPAPER) {
2882 mWallpaperTokens.add(wtoken);
2883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 }
2885 }
Romain Guy06882f82009-06-10 13:36:04 -07002886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 public void removeWindowToken(IBinder token) {
2888 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2889 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002890 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 }
2892
2893 final long origId = Binder.clearCallingIdentity();
2894 synchronized(mWindowMap) {
2895 WindowToken wtoken = mTokenMap.remove(token);
2896 mTokenList.remove(wtoken);
2897 if (wtoken != null) {
2898 boolean delayed = false;
2899 if (!wtoken.hidden) {
2900 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 final int N = wtoken.windows.size();
2903 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 for (int i=0; i<N; i++) {
2906 WindowState win = wtoken.windows.get(i);
2907
2908 if (win.isAnimating()) {
2909 delayed = true;
2910 }
Romain Guy06882f82009-06-10 13:36:04 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 if (win.isVisibleNow()) {
2913 applyAnimationLocked(win,
2914 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 changed = true;
2916 }
2917 }
2918
2919 if (changed) {
2920 mLayoutNeeded = true;
2921 performLayoutAndPlaceSurfacesLocked();
2922 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2923 }
Romain Guy06882f82009-06-10 13:36:04 -07002924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 if (delayed) {
2926 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002927 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2928 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 }
2930 }
Romain Guy06882f82009-06-10 13:36:04 -07002931
Jeff Brownc5ed5912010-07-14 18:48:53 -07002932 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002934 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 }
2936 }
2937 Binder.restoreCallingIdentity(origId);
2938 }
2939
2940 public void addAppToken(int addPos, IApplicationToken token,
2941 int groupId, int requestedOrientation, boolean fullscreen) {
2942 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2943 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002944 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 }
Jeff Brown349703e2010-06-22 01:27:15 -07002946
2947 // Get the dispatching timeout here while we are not holding any locks so that it
2948 // can be cached by the AppWindowToken. The timeout value is used later by the
2949 // input dispatcher in code that does hold locks. If we did not cache the value
2950 // here we would run the chance of introducing a deadlock between the window manager
2951 // (which holds locks while updating the input dispatcher state) and the activity manager
2952 // (which holds locks while querying the application token).
2953 long inputDispatchingTimeoutNanos;
2954 try {
2955 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2956 } catch (RemoteException ex) {
2957 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2958 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2959 }
Romain Guy06882f82009-06-10 13:36:04 -07002960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 synchronized(mWindowMap) {
2962 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2963 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002964 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 return;
2966 }
2967 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002968 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 wtoken.groupId = groupId;
2970 wtoken.appFullscreen = fullscreen;
2971 wtoken.requestedOrientation = requestedOrientation;
2972 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002973 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 mTokenMap.put(token.asBinder(), wtoken);
2975 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 // Application tokens start out hidden.
2978 wtoken.hidden = true;
2979 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 //dump();
2982 }
2983 }
Romain Guy06882f82009-06-10 13:36:04 -07002984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 public void setAppGroupId(IBinder token, int groupId) {
2986 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2987 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002988 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 }
2990
2991 synchronized(mWindowMap) {
2992 AppWindowToken wtoken = findAppWindowToken(token);
2993 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002994 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 return;
2996 }
2997 wtoken.groupId = groupId;
2998 }
2999 }
Romain Guy06882f82009-06-10 13:36:04 -07003000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 public int getOrientationFromWindowsLocked() {
3002 int pos = mWindows.size() - 1;
3003 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003004 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 pos--;
3006 if (wtoken.mAppToken != null) {
3007 // We hit an application window. so the orientation will be determined by the
3008 // app window. No point in continuing further.
3009 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3010 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003011 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 continue;
3013 }
3014 int req = wtoken.mAttrs.screenOrientation;
3015 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3016 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3017 continue;
3018 } else {
3019 return req;
3020 }
3021 }
3022 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3023 }
Romain Guy06882f82009-06-10 13:36:04 -07003024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003026 int pos = mAppTokens.size() - 1;
3027 int curGroup = 0;
3028 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3029 boolean findingBehind = false;
3030 boolean haveGroup = false;
3031 boolean lastFullscreen = false;
3032 while (pos >= 0) {
3033 AppWindowToken wtoken = mAppTokens.get(pos);
3034 pos--;
3035 // if we're about to tear down this window and not seek for
3036 // the behind activity, don't use it for orientation
3037 if (!findingBehind
3038 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3039 continue;
3040 }
3041
3042 if (!haveGroup) {
3043 // We ignore any hidden applications on the top.
3044 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003045 continue;
3046 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003047 haveGroup = true;
3048 curGroup = wtoken.groupId;
3049 lastOrientation = wtoken.requestedOrientation;
3050 } else if (curGroup != wtoken.groupId) {
3051 // If we have hit a new application group, and the bottom
3052 // of the previous group didn't explicitly say to use
3053 // the orientation behind it, and the last app was
3054 // full screen, then we'll stick with the
3055 // user's orientation.
3056 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3057 && lastFullscreen) {
3058 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003061 int or = wtoken.requestedOrientation;
3062 // If this application is fullscreen, and didn't explicitly say
3063 // to use the orientation behind it, then just take whatever
3064 // orientation it has and ignores whatever is under it.
3065 lastFullscreen = wtoken.appFullscreen;
3066 if (lastFullscreen
3067 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3068 return or;
3069 }
3070 // If this application has requested an explicit orientation,
3071 // then use it.
3072 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3074 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3075 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3076 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3077 return or;
3078 }
3079 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3080 }
3081 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 }
Romain Guy06882f82009-06-10 13:36:04 -07003083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003085 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003086 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3087 "updateOrientationFromAppTokens()")) {
3088 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3089 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003090
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003091 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003092 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003093
3094 synchronized(mWindowMap) {
3095 if (updateOrientationFromAppTokensLocked()) {
3096 if (freezeThisOneIfNeeded != null) {
3097 AppWindowToken wtoken = findAppWindowToken(
3098 freezeThisOneIfNeeded);
3099 if (wtoken != null) {
3100 startAppFreezingScreenLocked(wtoken,
3101 ActivityInfo.CONFIG_ORIENTATION);
3102 }
3103 }
3104 config = computeNewConfigurationLocked();
3105
3106 } else if (currentConfig != null) {
3107 // No obvious action we need to take, but if our current
3108 // state mismatches the activity maanager's, update it
3109 mTempConfiguration.setToDefaults();
3110 if (computeNewConfigurationLocked(mTempConfiguration)) {
3111 if (currentConfig.diff(mTempConfiguration) != 0) {
3112 mWaitingForConfig = true;
3113 mLayoutNeeded = true;
3114 startFreezingDisplayLocked();
3115 config = new Configuration(mTempConfiguration);
3116 }
3117 }
3118 }
3119 }
3120
Dianne Hackborncfaef692009-06-15 14:24:44 -07003121 Binder.restoreCallingIdentity(ident);
3122 return config;
3123 }
3124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003126 * Determine the new desired orientation of the display, returning
3127 * a non-null new Configuration if it has changed from the current
3128 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3129 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3130 * SCREEN. This will typically be done for you if you call
3131 * sendNewConfiguration().
3132 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 * The orientation is computed from non-application windows first. If none of
3134 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003135 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3137 * android.os.IBinder)
3138 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003139 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003140 if (mDisplayFrozen) {
3141 // If the display is frozen, some activities may be in the middle
3142 // of restarting, and thus have removed their old window. If the
3143 // window has the flag to hide the lock screen, then the lock screen
3144 // can re-appear and inflict its own orientation on us. Keep the
3145 // orientation stable until this all settles down.
3146 return false;
3147 }
3148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 long ident = Binder.clearCallingIdentity();
3151 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003152 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 mForcedAppOrientation = req;
3156 //send a message to Policy indicating orientation change to take
3157 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003158 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003159 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3160 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3161 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 }
3163 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003164
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003165 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 } finally {
3167 Binder.restoreCallingIdentity(ident);
3168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169 }
Romain Guy06882f82009-06-10 13:36:04 -07003170
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003171 int computeForcedAppOrientationLocked() {
3172 int req = getOrientationFromWindowsLocked();
3173 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3174 req = getOrientationFromAppTokensLocked();
3175 }
3176 return req;
3177 }
Romain Guy06882f82009-06-10 13:36:04 -07003178
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003179 public void setNewConfiguration(Configuration config) {
3180 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3181 "setNewConfiguration()")) {
3182 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3183 }
3184
3185 synchronized(mWindowMap) {
3186 mCurConfiguration = new Configuration(config);
3187 mWaitingForConfig = false;
3188 performLayoutAndPlaceSurfacesLocked();
3189 }
3190 }
3191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3193 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3194 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003195 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 }
Romain Guy06882f82009-06-10 13:36:04 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 synchronized(mWindowMap) {
3199 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3200 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003201 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 return;
3203 }
Romain Guy06882f82009-06-10 13:36:04 -07003204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 wtoken.requestedOrientation = requestedOrientation;
3206 }
3207 }
Romain Guy06882f82009-06-10 13:36:04 -07003208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 public int getAppOrientation(IApplicationToken token) {
3210 synchronized(mWindowMap) {
3211 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3212 if (wtoken == null) {
3213 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3214 }
Romain Guy06882f82009-06-10 13:36:04 -07003215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003216 return wtoken.requestedOrientation;
3217 }
3218 }
Romain Guy06882f82009-06-10 13:36:04 -07003219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3221 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3222 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003223 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 }
3225
3226 synchronized(mWindowMap) {
3227 boolean changed = false;
3228 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003229 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 changed = mFocusedApp != null;
3231 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003232 if (changed) {
3233 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 } else {
3236 AppWindowToken newFocus = findAppWindowToken(token);
3237 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003238 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 return;
3240 }
3241 changed = mFocusedApp != newFocus;
3242 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003243 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003244 if (changed) {
3245 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003247 }
3248
3249 if (moveFocusNow && changed) {
3250 final long origId = Binder.clearCallingIdentity();
3251 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3252 Binder.restoreCallingIdentity(origId);
3253 }
3254 }
3255 }
3256
3257 public void prepareAppTransition(int transit) {
3258 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3259 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003260 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 }
Romain Guy06882f82009-06-10 13:36:04 -07003262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003264 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 TAG, "Prepare app transition: transit=" + transit
3266 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003267 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003268 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3269 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003271 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3272 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3273 // Opening a new task always supersedes a close for the anim.
3274 mNextAppTransition = transit;
3275 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3276 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3277 // Opening a new activity always supersedes a close for the anim.
3278 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 }
3280 mAppTransitionReady = false;
3281 mAppTransitionTimeout = false;
3282 mStartingIconInTransition = false;
3283 mSkipAppTransitionAnimation = false;
3284 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3285 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3286 5000);
3287 }
3288 }
3289 }
3290
3291 public int getPendingAppTransition() {
3292 return mNextAppTransition;
3293 }
Romain Guy06882f82009-06-10 13:36:04 -07003294
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003295 public void overridePendingAppTransition(String packageName,
3296 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003297 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003298 mNextAppTransitionPackage = packageName;
3299 mNextAppTransitionEnter = enterAnim;
3300 mNextAppTransitionExit = exitAnim;
3301 }
3302 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 public void executeAppTransition() {
3305 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3306 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003307 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 }
Romain Guy06882f82009-06-10 13:36:04 -07003309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003310 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003311 if (DEBUG_APP_TRANSITIONS) {
3312 RuntimeException e = new RuntimeException("here");
3313 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003314 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003315 + mNextAppTransition, e);
3316 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003317 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 mAppTransitionReady = true;
3319 final long origId = Binder.clearCallingIdentity();
3320 performLayoutAndPlaceSurfacesLocked();
3321 Binder.restoreCallingIdentity(origId);
3322 }
3323 }
3324 }
3325
3326 public void setAppStartingWindow(IBinder token, String pkg,
3327 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3328 IBinder transferFrom, boolean createIfNeeded) {
3329 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3330 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003331 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 }
3333
3334 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003335 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3337 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 AppWindowToken wtoken = findAppWindowToken(token);
3340 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003341 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 return;
3343 }
3344
3345 // If the display is frozen, we won't do anything until the
3346 // actual window is displayed so there is no reason to put in
3347 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003348 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 return;
3350 }
Romain Guy06882f82009-06-10 13:36:04 -07003351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 if (wtoken.startingData != null) {
3353 return;
3354 }
Romain Guy06882f82009-06-10 13:36:04 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 if (transferFrom != null) {
3357 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3358 if (ttoken != null) {
3359 WindowState startingWindow = ttoken.startingWindow;
3360 if (startingWindow != null) {
3361 if (mStartingIconInTransition) {
3362 // In this case, the starting icon has already
3363 // been displayed, so start letting windows get
3364 // shown immediately without any more transitions.
3365 mSkipAppTransitionAnimation = true;
3366 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003367 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 "Moving existing starting from " + ttoken
3369 + " to " + wtoken);
3370 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 // Transfer the starting window over to the new
3373 // token.
3374 wtoken.startingData = ttoken.startingData;
3375 wtoken.startingView = ttoken.startingView;
3376 wtoken.startingWindow = startingWindow;
3377 ttoken.startingData = null;
3378 ttoken.startingView = null;
3379 ttoken.startingWindow = null;
3380 ttoken.startingMoved = true;
3381 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003382 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003384 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003385 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003387 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003388 ttoken.windows.remove(startingWindow);
3389 ttoken.allAppWindows.remove(startingWindow);
3390 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 // Propagate other interesting state between the
3393 // tokens. If the old token is displayed, we should
3394 // immediately force the new one to be displayed. If
3395 // it is animating, we need to move that animation to
3396 // the new one.
3397 if (ttoken.allDrawn) {
3398 wtoken.allDrawn = true;
3399 }
3400 if (ttoken.firstWindowDrawn) {
3401 wtoken.firstWindowDrawn = true;
3402 }
3403 if (!ttoken.hidden) {
3404 wtoken.hidden = false;
3405 wtoken.hiddenRequested = false;
3406 wtoken.willBeHidden = false;
3407 }
3408 if (wtoken.clientHidden != ttoken.clientHidden) {
3409 wtoken.clientHidden = ttoken.clientHidden;
3410 wtoken.sendAppVisibilityToClients();
3411 }
3412 if (ttoken.animation != null) {
3413 wtoken.animation = ttoken.animation;
3414 wtoken.animating = ttoken.animating;
3415 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3416 ttoken.animation = null;
3417 ttoken.animLayerAdjustment = 0;
3418 wtoken.updateLayers();
3419 ttoken.updateLayers();
3420 }
Romain Guy06882f82009-06-10 13:36:04 -07003421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003423 mLayoutNeeded = true;
3424 performLayoutAndPlaceSurfacesLocked();
3425 Binder.restoreCallingIdentity(origId);
3426 return;
3427 } else if (ttoken.startingData != null) {
3428 // The previous app was getting ready to show a
3429 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003430 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 "Moving pending starting from " + ttoken
3432 + " to " + wtoken);
3433 wtoken.startingData = ttoken.startingData;
3434 ttoken.startingData = null;
3435 ttoken.startingMoved = true;
3436 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3437 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3438 // want to process the message ASAP, before any other queued
3439 // messages.
3440 mH.sendMessageAtFrontOfQueue(m);
3441 return;
3442 }
3443 }
3444 }
3445
3446 // There is no existing starting window, and the caller doesn't
3447 // want us to create one, so that's it!
3448 if (!createIfNeeded) {
3449 return;
3450 }
Romain Guy06882f82009-06-10 13:36:04 -07003451
Dianne Hackborn284ac932009-08-28 10:34:25 -07003452 // If this is a translucent or wallpaper window, then don't
3453 // show a starting window -- the current effect (a full-screen
3454 // opaque starting window that fades away to the real contents
3455 // when it is ready) does not work for this.
3456 if (theme != 0) {
3457 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3458 com.android.internal.R.styleable.Window);
3459 if (ent.array.getBoolean(
3460 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3461 return;
3462 }
3463 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003464 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3465 return;
3466 }
3467 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003468 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3469 return;
3470 }
3471 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 mStartingIconInTransition = true;
3474 wtoken.startingData = new StartingData(
3475 pkg, theme, nonLocalizedLabel,
3476 labelRes, icon);
3477 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3478 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3479 // want to process the message ASAP, before any other queued
3480 // messages.
3481 mH.sendMessageAtFrontOfQueue(m);
3482 }
3483 }
3484
3485 public void setAppWillBeHidden(IBinder token) {
3486 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3487 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003488 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489 }
3490
3491 AppWindowToken wtoken;
3492
3493 synchronized(mWindowMap) {
3494 wtoken = findAppWindowToken(token);
3495 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003496 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 -08003497 return;
3498 }
3499 wtoken.willBeHidden = true;
3500 }
3501 }
Romain Guy06882f82009-06-10 13:36:04 -07003502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3504 boolean visible, int transit, boolean performLayout) {
3505 boolean delayed = false;
3506
3507 if (wtoken.clientHidden == visible) {
3508 wtoken.clientHidden = !visible;
3509 wtoken.sendAppVisibilityToClients();
3510 }
Romain Guy06882f82009-06-10 13:36:04 -07003511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 wtoken.willBeHidden = false;
3513 if (wtoken.hidden == visible) {
3514 final int N = wtoken.allAppWindows.size();
3515 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003516 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3518 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003521
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003522 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 if (wtoken.animation == sDummyAnimation) {
3524 wtoken.animation = null;
3525 }
3526 applyAnimationLocked(wtoken, lp, transit, visible);
3527 changed = true;
3528 if (wtoken.animation != null) {
3529 delayed = runningAppAnimation = true;
3530 }
3531 }
Romain Guy06882f82009-06-10 13:36:04 -07003532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 for (int i=0; i<N; i++) {
3534 WindowState win = wtoken.allAppWindows.get(i);
3535 if (win == wtoken.startingWindow) {
3536 continue;
3537 }
3538
3539 if (win.isAnimating()) {
3540 delayed = true;
3541 }
Romain Guy06882f82009-06-10 13:36:04 -07003542
Joe Onorato8a9b2202010-02-26 18:56:32 -08003543 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 //win.dump(" ");
3545 if (visible) {
3546 if (!win.isVisibleNow()) {
3547 if (!runningAppAnimation) {
3548 applyAnimationLocked(win,
3549 WindowManagerPolicy.TRANSIT_ENTER, true);
3550 }
3551 changed = true;
3552 }
3553 } else if (win.isVisibleNow()) {
3554 if (!runningAppAnimation) {
3555 applyAnimationLocked(win,
3556 WindowManagerPolicy.TRANSIT_EXIT, false);
3557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 changed = true;
3559 }
3560 }
3561
3562 wtoken.hidden = wtoken.hiddenRequested = !visible;
3563 if (!visible) {
3564 unsetAppFreezingScreenLocked(wtoken, true, true);
3565 } else {
3566 // If we are being set visible, and the starting window is
3567 // not yet displayed, then make sure it doesn't get displayed.
3568 WindowState swin = wtoken.startingWindow;
3569 if (swin != null && (swin.mDrawPending
3570 || swin.mCommitDrawPending)) {
3571 swin.mPolicyVisibility = false;
3572 swin.mPolicyVisibilityAfterAnim = false;
3573 }
3574 }
Romain Guy06882f82009-06-10 13:36:04 -07003575
Joe Onorato8a9b2202010-02-26 18:56:32 -08003576 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3578 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003579
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003580 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003582 if (performLayout) {
3583 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3584 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003585 } else {
3586 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 }
3589 }
3590
3591 if (wtoken.animation != null) {
3592 delayed = true;
3593 }
Romain Guy06882f82009-06-10 13:36:04 -07003594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 return delayed;
3596 }
3597
3598 public void setAppVisibility(IBinder token, boolean visible) {
3599 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3600 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003601 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 }
3603
3604 AppWindowToken wtoken;
3605
3606 synchronized(mWindowMap) {
3607 wtoken = findAppWindowToken(token);
3608 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003609 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 return;
3611 }
3612
3613 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003614 RuntimeException e = null;
3615 if (!HIDE_STACK_CRAWLS) {
3616 e = new RuntimeException();
3617 e.fillInStackTrace();
3618 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003619 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 + "): mNextAppTransition=" + mNextAppTransition
3621 + " hidden=" + wtoken.hidden
3622 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3623 }
Romain Guy06882f82009-06-10 13:36:04 -07003624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 // If we are preparing an app transition, then delay changing
3626 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003627 if (!mDisplayFrozen && mPolicy.isScreenOn()
3628 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 // Already in requested state, don't do anything more.
3630 if (wtoken.hiddenRequested != visible) {
3631 return;
3632 }
3633 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003634
Joe Onorato8a9b2202010-02-26 18:56:32 -08003635 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 TAG, "Setting dummy animation on: " + wtoken);
3637 wtoken.setDummyAnimation();
3638 mOpeningApps.remove(wtoken);
3639 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003640 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 wtoken.inPendingTransaction = true;
3642 if (visible) {
3643 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 wtoken.startingDisplayed = false;
3645 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003646
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003647 // If the token is currently hidden (should be the
3648 // common case), then we need to set up to wait for
3649 // its windows to be ready.
3650 if (wtoken.hidden) {
3651 wtoken.allDrawn = false;
3652 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003653
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003654 if (wtoken.clientHidden) {
3655 // In the case where we are making an app visible
3656 // but holding off for a transition, we still need
3657 // to tell the client to make its windows visible so
3658 // they get drawn. Otherwise, we will wait on
3659 // performing the transition until all windows have
3660 // been drawn, they never will be, and we are sad.
3661 wtoken.clientHidden = false;
3662 wtoken.sendAppVisibilityToClients();
3663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 }
3665 } else {
3666 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003667
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003668 // If the token is currently visible (should be the
3669 // common case), then set up to wait for it to be hidden.
3670 if (!wtoken.hidden) {
3671 wtoken.waitingToHide = true;
3672 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 }
3674 return;
3675 }
Romain Guy06882f82009-06-10 13:36:04 -07003676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003678 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 wtoken.updateReportedVisibilityLocked();
3680 Binder.restoreCallingIdentity(origId);
3681 }
3682 }
3683
3684 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3685 boolean unfreezeSurfaceNow, boolean force) {
3686 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003687 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 + " force=" + force);
3689 final int N = wtoken.allAppWindows.size();
3690 boolean unfrozeWindows = false;
3691 for (int i=0; i<N; i++) {
3692 WindowState w = wtoken.allAppWindows.get(i);
3693 if (w.mAppFreezing) {
3694 w.mAppFreezing = false;
3695 if (w.mSurface != null && !w.mOrientationChanging) {
3696 w.mOrientationChanging = true;
3697 }
3698 unfrozeWindows = true;
3699 }
3700 }
3701 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003702 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 wtoken.freezingScreen = false;
3704 mAppsFreezingScreen--;
3705 }
3706 if (unfreezeSurfaceNow) {
3707 if (unfrozeWindows) {
3708 mLayoutNeeded = true;
3709 performLayoutAndPlaceSurfacesLocked();
3710 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003711 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 }
3713 }
3714 }
Romain Guy06882f82009-06-10 13:36:04 -07003715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003716 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3717 int configChanges) {
3718 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003719 RuntimeException e = null;
3720 if (!HIDE_STACK_CRAWLS) {
3721 e = new RuntimeException();
3722 e.fillInStackTrace();
3723 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003724 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 + ": hidden=" + wtoken.hidden + " freezing="
3726 + wtoken.freezingScreen, e);
3727 }
3728 if (!wtoken.hiddenRequested) {
3729 if (!wtoken.freezingScreen) {
3730 wtoken.freezingScreen = true;
3731 mAppsFreezingScreen++;
3732 if (mAppsFreezingScreen == 1) {
3733 startFreezingDisplayLocked();
3734 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3735 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3736 5000);
3737 }
3738 }
3739 final int N = wtoken.allAppWindows.size();
3740 for (int i=0; i<N; i++) {
3741 WindowState w = wtoken.allAppWindows.get(i);
3742 w.mAppFreezing = true;
3743 }
3744 }
3745 }
Romain Guy06882f82009-06-10 13:36:04 -07003746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 public void startAppFreezingScreen(IBinder token, int configChanges) {
3748 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3749 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003750 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 }
3752
3753 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003754 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003755 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 return;
3757 }
Romain Guy06882f82009-06-10 13:36:04 -07003758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 AppWindowToken wtoken = findAppWindowToken(token);
3760 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003761 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 return;
3763 }
3764 final long origId = Binder.clearCallingIdentity();
3765 startAppFreezingScreenLocked(wtoken, configChanges);
3766 Binder.restoreCallingIdentity(origId);
3767 }
3768 }
Romain Guy06882f82009-06-10 13:36:04 -07003769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 public void stopAppFreezingScreen(IBinder token, boolean force) {
3771 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3772 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003773 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 }
3775
3776 synchronized(mWindowMap) {
3777 AppWindowToken wtoken = findAppWindowToken(token);
3778 if (wtoken == null || wtoken.appToken == null) {
3779 return;
3780 }
3781 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003782 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3784 unsetAppFreezingScreenLocked(wtoken, true, force);
3785 Binder.restoreCallingIdentity(origId);
3786 }
3787 }
Romain Guy06882f82009-06-10 13:36:04 -07003788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003789 public void removeAppToken(IBinder token) {
3790 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3791 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003792 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 }
3794
3795 AppWindowToken wtoken = null;
3796 AppWindowToken startingToken = null;
3797 boolean delayed = false;
3798
3799 final long origId = Binder.clearCallingIdentity();
3800 synchronized(mWindowMap) {
3801 WindowToken basewtoken = mTokenMap.remove(token);
3802 mTokenList.remove(basewtoken);
3803 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003804 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003805 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 wtoken.inPendingTransaction = false;
3807 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003808 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 if (mClosingApps.contains(wtoken)) {
3810 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003811 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003813 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003814 delayed = true;
3815 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003816 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003817 TAG, "Removing app " + wtoken + " delayed=" + delayed
3818 + " animation=" + wtoken.animation
3819 + " animating=" + wtoken.animating);
3820 if (delayed) {
3821 // set the token aside because it has an active animation to be finished
3822 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003823 } else {
3824 // Make sure there is no animation running on this token,
3825 // so any windows associated with it will be removed as
3826 // soon as their animations are complete
3827 wtoken.animation = null;
3828 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 }
3830 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003831 if (mLastEnterAnimToken == wtoken) {
3832 mLastEnterAnimToken = null;
3833 mLastEnterAnimParams = null;
3834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 wtoken.removed = true;
3836 if (wtoken.startingData != null) {
3837 startingToken = wtoken;
3838 }
3839 unsetAppFreezingScreenLocked(wtoken, true, true);
3840 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003841 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 mFocusedApp = null;
3843 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003844 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 }
3846 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003847 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 }
Romain Guy06882f82009-06-10 13:36:04 -07003849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003850 if (!delayed && wtoken != null) {
3851 wtoken.updateReportedVisibilityLocked();
3852 }
3853 }
3854 Binder.restoreCallingIdentity(origId);
3855
3856 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003857 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858 + startingToken + ": app token removed");
3859 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3860 mH.sendMessage(m);
3861 }
3862 }
3863
3864 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3865 final int NW = token.windows.size();
3866 for (int i=0; i<NW; i++) {
3867 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003868 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003870 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003871 int j = win.mChildWindows.size();
3872 while (j > 0) {
3873 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003874 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003875 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003876 "Tmp removing child window " + cwin);
3877 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 }
3879 }
3880 return NW > 0;
3881 }
3882
3883 void dumpAppTokensLocked() {
3884 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003885 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
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 void dumpWindowsLocked() {
3890 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003891 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003892 }
3893 }
Romain Guy06882f82009-06-10 13:36:04 -07003894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003895 private int findWindowOffsetLocked(int tokenPos) {
3896 final int NW = mWindows.size();
3897
3898 if (tokenPos >= mAppTokens.size()) {
3899 int i = NW;
3900 while (i > 0) {
3901 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003902 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903 if (win.getAppToken() != null) {
3904 return i+1;
3905 }
3906 }
3907 }
3908
3909 while (tokenPos > 0) {
3910 // Find the first app token below the new position that has
3911 // a window displayed.
3912 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003913 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003915 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003916 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003917 "Skipping token -- currently sending to bottom");
3918 tokenPos--;
3919 continue;
3920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 int i = wtoken.windows.size();
3922 while (i > 0) {
3923 i--;
3924 WindowState win = wtoken.windows.get(i);
3925 int j = win.mChildWindows.size();
3926 while (j > 0) {
3927 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003928 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003929 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 for (int pos=NW-1; pos>=0; pos--) {
3931 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003932 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 "Found child win @" + (pos+1));
3934 return pos+1;
3935 }
3936 }
3937 }
3938 }
3939 for (int pos=NW-1; pos>=0; pos--) {
3940 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003941 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003942 return pos+1;
3943 }
3944 }
3945 }
3946 tokenPos--;
3947 }
3948
3949 return 0;
3950 }
3951
3952 private final int reAddWindowLocked(int index, WindowState win) {
3953 final int NCW = win.mChildWindows.size();
3954 boolean added = false;
3955 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003956 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003958 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child 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, win);
3961 index++;
3962 added = true;
3963 }
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 + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 mWindows.add(index, cwin);
3967 index++;
3968 }
3969 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003970 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003971 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 mWindows.add(index, win);
3973 index++;
3974 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003975 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 return index;
3977 }
Romain Guy06882f82009-06-10 13:36:04 -07003978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003979 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3980 final int NW = token.windows.size();
3981 for (int i=0; i<NW; i++) {
3982 index = reAddWindowLocked(index, token.windows.get(i));
3983 }
3984 return index;
3985 }
3986
3987 public void moveAppToken(int index, IBinder token) {
3988 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3989 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003990 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003991 }
3992
3993 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003994 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 if (DEBUG_REORDER) dumpAppTokensLocked();
3996 final AppWindowToken wtoken = findAppWindowToken(token);
3997 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003998 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 + token + " (" + wtoken + ")");
4000 return;
4001 }
4002 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004003 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004007 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 if (DEBUG_REORDER) dumpWindowsLocked();
4009 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004010 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 if (DEBUG_REORDER) dumpWindowsLocked();
4012 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004013 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 if (DEBUG_REORDER) dumpWindowsLocked();
4015 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004016 mLayoutNeeded = true;
4017 performLayoutAndPlaceSurfacesLocked();
4018 }
4019 Binder.restoreCallingIdentity(origId);
4020 }
4021 }
4022
4023 private void removeAppTokensLocked(List<IBinder> tokens) {
4024 // XXX This should be done more efficiently!
4025 // (take advantage of the fact that both lists should be
4026 // ordered in the same way.)
4027 int N = tokens.size();
4028 for (int i=0; i<N; i++) {
4029 IBinder token = tokens.get(i);
4030 final AppWindowToken wtoken = findAppWindowToken(token);
4031 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004032 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004033 + token + " (" + wtoken + ")");
4034 i--;
4035 N--;
4036 }
4037 }
4038 }
4039
Dianne Hackborna8f60182009-09-01 19:01:50 -07004040 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4041 boolean updateFocusAndLayout) {
4042 // First remove all of the windows from the list.
4043 tmpRemoveAppWindowsLocked(wtoken);
4044
4045 // Where to start adding?
4046 int pos = findWindowOffsetLocked(tokenPos);
4047
4048 // And now add them back at the correct place.
4049 pos = reAddAppWindowsLocked(pos, wtoken);
4050
4051 if (updateFocusAndLayout) {
4052 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4053 assignLayersLocked();
4054 }
4055 mLayoutNeeded = true;
4056 performLayoutAndPlaceSurfacesLocked();
4057 }
4058 }
4059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004060 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4061 // First remove all of the windows from the list.
4062 final int N = tokens.size();
4063 int i;
4064 for (i=0; i<N; i++) {
4065 WindowToken token = mTokenMap.get(tokens.get(i));
4066 if (token != null) {
4067 tmpRemoveAppWindowsLocked(token);
4068 }
4069 }
4070
4071 // Where to start adding?
4072 int pos = findWindowOffsetLocked(tokenPos);
4073
4074 // And now add them back at the correct place.
4075 for (i=0; i<N; i++) {
4076 WindowToken token = mTokenMap.get(tokens.get(i));
4077 if (token != null) {
4078 pos = reAddAppWindowsLocked(pos, token);
4079 }
4080 }
4081
Dianne Hackborna8f60182009-09-01 19:01:50 -07004082 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4083 assignLayersLocked();
4084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004085 mLayoutNeeded = true;
4086 performLayoutAndPlaceSurfacesLocked();
4087
4088 //dump();
4089 }
4090
4091 public void moveAppTokensToTop(List<IBinder> tokens) {
4092 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4093 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004094 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004095 }
4096
4097 final long origId = Binder.clearCallingIdentity();
4098 synchronized(mWindowMap) {
4099 removeAppTokensLocked(tokens);
4100 final int N = tokens.size();
4101 for (int i=0; i<N; i++) {
4102 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4103 if (wt != null) {
4104 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004105 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004106 mToTopApps.remove(wt);
4107 mToBottomApps.remove(wt);
4108 mToTopApps.add(wt);
4109 wt.sendingToBottom = false;
4110 wt.sendingToTop = true;
4111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 }
4113 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004114
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004115 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004116 moveAppWindowsLocked(tokens, mAppTokens.size());
4117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004118 }
4119 Binder.restoreCallingIdentity(origId);
4120 }
4121
4122 public void moveAppTokensToBottom(List<IBinder> tokens) {
4123 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4124 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004125 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126 }
4127
4128 final long origId = Binder.clearCallingIdentity();
4129 synchronized(mWindowMap) {
4130 removeAppTokensLocked(tokens);
4131 final int N = tokens.size();
4132 int pos = 0;
4133 for (int i=0; i<N; i++) {
4134 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4135 if (wt != null) {
4136 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004137 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004138 mToTopApps.remove(wt);
4139 mToBottomApps.remove(wt);
4140 mToBottomApps.add(i, wt);
4141 wt.sendingToTop = false;
4142 wt.sendingToBottom = true;
4143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004144 pos++;
4145 }
4146 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004147
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004148 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004149 moveAppWindowsLocked(tokens, 0);
4150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 }
4152 Binder.restoreCallingIdentity(origId);
4153 }
4154
4155 // -------------------------------------------------------------
4156 // Misc IWindowSession methods
4157 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004158
Jim Miller284b62e2010-06-08 14:27:42 -07004159 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004160 {
Jim Miller284b62e2010-06-08 14:27:42 -07004161 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4162 // called before DevicePolicyManagerService has started.
4163 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4164 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4165 Context.DEVICE_POLICY_SERVICE);
4166 if (dpm != null) {
4167 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4168 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4169 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4170 }
Jim Millerd6b57052010-06-07 17:52:42 -07004171 }
Jim Miller284b62e2010-06-08 14:27:42 -07004172 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004173 }
4174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004176 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 != PackageManager.PERMISSION_GRANTED) {
4178 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4179 }
Jim Millerd6b57052010-06-07 17:52:42 -07004180
Jim Miller284b62e2010-06-08 14:27:42 -07004181 synchronized (mKeyguardTokenWatcher) {
4182 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004183 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 }
4185
4186 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004187 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 != PackageManager.PERMISSION_GRANTED) {
4189 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191
Jim Miller284b62e2010-06-08 14:27:42 -07004192 synchronized (mKeyguardTokenWatcher) {
4193 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004194
Jim Miller284b62e2010-06-08 14:27:42 -07004195 if (!mKeyguardTokenWatcher.isAcquired()) {
4196 // If we are the last one to reenable the keyguard wait until
4197 // we have actually finished reenabling until returning.
4198 // It is possible that reenableKeyguard() can be called before
4199 // the previous disableKeyguard() is handled, in which case
4200 // neither mKeyguardTokenWatcher.acquired() or released() would
4201 // be called. In that case mKeyguardDisabled will be false here
4202 // and we have nothing to wait for.
4203 while (mKeyguardDisabled) {
4204 try {
4205 mKeyguardTokenWatcher.wait();
4206 } catch (InterruptedException e) {
4207 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 }
4209 }
4210 }
4211 }
4212 }
4213
4214 /**
4215 * @see android.app.KeyguardManager#exitKeyguardSecurely
4216 */
4217 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004218 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 != PackageManager.PERMISSION_GRANTED) {
4220 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4221 }
4222 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4223 public void onKeyguardExitResult(boolean success) {
4224 try {
4225 callback.onKeyguardExitResult(success);
4226 } catch (RemoteException e) {
4227 // Client has died, we don't care.
4228 }
4229 }
4230 });
4231 }
4232
4233 public boolean inKeyguardRestrictedInputMode() {
4234 return mPolicy.inKeyguardRestrictedKeyInputMode();
4235 }
Romain Guy06882f82009-06-10 13:36:04 -07004236
Dianne Hackbornffa42482009-09-23 22:20:11 -07004237 public void closeSystemDialogs(String reason) {
4238 synchronized(mWindowMap) {
4239 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004240 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004241 if (w.mSurface != null) {
4242 try {
4243 w.mClient.closeSystemDialogs(reason);
4244 } catch (RemoteException e) {
4245 }
4246 }
4247 }
4248 }
4249 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 static float fixScale(float scale) {
4252 if (scale < 0) scale = 0;
4253 else if (scale > 20) scale = 20;
4254 return Math.abs(scale);
4255 }
Romain Guy06882f82009-06-10 13:36:04 -07004256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 public void setAnimationScale(int which, float scale) {
4258 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4259 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004260 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 }
4262
4263 if (scale < 0) scale = 0;
4264 else if (scale > 20) scale = 20;
4265 scale = Math.abs(scale);
4266 switch (which) {
4267 case 0: mWindowAnimationScale = fixScale(scale); break;
4268 case 1: mTransitionAnimationScale = fixScale(scale); break;
4269 }
Romain Guy06882f82009-06-10 13:36:04 -07004270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 // Persist setting
4272 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4273 }
Romain Guy06882f82009-06-10 13:36:04 -07004274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 public void setAnimationScales(float[] scales) {
4276 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4277 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004278 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 }
4280
4281 if (scales != null) {
4282 if (scales.length >= 1) {
4283 mWindowAnimationScale = fixScale(scales[0]);
4284 }
4285 if (scales.length >= 2) {
4286 mTransitionAnimationScale = fixScale(scales[1]);
4287 }
4288 }
Romain Guy06882f82009-06-10 13:36:04 -07004289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 // Persist setting
4291 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4292 }
Romain Guy06882f82009-06-10 13:36:04 -07004293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 public float getAnimationScale(int which) {
4295 switch (which) {
4296 case 0: return mWindowAnimationScale;
4297 case 1: return mTransitionAnimationScale;
4298 }
4299 return 0;
4300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 public float[] getAnimationScales() {
4303 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4304 }
Romain Guy06882f82009-06-10 13:36:04 -07004305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 public int getSwitchState(int sw) {
4307 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4308 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004309 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004311 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 }
Romain Guy06882f82009-06-10 13:36:04 -07004313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004314 public int getSwitchStateForDevice(int devid, int sw) {
4315 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4316 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004317 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004319 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 }
Romain Guy06882f82009-06-10 13:36:04 -07004321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 public int getScancodeState(int sw) {
4323 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4324 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004325 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004327 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 }
Romain Guy06882f82009-06-10 13:36:04 -07004329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 public int getScancodeStateForDevice(int devid, int sw) {
4331 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4332 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004333 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004335 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004336 }
Romain Guy06882f82009-06-10 13:36:04 -07004337
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004338 public int getTrackballScancodeState(int sw) {
4339 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4340 "getTrackballScancodeState()")) {
4341 throw new SecurityException("Requires READ_INPUT_STATE permission");
4342 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004343 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004344 }
4345
4346 public int getDPadScancodeState(int sw) {
4347 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4348 "getDPadScancodeState()")) {
4349 throw new SecurityException("Requires READ_INPUT_STATE permission");
4350 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004351 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004352 }
4353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 public int getKeycodeState(int sw) {
4355 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4356 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004357 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004359 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 }
Romain Guy06882f82009-06-10 13:36:04 -07004361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 public int getKeycodeStateForDevice(int devid, int sw) {
4363 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4364 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004365 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004367 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 }
Romain Guy06882f82009-06-10 13:36:04 -07004369
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004370 public int getTrackballKeycodeState(int sw) {
4371 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4372 "getTrackballKeycodeState()")) {
4373 throw new SecurityException("Requires READ_INPUT_STATE permission");
4374 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004375 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004376 }
4377
4378 public int getDPadKeycodeState(int sw) {
4379 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4380 "getDPadKeycodeState()")) {
4381 throw new SecurityException("Requires READ_INPUT_STATE permission");
4382 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004383 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004384 }
4385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004387 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004388 }
Romain Guy06882f82009-06-10 13:36:04 -07004389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 public void enableScreenAfterBoot() {
4391 synchronized(mWindowMap) {
4392 if (mSystemBooted) {
4393 return;
4394 }
4395 mSystemBooted = true;
4396 }
Romain Guy06882f82009-06-10 13:36:04 -07004397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 performEnableScreen();
4399 }
Romain Guy06882f82009-06-10 13:36:04 -07004400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 public void enableScreenIfNeededLocked() {
4402 if (mDisplayEnabled) {
4403 return;
4404 }
4405 if (!mSystemBooted) {
4406 return;
4407 }
4408 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4409 }
Romain Guy06882f82009-06-10 13:36:04 -07004410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 public void performEnableScreen() {
4412 synchronized(mWindowMap) {
4413 if (mDisplayEnabled) {
4414 return;
4415 }
4416 if (!mSystemBooted) {
4417 return;
4418 }
Romain Guy06882f82009-06-10 13:36:04 -07004419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 // Don't enable the screen until all existing windows
4421 // have been drawn.
4422 final int N = mWindows.size();
4423 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004424 WindowState w = mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004425 if (w.isVisibleLw() && !w.mObscured
4426 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004427 return;
4428 }
4429 }
Romain Guy06882f82009-06-10 13:36:04 -07004430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004431 mDisplayEnabled = true;
4432 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004433 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004434 StringWriter sw = new StringWriter();
4435 PrintWriter pw = new PrintWriter(sw);
4436 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004437 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 }
4439 try {
4440 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4441 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 Parcel data = Parcel.obtain();
4444 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4445 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4446 data, null, 0);
4447 data.recycle();
4448 }
4449 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004450 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 }
4452 }
Romain Guy06882f82009-06-10 13:36:04 -07004453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004457 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4458 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 }
Romain Guy06882f82009-06-10 13:36:04 -07004460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 public void setInTouchMode(boolean mode) {
4462 synchronized(mWindowMap) {
4463 mInTouchMode = mode;
4464 }
4465 }
4466
Romain Guy06882f82009-06-10 13:36:04 -07004467 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004468 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004470 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004471 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
4473
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004474 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 }
Romain Guy06882f82009-06-10 13:36:04 -07004476
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004477 public void setRotationUnchecked(int rotation,
4478 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004479 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 long origId = Binder.clearCallingIdentity();
4483 boolean changed;
4484 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004485 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 }
Romain Guy06882f82009-06-10 13:36:04 -07004487
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004488 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 sendNewConfiguration();
4490 }
Romain Guy06882f82009-06-10 13:36:04 -07004491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 Binder.restoreCallingIdentity(origId);
4493 }
Romain Guy06882f82009-06-10 13:36:04 -07004494
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004495 /**
4496 * Apply a new rotation to the screen, respecting the requests of
4497 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4498 * re-evaluate the desired rotation.
4499 *
4500 * Returns null if the rotation has been changed. In this case YOU
4501 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4502 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004503 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004504 boolean changed;
4505 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4506 rotation = mRequestedRotation;
4507 } else {
4508 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004509 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004511 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004512 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004514 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004518 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 "Rotation changed to " + rotation
4520 + " from " + mRotation
4521 + " (forceApp=" + mForcedAppOrientation
4522 + ", req=" + mRequestedRotation + ")");
4523 mRotation = rotation;
4524 mWindowsFreezingScreen = true;
4525 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4526 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4527 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004528 mWaitingForConfig = true;
4529 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004531 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004532 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004533 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004534 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 }
4536 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004537 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 if (w.mSurface != null) {
4539 w.mOrientationChanging = true;
4540 }
4541 }
4542 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4543 try {
4544 mRotationWatchers.get(i).onRotationChanged(rotation);
4545 } catch (RemoteException e) {
4546 }
4547 }
4548 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 return changed;
4551 }
Romain Guy06882f82009-06-10 13:36:04 -07004552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004553 public int getRotation() {
4554 return mRotation;
4555 }
4556
4557 public int watchRotation(IRotationWatcher watcher) {
4558 final IBinder watcherBinder = watcher.asBinder();
4559 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4560 public void binderDied() {
4561 synchronized (mWindowMap) {
4562 for (int i=0; i<mRotationWatchers.size(); i++) {
4563 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004564 IRotationWatcher removed = mRotationWatchers.remove(i);
4565 if (removed != null) {
4566 removed.asBinder().unlinkToDeath(this, 0);
4567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004568 i--;
4569 }
4570 }
4571 }
4572 }
4573 };
Romain Guy06882f82009-06-10 13:36:04 -07004574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004575 synchronized (mWindowMap) {
4576 try {
4577 watcher.asBinder().linkToDeath(dr, 0);
4578 mRotationWatchers.add(watcher);
4579 } catch (RemoteException e) {
4580 // Client died, no cleanup needed.
4581 }
Romain Guy06882f82009-06-10 13:36:04 -07004582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004583 return mRotation;
4584 }
4585 }
4586
4587 /**
4588 * Starts the view server on the specified port.
4589 *
4590 * @param port The port to listener to.
4591 *
4592 * @return True if the server was successfully started, false otherwise.
4593 *
4594 * @see com.android.server.ViewServer
4595 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4596 */
4597 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004598 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004599 return false;
4600 }
4601
4602 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4603 return false;
4604 }
4605
4606 if (port < 1024) {
4607 return false;
4608 }
4609
4610 if (mViewServer != null) {
4611 if (!mViewServer.isRunning()) {
4612 try {
4613 return mViewServer.start();
4614 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004615 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004616 }
4617 }
4618 return false;
4619 }
4620
4621 try {
4622 mViewServer = new ViewServer(this, port);
4623 return mViewServer.start();
4624 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004625 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004626 }
4627 return false;
4628 }
4629
Romain Guy06882f82009-06-10 13:36:04 -07004630 private boolean isSystemSecure() {
4631 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4632 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4633 }
4634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 /**
4636 * Stops the view server if it exists.
4637 *
4638 * @return True if the server stopped, false if it wasn't started or
4639 * couldn't be stopped.
4640 *
4641 * @see com.android.server.ViewServer
4642 */
4643 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004644 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 return false;
4646 }
4647
4648 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4649 return false;
4650 }
4651
4652 if (mViewServer != null) {
4653 return mViewServer.stop();
4654 }
4655 return false;
4656 }
4657
4658 /**
4659 * Indicates whether the view server is running.
4660 *
4661 * @return True if the server is running, false otherwise.
4662 *
4663 * @see com.android.server.ViewServer
4664 */
4665 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004666 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004667 return false;
4668 }
4669
4670 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4671 return false;
4672 }
4673
4674 return mViewServer != null && mViewServer.isRunning();
4675 }
4676
4677 /**
4678 * Lists all availble windows in the system. The listing is written in the
4679 * specified Socket's output stream with the following syntax:
4680 * windowHashCodeInHexadecimal windowName
4681 * Each line of the ouput represents a different window.
4682 *
4683 * @param client The remote client to send the listing to.
4684 * @return False if an error occured, true otherwise.
4685 */
4686 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004687 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 return false;
4689 }
4690
4691 boolean result = true;
4692
Jeff Browne33348b2010-07-15 23:54:05 -07004693 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004694 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004695 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004696 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 }
4698
4699 BufferedWriter out = null;
4700
4701 // Any uncaught exception will crash the system process
4702 try {
4703 OutputStream clientStream = client.getOutputStream();
4704 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4705
4706 final int count = windows.length;
4707 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004708 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 out.write(Integer.toHexString(System.identityHashCode(w)));
4710 out.write(' ');
4711 out.append(w.mAttrs.getTitle());
4712 out.write('\n');
4713 }
4714
4715 out.write("DONE.\n");
4716 out.flush();
4717 } catch (Exception e) {
4718 result = false;
4719 } finally {
4720 if (out != null) {
4721 try {
4722 out.close();
4723 } catch (IOException e) {
4724 result = false;
4725 }
4726 }
4727 }
4728
4729 return result;
4730 }
4731
4732 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004733 * Returns the focused window in the following format:
4734 * windowHashCodeInHexadecimal windowName
4735 *
4736 * @param client The remote client to send the listing to.
4737 * @return False if an error occurred, true otherwise.
4738 */
4739 boolean viewServerGetFocusedWindow(Socket client) {
4740 if (isSystemSecure()) {
4741 return false;
4742 }
4743
4744 boolean result = true;
4745
4746 WindowState focusedWindow = getFocusedWindow();
4747
4748 BufferedWriter out = null;
4749
4750 // Any uncaught exception will crash the system process
4751 try {
4752 OutputStream clientStream = client.getOutputStream();
4753 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4754
4755 if(focusedWindow != null) {
4756 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4757 out.write(' ');
4758 out.append(focusedWindow.mAttrs.getTitle());
4759 }
4760 out.write('\n');
4761 out.flush();
4762 } catch (Exception e) {
4763 result = false;
4764 } finally {
4765 if (out != null) {
4766 try {
4767 out.close();
4768 } catch (IOException e) {
4769 result = false;
4770 }
4771 }
4772 }
4773
4774 return result;
4775 }
4776
4777 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 * Sends a command to a target window. The result of the command, if any, will be
4779 * written in the output stream of the specified socket.
4780 *
4781 * The parameters must follow this syntax:
4782 * windowHashcode extra
4783 *
4784 * Where XX is the length in characeters of the windowTitle.
4785 *
4786 * The first parameter is the target window. The window with the specified hashcode
4787 * will be the target. If no target can be found, nothing happens. The extra parameters
4788 * will be delivered to the target window and as parameters to the command itself.
4789 *
4790 * @param client The remote client to sent the result, if any, to.
4791 * @param command The command to execute.
4792 * @param parameters The command parameters.
4793 *
4794 * @return True if the command was successfully delivered, false otherwise. This does
4795 * not indicate whether the command itself was successful.
4796 */
4797 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004798 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 return false;
4800 }
4801
4802 boolean success = true;
4803 Parcel data = null;
4804 Parcel reply = null;
4805
4806 // Any uncaught exception will crash the system process
4807 try {
4808 // Find the hashcode of the window
4809 int index = parameters.indexOf(' ');
4810 if (index == -1) {
4811 index = parameters.length();
4812 }
4813 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004814 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815
4816 // Extract the command's parameter after the window description
4817 if (index < parameters.length()) {
4818 parameters = parameters.substring(index + 1);
4819 } else {
4820 parameters = "";
4821 }
4822
4823 final WindowManagerService.WindowState window = findWindow(hashCode);
4824 if (window == null) {
4825 return false;
4826 }
4827
4828 data = Parcel.obtain();
4829 data.writeInterfaceToken("android.view.IWindow");
4830 data.writeString(command);
4831 data.writeString(parameters);
4832 data.writeInt(1);
4833 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4834
4835 reply = Parcel.obtain();
4836
4837 final IBinder binder = window.mClient.asBinder();
4838 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4839 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4840
4841 reply.readException();
4842
4843 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004844 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004845 success = false;
4846 } finally {
4847 if (data != null) {
4848 data.recycle();
4849 }
4850 if (reply != null) {
4851 reply.recycle();
4852 }
4853 }
4854
4855 return success;
4856 }
4857
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004858 public void addWindowChangeListener(WindowChangeListener listener) {
4859 synchronized(mWindowMap) {
4860 mWindowChangeListeners.add(listener);
4861 }
4862 }
4863
4864 public void removeWindowChangeListener(WindowChangeListener listener) {
4865 synchronized(mWindowMap) {
4866 mWindowChangeListeners.remove(listener);
4867 }
4868 }
4869
4870 private void notifyWindowsChanged() {
4871 WindowChangeListener[] windowChangeListeners;
4872 synchronized(mWindowMap) {
4873 if(mWindowChangeListeners.isEmpty()) {
4874 return;
4875 }
4876 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4877 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4878 }
4879 int N = windowChangeListeners.length;
4880 for(int i = 0; i < N; i++) {
4881 windowChangeListeners[i].windowsChanged();
4882 }
4883 }
4884
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004885 private void notifyFocusChanged() {
4886 WindowChangeListener[] windowChangeListeners;
4887 synchronized(mWindowMap) {
4888 if(mWindowChangeListeners.isEmpty()) {
4889 return;
4890 }
4891 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4892 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4893 }
4894 int N = windowChangeListeners.length;
4895 for(int i = 0; i < N; i++) {
4896 windowChangeListeners[i].focusChanged();
4897 }
4898 }
4899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900 private WindowState findWindow(int hashCode) {
4901 if (hashCode == -1) {
4902 return getFocusedWindow();
4903 }
4904
4905 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004906 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004907 final int count = windows.size();
4908
4909 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004910 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 if (System.identityHashCode(w) == hashCode) {
4912 return w;
4913 }
4914 }
4915 }
4916
4917 return null;
4918 }
4919
4920 /*
4921 * Instruct the Activity Manager to fetch the current configuration and broadcast
4922 * that to config-changed listeners if appropriate.
4923 */
4924 void sendNewConfiguration() {
4925 try {
4926 mActivityManager.updateConfiguration(null);
4927 } catch (RemoteException e) {
4928 }
4929 }
Romain Guy06882f82009-06-10 13:36:04 -07004930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004931 public Configuration computeNewConfiguration() {
4932 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004933 return computeNewConfigurationLocked();
4934 }
4935 }
Romain Guy06882f82009-06-10 13:36:04 -07004936
Dianne Hackbornc485a602009-03-24 22:39:49 -07004937 Configuration computeNewConfigurationLocked() {
4938 Configuration config = new Configuration();
4939 if (!computeNewConfigurationLocked(config)) {
4940 return null;
4941 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004942 return config;
4943 }
Romain Guy06882f82009-06-10 13:36:04 -07004944
Dianne Hackbornc485a602009-03-24 22:39:49 -07004945 boolean computeNewConfigurationLocked(Configuration config) {
4946 if (mDisplay == null) {
4947 return false;
4948 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004949
4950 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004951
4952 // Use the effective "visual" dimensions based on current rotation
4953 final boolean rotated = (mRotation == Surface.ROTATION_90
4954 || mRotation == Surface.ROTATION_270);
4955 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4956 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4957
Dianne Hackbornc485a602009-03-24 22:39:49 -07004958 int orientation = Configuration.ORIENTATION_SQUARE;
4959 if (dw < dh) {
4960 orientation = Configuration.ORIENTATION_PORTRAIT;
4961 } else if (dw > dh) {
4962 orientation = Configuration.ORIENTATION_LANDSCAPE;
4963 }
4964 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004965
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004966 DisplayMetrics dm = new DisplayMetrics();
4967 mDisplay.getMetrics(dm);
4968 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4969
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004970 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004971 // Note we only do this once because at this point we don't
4972 // expect the screen to change in this way at runtime, and want
4973 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004974 int longSize = dw;
4975 int shortSize = dh;
4976 if (longSize < shortSize) {
4977 int tmp = longSize;
4978 longSize = shortSize;
4979 shortSize = tmp;
4980 }
4981 longSize = (int)(longSize/dm.density);
4982 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004983
Dianne Hackborn723738c2009-06-25 19:48:04 -07004984 // These semi-magic numbers define our compatibility modes for
4985 // applications with different screens. Don't change unless you
4986 // make sure to test lots and lots of apps!
4987 if (longSize < 470) {
4988 // This is shorter than an HVGA normal density screen (which
4989 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004990 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4991 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004992 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004993 // What size is this screen screen?
4994 if (longSize >= 800 && shortSize >= 600) {
4995 // SVGA or larger screens at medium density are the point
4996 // at which we consider it to be an extra large screen.
4997 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4998 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004999 // VGA or larger screens at medium density are the point
5000 // at which we consider it to be a large screen.
5001 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5002 } else {
5003 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005004
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005005 // If this screen is wider than normal HVGA, or taller
5006 // than FWVGA, then for old apps we want to run in size
5007 // compatibility mode.
5008 if (shortSize > 321 || longSize > 570) {
5009 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5010 }
5011 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005012
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005013 // Is this a long screen?
5014 if (((longSize*3)/5) >= (shortSize-1)) {
5015 // Anything wider than WVGA (5:3) is considering to be long.
5016 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5017 } else {
5018 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5019 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005020 }
5021 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005022 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005023
Dianne Hackbornc485a602009-03-24 22:39:49 -07005024 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5025 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5026 mPolicy.adjustConfigurationLw(config);
5027 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005028 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005030 // -------------------------------------------------------------
5031 // Input Events and Focus Management
5032 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005033
Jeff Brown349703e2010-06-22 01:27:15 -07005034 InputMonitor mInputMonitor = new InputMonitor();
5035
5036 /* Tracks the progress of input dispatch and ensures that input dispatch state
5037 * is kept in sync with changes in window focus, visibility, registration, and
5038 * other relevant Window Manager state transitions. */
5039 final class InputMonitor {
5040 // Current window with input focus for keys and other non-touch events. May be null.
5041 private WindowState mInputFocus;
5042
5043 // When true, prevents input dispatch from proceeding until set to false again.
5044 private boolean mInputDispatchFrozen;
5045
5046 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5047 private boolean mInputDispatchEnabled = true;
5048
5049 // Temporary list of windows information to provide to the input dispatcher.
5050 private InputWindowList mTempInputWindows = new InputWindowList();
5051
5052 // Temporary input application object to provide to the input dispatcher.
5053 private InputApplication mTempInputApplication = new InputApplication();
5054
5055 /* Notifies the window manager about a broken input channel.
5056 *
5057 * Called by the InputManager.
5058 */
5059 public void notifyInputChannelBroken(InputChannel inputChannel) {
5060 synchronized (mWindowMap) {
5061 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5062 if (windowState == null) {
5063 return; // irrelevant
5064 }
5065
5066 Slog.i(TAG, "WINDOW DIED " + windowState);
5067 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005068 }
5069 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005070
Jeff Brown349703e2010-06-22 01:27:15 -07005071 /* Notifies the window manager about an input channel that is not responding.
5072 * The method can either cause dispatching to be aborted by returning -2 or
5073 * return a new timeout in nanoseconds.
5074 *
5075 * Called by the InputManager.
5076 */
5077 public long notifyInputChannelANR(InputChannel inputChannel) {
5078 AppWindowToken token;
5079 synchronized (mWindowMap) {
5080 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5081 if (windowState == null) {
5082 return -2; // irrelevant, abort dispatching (-2)
5083 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005084
Jeff Brown349703e2010-06-22 01:27:15 -07005085 Slog.i(TAG, "Input event dispatching timed out sending to "
5086 + windowState.mAttrs.getTitle());
5087 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005088 }
5089
Jeff Brown349703e2010-06-22 01:27:15 -07005090 return notifyANRInternal(token);
5091 }
5092
5093 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5094 * by successfully delivering the event that originally timed out.
5095 *
5096 * Called by the InputManager.
5097 */
5098 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5099 // Nothing to do just now.
5100 // Just wait for the user to dismiss the ANR dialog.
5101 }
5102
5103 /* Notifies the window manager about an application that is not responding
5104 * in general rather than with respect to a particular input channel.
5105 * The method can either cause dispatching to be aborted by returning -2 or
5106 * return a new timeout in nanoseconds.
5107 *
5108 * Called by the InputManager.
5109 */
5110 public long notifyANR(Object token) {
5111 AppWindowToken appWindowToken = (AppWindowToken) token;
5112
5113 Slog.i(TAG, "Input event dispatching timed out sending to application "
5114 + appWindowToken.stringName);
5115 return notifyANRInternal(appWindowToken);
5116 }
5117
5118 private long notifyANRInternal(AppWindowToken token) {
5119 if (token != null && token.appToken != null) {
5120 try {
5121 // Notify the activity manager about the timeout and let it decide whether
5122 // to abort dispatching or keep waiting.
5123 boolean abort = token.appToken.keyDispatchingTimedOut();
5124 if (! abort) {
5125 // The activity manager declined to abort dispatching.
5126 // Wait a bit longer and timeout again later.
5127 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005128 }
Jeff Brown349703e2010-06-22 01:27:15 -07005129 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005130 }
5131 }
Jeff Brown349703e2010-06-22 01:27:15 -07005132 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005133 }
5134
Jeff Brown349703e2010-06-22 01:27:15 -07005135 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5136 synchronized (mWindowMap) {
5137 return getWindowStateForInputChannelLocked(inputChannel);
5138 }
5139 }
5140
5141 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5142 int windowCount = mWindows.size();
5143 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005144 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005145 if (windowState.mInputChannel == inputChannel) {
5146 return windowState;
5147 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005148 }
5149
Jeff Brown349703e2010-06-22 01:27:15 -07005150 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005151 }
5152
Jeff Brown349703e2010-06-22 01:27:15 -07005153 /* Updates the cached window information provided to the input dispatcher. */
5154 public void updateInputWindowsLw() {
5155 // Populate the input window list with information about all of the windows that
5156 // could potentially receive input.
5157 // As an optimization, we could try to prune the list of windows but this turns
5158 // out to be difficult because only the native code knows for sure which window
5159 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005160 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005161 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005162 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005163 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005164 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005165 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005166 continue;
5167 }
5168
Jeff Brown349703e2010-06-22 01:27:15 -07005169 final int flags = child.mAttrs.flags;
5170 final int type = child.mAttrs.type;
5171
5172 final boolean hasFocus = (child == mInputFocus);
5173 final boolean isVisible = child.isVisibleLw();
5174 final boolean hasWallpaper = (child == mWallpaperTarget)
5175 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5176
5177 // Add a window to our list of input windows.
5178 final InputWindow inputWindow = mTempInputWindows.add();
5179 inputWindow.inputChannel = child.mInputChannel;
5180 inputWindow.layoutParamsFlags = flags;
5181 inputWindow.layoutParamsType = type;
5182 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5183 inputWindow.visible = isVisible;
5184 inputWindow.hasFocus = hasFocus;
5185 inputWindow.hasWallpaper = hasWallpaper;
5186 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5187 inputWindow.ownerPid = child.mSession.mPid;
5188 inputWindow.ownerUid = child.mSession.mUid;
5189
5190 final Rect frame = child.mFrame;
5191 inputWindow.frameLeft = frame.left;
5192 inputWindow.frameTop = frame.top;
5193
5194 switch (child.mTouchableInsets) {
5195 default:
5196 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5197 inputWindow.touchableAreaLeft = frame.left;
5198 inputWindow.touchableAreaTop = frame.top;
5199 inputWindow.touchableAreaRight = frame.right;
5200 inputWindow.touchableAreaBottom = frame.bottom;
5201 break;
5202
5203 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5204 Rect inset = child.mGivenContentInsets;
5205 inputWindow.touchableAreaLeft = frame.left + inset.left;
5206 inputWindow.touchableAreaTop = frame.top + inset.top;
5207 inputWindow.touchableAreaRight = frame.right - inset.right;
5208 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5209 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005210 }
Jeff Brown349703e2010-06-22 01:27:15 -07005211
5212 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5213 Rect inset = child.mGivenVisibleInsets;
5214 inputWindow.touchableAreaLeft = frame.left + inset.left;
5215 inputWindow.touchableAreaTop = frame.top + inset.top;
5216 inputWindow.touchableAreaRight = frame.right - inset.right;
5217 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005218 break;
5219 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005220 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005221 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005222
Jeff Brown349703e2010-06-22 01:27:15 -07005223 // Send windows to native code.
5224 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005225
Jeff Brown349703e2010-06-22 01:27:15 -07005226 // Clear the list in preparation for the next round.
5227 // Also avoids keeping InputChannel objects referenced unnecessarily.
5228 mTempInputWindows.clear();
5229 }
5230
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005231 /* Provides feedback for a virtual key down. */
5232 public void virtualKeyDownFeedback() {
5233 synchronized (mWindowMap) {
5234 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5235 }
5236 }
5237
Jeff Brown349703e2010-06-22 01:27:15 -07005238 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5239 * This essentially starts a .5 second timeout for the application to process
5240 * subsequent input events while waiting for the app switch to occur. If it takes longer
5241 * than this, the pending events will be dropped.
5242 */
5243 public void notifyAppSwitchComing() {
5244 // TODO Not implemented yet. Should go in the native side.
5245 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005246
5247 /* Notifies that the lid switch changed state. */
5248 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5249 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5250 }
5251
Jeff Brown349703e2010-06-22 01:27:15 -07005252 /* Provides an opportunity for the window manager policy to intercept early key
5253 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005254 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5255 int policyFlags, boolean isScreenOn) {
5256 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5257 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005258 }
5259
5260 /* Provides an opportunity for the window manager policy to process a key before
5261 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005262 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5263 int action, int flags, int keyCode, int metaState, int repeatCount,
5264 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005265 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005266 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5267 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005268 }
5269
5270 /* Called when the current input focus changes.
5271 * Layer assignment is assumed to be complete by the time this is called.
5272 */
5273 public void setInputFocusLw(WindowState newWindow) {
5274 if (DEBUG_INPUT) {
5275 Slog.d(TAG, "Input focus has changed to " + newWindow);
5276 }
5277
5278 if (newWindow != mInputFocus) {
5279 if (newWindow != null && newWindow.canReceiveKeys()) {
5280 // If the new input focus is an error window or appears above the current
5281 // input focus, preempt any pending synchronous dispatch so that we can
5282 // start delivering events to the new input focus as soon as possible.
5283 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5284 if (DEBUG_INPUT) {
5285 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005286 }
Jeff Brown349703e2010-06-22 01:27:15 -07005287 preemptInputDispatchLw();
5288 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5289 if (DEBUG_INPUT) {
5290 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5291 + "old win layer=" + mInputFocus.mLayer
5292 + ", new win layer=" + newWindow.mLayer);
5293 }
5294 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005295 }
Jeff Brown349703e2010-06-22 01:27:15 -07005296
5297 // Displaying a window implicitly causes dispatching to be unpaused.
5298 // This is to protect against bugs if someone pauses dispatching but
5299 // forgets to resume.
5300 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005301 }
Jeff Brown349703e2010-06-22 01:27:15 -07005302
5303 mInputFocus = newWindow;
5304 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005305 }
5306 }
5307
Jeff Brown349703e2010-06-22 01:27:15 -07005308 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5309 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5310 * can begin.
5311 */
5312 private void preemptInputDispatchLw() {
5313 mInputManager.preemptInputDispatch();
5314 }
5315
5316 public void setFocusedAppLw(AppWindowToken newApp) {
5317 // Focused app has changed.
5318 if (newApp == null) {
5319 mInputManager.setFocusedApplication(null);
5320 } else {
5321 mTempInputApplication.name = newApp.toString();
5322 mTempInputApplication.dispatchingTimeoutNanos =
5323 newApp.inputDispatchingTimeoutNanos;
5324 mTempInputApplication.token = newApp;
5325
5326 mInputManager.setFocusedApplication(mTempInputApplication);
5327 }
5328 }
5329
Jeff Brown349703e2010-06-22 01:27:15 -07005330 public void pauseDispatchingLw(WindowToken window) {
5331 if (! window.paused) {
5332 if (DEBUG_INPUT) {
5333 Slog.v(TAG, "Pausing WindowToken " + window);
5334 }
5335
5336 window.paused = true;
5337 updateInputWindowsLw();
5338 }
5339 }
5340
5341 public void resumeDispatchingLw(WindowToken window) {
5342 if (window.paused) {
5343 if (DEBUG_INPUT) {
5344 Slog.v(TAG, "Resuming WindowToken " + window);
5345 }
5346
5347 window.paused = false;
5348 updateInputWindowsLw();
5349 }
5350 }
5351
5352 public void freezeInputDispatchingLw() {
5353 if (! mInputDispatchFrozen) {
5354 if (DEBUG_INPUT) {
5355 Slog.v(TAG, "Freezing input dispatching");
5356 }
5357
5358 mInputDispatchFrozen = true;
5359 updateInputDispatchModeLw();
5360 }
5361 }
5362
5363 public void thawInputDispatchingLw() {
5364 if (mInputDispatchFrozen) {
5365 if (DEBUG_INPUT) {
5366 Slog.v(TAG, "Thawing input dispatching");
5367 }
5368
5369 mInputDispatchFrozen = false;
5370 updateInputDispatchModeLw();
5371 }
5372 }
5373
5374 public void setEventDispatchingLw(boolean enabled) {
5375 if (mInputDispatchEnabled != enabled) {
5376 if (DEBUG_INPUT) {
5377 Slog.v(TAG, "Setting event dispatching to " + enabled);
5378 }
5379
5380 mInputDispatchEnabled = enabled;
5381 updateInputDispatchModeLw();
5382 }
5383 }
5384
5385 private void updateInputDispatchModeLw() {
5386 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5387 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005390 public void pauseKeyDispatching(IBinder _token) {
5391 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5392 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005393 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005394 }
5395
5396 synchronized (mWindowMap) {
5397 WindowToken token = mTokenMap.get(_token);
5398 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005399 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005400 }
5401 }
5402 }
5403
5404 public void resumeKeyDispatching(IBinder _token) {
5405 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5406 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005407 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005408 }
5409
5410 synchronized (mWindowMap) {
5411 WindowToken token = mTokenMap.get(_token);
5412 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005413 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005414 }
5415 }
5416 }
5417
5418 public void setEventDispatching(boolean enabled) {
5419 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5420 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005421 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005422 }
5423
5424 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005425 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005426 }
5427 }
Romain Guy06882f82009-06-10 13:36:04 -07005428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005429 /**
5430 * Injects a keystroke event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005431 * Even when sync is false, this method may block while waiting for current
5432 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005433 *
5434 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005435 * {@link SystemClock#uptimeMillis()} as the timebase.)
5436 * @param sync If true, wait for the event to be completed before returning to the caller.
5437 * @return Returns true if event was dispatched, false if it was dropped for any reason
5438 */
5439 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5440 long downTime = ev.getDownTime();
5441 long eventTime = ev.getEventTime();
5442
5443 int action = ev.getAction();
5444 int code = ev.getKeyCode();
5445 int repeatCount = ev.getRepeatCount();
5446 int metaState = ev.getMetaState();
5447 int deviceId = ev.getDeviceId();
5448 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005449 int source = ev.getSource();
5450
5451 if (source == InputDevice.SOURCE_UNKNOWN) {
5452 source = InputDevice.SOURCE_KEYBOARD;
5453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005454
5455 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5456 if (downTime == 0) downTime = eventTime;
5457
5458 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005459 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005460
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005461 final int pid = Binder.getCallingPid();
5462 final int uid = Binder.getCallingUid();
5463 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005464
Jeff Brown6ec402b2010-07-28 15:48:59 -07005465 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5466 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5467 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5468 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005469
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005470 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005471 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005472 }
5473
5474 /**
5475 * Inject a pointer (touch) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005476 * Even when sync is false, this method may block while waiting for current
5477 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005478 *
5479 * @param ev A motion event describing the pointer (touch) action. (As noted in
5480 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005481 * {@link SystemClock#uptimeMillis()} as the timebase.)
5482 * @param sync If true, wait for the event to be completed before returning to the caller.
5483 * @return Returns true if event was dispatched, false if it was dropped for any reason
5484 */
5485 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005486 final int pid = Binder.getCallingPid();
5487 final int uid = Binder.getCallingUid();
5488 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005489
Jeff Brownc5ed5912010-07-14 18:48:53 -07005490 MotionEvent newEvent = MotionEvent.obtain(ev);
5491 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5492 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5493 }
5494
Jeff Brown6ec402b2010-07-28 15:48:59 -07005495 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5496 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5497 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5498 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005499
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005500 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005501 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005502 }
Romain Guy06882f82009-06-10 13:36:04 -07005503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005504 /**
5505 * Inject a trackball (navigation device) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005506 * Even when sync is false, this method may block while waiting for current
5507 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005508 *
5509 * @param ev A motion event describing the trackball action. (As noted in
5510 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005511 * {@link SystemClock#uptimeMillis()} as the timebase.)
5512 * @param sync If true, wait for the event to be completed before returning to the caller.
5513 * @return Returns true if event was dispatched, false if it was dropped for any reason
5514 */
5515 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005516 final int pid = Binder.getCallingPid();
5517 final int uid = Binder.getCallingUid();
5518 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005519
Jeff Brownc5ed5912010-07-14 18:48:53 -07005520 MotionEvent newEvent = MotionEvent.obtain(ev);
5521 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5522 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5523 }
5524
Jeff Brown6ec402b2010-07-28 15:48:59 -07005525 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5526 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5527 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5528 INJECTION_TIMEOUT_MILLIS);
5529
5530 Binder.restoreCallingIdentity(ident);
5531 return reportInjectionResult(result);
5532 }
5533
5534 /**
5535 * Inject an input event into the UI without waiting for dispatch to commence.
5536 * This variant is useful for fire-and-forget input event injection. It does not
5537 * block any longer than it takes to enqueue the input event.
5538 *
5539 * @param ev An input event. (Be sure to set the input source correctly.)
5540 * @return Returns true if event was dispatched, false if it was dropped for any reason
5541 */
5542 public boolean injectInputEventNoWait(InputEvent ev) {
5543 final int pid = Binder.getCallingPid();
5544 final int uid = Binder.getCallingUid();
5545 final long ident = Binder.clearCallingIdentity();
5546
5547 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5548 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5549 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005550
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005551 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005552 return reportInjectionResult(result);
5553 }
5554
5555 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005556 switch (result) {
5557 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5558 Slog.w(TAG, "Input event injection permission denied.");
5559 throw new SecurityException(
5560 "Injecting to another application requires INJECT_EVENTS permission");
5561 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005562 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005563 return true;
5564 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5565 Slog.w(TAG, "Input event injection timed out.");
5566 return false;
5567 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5568 default:
5569 Slog.w(TAG, "Input event injection failed.");
5570 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005572 }
Romain Guy06882f82009-06-10 13:36:04 -07005573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005574 private WindowState getFocusedWindow() {
5575 synchronized (mWindowMap) {
5576 return getFocusedWindowLocked();
5577 }
5578 }
5579
5580 private WindowState getFocusedWindowLocked() {
5581 return mCurrentFocus;
5582 }
Romain Guy06882f82009-06-10 13:36:04 -07005583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005584 public boolean detectSafeMode() {
5585 mSafeMode = mPolicy.detectSafeMode();
5586 return mSafeMode;
5587 }
Romain Guy06882f82009-06-10 13:36:04 -07005588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005589 public void systemReady() {
5590 mPolicy.systemReady();
5591 }
Romain Guy06882f82009-06-10 13:36:04 -07005592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005593 // -------------------------------------------------------------
5594 // Client Session State
5595 // -------------------------------------------------------------
5596
5597 private final class Session extends IWindowSession.Stub
5598 implements IBinder.DeathRecipient {
5599 final IInputMethodClient mClient;
5600 final IInputContext mInputContext;
5601 final int mUid;
5602 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005603 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005604 SurfaceSession mSurfaceSession;
5605 int mNumWindow = 0;
5606 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005608 public Session(IInputMethodClient client, IInputContext inputContext) {
5609 mClient = client;
5610 mInputContext = inputContext;
5611 mUid = Binder.getCallingUid();
5612 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005613 StringBuilder sb = new StringBuilder();
5614 sb.append("Session{");
5615 sb.append(Integer.toHexString(System.identityHashCode(this)));
5616 sb.append(" uid ");
5617 sb.append(mUid);
5618 sb.append("}");
5619 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005621 synchronized (mWindowMap) {
5622 if (mInputMethodManager == null && mHaveInputMethods) {
5623 IBinder b = ServiceManager.getService(
5624 Context.INPUT_METHOD_SERVICE);
5625 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5626 }
5627 }
5628 long ident = Binder.clearCallingIdentity();
5629 try {
5630 // Note: it is safe to call in to the input method manager
5631 // here because we are not holding our lock.
5632 if (mInputMethodManager != null) {
5633 mInputMethodManager.addClient(client, inputContext,
5634 mUid, mPid);
5635 } else {
5636 client.setUsingInputMethod(false);
5637 }
5638 client.asBinder().linkToDeath(this, 0);
5639 } catch (RemoteException e) {
5640 // The caller has died, so we can just forget about this.
5641 try {
5642 if (mInputMethodManager != null) {
5643 mInputMethodManager.removeClient(client);
5644 }
5645 } catch (RemoteException ee) {
5646 }
5647 } finally {
5648 Binder.restoreCallingIdentity(ident);
5649 }
5650 }
Romain Guy06882f82009-06-10 13:36:04 -07005651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005652 @Override
5653 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5654 throws RemoteException {
5655 try {
5656 return super.onTransact(code, data, reply, flags);
5657 } catch (RuntimeException e) {
5658 // Log all 'real' exceptions thrown to the caller
5659 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005660 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005661 }
5662 throw e;
5663 }
5664 }
5665
5666 public void binderDied() {
5667 // Note: it is safe to call in to the input method manager
5668 // here because we are not holding our lock.
5669 try {
5670 if (mInputMethodManager != null) {
5671 mInputMethodManager.removeClient(mClient);
5672 }
5673 } catch (RemoteException e) {
5674 }
5675 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005676 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005677 mClientDead = true;
5678 killSessionLocked();
5679 }
5680 }
5681
5682 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005683 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5684 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5685 outInputChannel);
5686 }
5687
5688 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005689 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005690 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005691 }
Romain Guy06882f82009-06-10 13:36:04 -07005692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005693 public void remove(IWindow window) {
5694 removeWindow(this, window);
5695 }
Romain Guy06882f82009-06-10 13:36:04 -07005696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005697 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5698 int requestedWidth, int requestedHeight, int viewFlags,
5699 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005700 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005701 return relayoutWindow(this, window, attrs,
5702 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005703 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005704 }
Romain Guy06882f82009-06-10 13:36:04 -07005705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005706 public void setTransparentRegion(IWindow window, Region region) {
5707 setTransparentRegionWindow(this, window, region);
5708 }
Romain Guy06882f82009-06-10 13:36:04 -07005709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005710 public void setInsets(IWindow window, int touchableInsets,
5711 Rect contentInsets, Rect visibleInsets) {
5712 setInsetsWindow(this, window, touchableInsets, contentInsets,
5713 visibleInsets);
5714 }
Romain Guy06882f82009-06-10 13:36:04 -07005715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005716 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5717 getWindowDisplayFrame(this, window, outDisplayFrame);
5718 }
Romain Guy06882f82009-06-10 13:36:04 -07005719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005720 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005721 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005722 TAG, "IWindow finishDrawing called for " + window);
5723 finishDrawingWindow(this, window);
5724 }
5725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005726 public void setInTouchMode(boolean mode) {
5727 synchronized(mWindowMap) {
5728 mInTouchMode = mode;
5729 }
5730 }
5731
5732 public boolean getInTouchMode() {
5733 synchronized(mWindowMap) {
5734 return mInTouchMode;
5735 }
5736 }
5737
5738 public boolean performHapticFeedback(IWindow window, int effectId,
5739 boolean always) {
5740 synchronized(mWindowMap) {
5741 long ident = Binder.clearCallingIdentity();
5742 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005743 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005744 windowForClientLocked(this, window, true),
5745 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005746 } finally {
5747 Binder.restoreCallingIdentity(ident);
5748 }
5749 }
5750 }
Romain Guy06882f82009-06-10 13:36:04 -07005751
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005752 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005753 synchronized(mWindowMap) {
5754 long ident = Binder.clearCallingIdentity();
5755 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005756 setWindowWallpaperPositionLocked(
5757 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005758 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005759 } finally {
5760 Binder.restoreCallingIdentity(ident);
5761 }
5762 }
5763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005764
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005765 public void wallpaperOffsetsComplete(IBinder window) {
5766 WindowManagerService.this.wallpaperOffsetsComplete(window);
5767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005768
Dianne Hackborn75804932009-10-20 20:15:20 -07005769 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5770 int z, Bundle extras, boolean sync) {
5771 synchronized(mWindowMap) {
5772 long ident = Binder.clearCallingIdentity();
5773 try {
5774 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005775 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005776 action, x, y, z, extras, sync);
5777 } finally {
5778 Binder.restoreCallingIdentity(ident);
5779 }
5780 }
5781 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005782
Dianne Hackborn75804932009-10-20 20:15:20 -07005783 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5784 WindowManagerService.this.wallpaperCommandComplete(window, result);
5785 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 void windowAddedLocked() {
5788 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005789 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005790 TAG, "First window added to " + this + ", creating SurfaceSession");
5791 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005792 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005793 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005794 mSessions.add(this);
5795 }
5796 mNumWindow++;
5797 }
5798
5799 void windowRemovedLocked() {
5800 mNumWindow--;
5801 killSessionLocked();
5802 }
Romain Guy06882f82009-06-10 13:36:04 -07005803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005804 void killSessionLocked() {
5805 if (mNumWindow <= 0 && mClientDead) {
5806 mSessions.remove(this);
5807 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005808 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005809 TAG, "Last window removed from " + this
5810 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005811 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005812 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005813 try {
5814 mSurfaceSession.kill();
5815 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005816 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005817 + mSurfaceSession + " in session " + this
5818 + ": " + e.toString());
5819 }
5820 mSurfaceSession = null;
5821 }
5822 }
5823 }
Romain Guy06882f82009-06-10 13:36:04 -07005824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005826 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5827 pw.print(" mClientDead="); pw.print(mClientDead);
5828 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005829 }
5830
5831 @Override
5832 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005833 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 }
5835 }
5836
5837 // -------------------------------------------------------------
5838 // Client Window State
5839 // -------------------------------------------------------------
5840
5841 private final class WindowState implements WindowManagerPolicy.WindowState {
5842 final Session mSession;
5843 final IWindow mClient;
5844 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005845 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005846 AppWindowToken mAppToken;
5847 AppWindowToken mTargetAppToken;
5848 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5849 final DeathRecipient mDeathRecipient;
5850 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005851 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005852 final int mBaseLayer;
5853 final int mSubLayer;
5854 final boolean mLayoutAttached;
5855 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005856 final boolean mIsWallpaper;
5857 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005858 int mViewVisibility;
5859 boolean mPolicyVisibility = true;
5860 boolean mPolicyVisibilityAfterAnim = true;
5861 boolean mAppFreezing;
5862 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005863 boolean mReportDestroySurface;
5864 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005865 boolean mAttachedHidden; // is our parent window hidden?
5866 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005867 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005868 int mRequestedWidth;
5869 int mRequestedHeight;
5870 int mLastRequestedWidth;
5871 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005872 int mLayer;
5873 int mAnimLayer;
5874 int mLastLayer;
5875 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005876 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005877 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005878
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005879 int mLayoutSeq = -1;
5880
5881 Configuration mConfiguration = null;
5882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883 // Actual frame shown on-screen (may be modified by animation)
5884 final Rect mShownFrame = new Rect();
5885 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005887 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005888 * Set when we have changed the size of the surface, to know that
5889 * we must tell them application to resize (and thus redraw itself).
5890 */
5891 boolean mSurfaceResized;
5892
5893 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005894 * Insets that determine the actually visible area
5895 */
5896 final Rect mVisibleInsets = new Rect();
5897 final Rect mLastVisibleInsets = new Rect();
5898 boolean mVisibleInsetsChanged;
5899
5900 /**
5901 * Insets that are covered by system windows
5902 */
5903 final Rect mContentInsets = new Rect();
5904 final Rect mLastContentInsets = new Rect();
5905 boolean mContentInsetsChanged;
5906
5907 /**
5908 * Set to true if we are waiting for this window to receive its
5909 * given internal insets before laying out other windows based on it.
5910 */
5911 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005913 /**
5914 * These are the content insets that were given during layout for
5915 * this window, to be applied to windows behind it.
5916 */
5917 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005919 /**
5920 * These are the visible insets that were given during layout for
5921 * this window, to be applied to windows behind it.
5922 */
5923 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005925 /**
5926 * Flag indicating whether the touchable region should be adjusted by
5927 * the visible insets; if false the area outside the visible insets is
5928 * NOT touchable, so we must use those to adjust the frame during hit
5929 * tests.
5930 */
5931 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005933 // Current transformation being applied.
5934 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5935 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5936 float mHScale=1, mVScale=1;
5937 float mLastHScale=1, mLastVScale=1;
5938 final Matrix mTmpMatrix = new Matrix();
5939
5940 // "Real" frame that the application sees.
5941 final Rect mFrame = new Rect();
5942 final Rect mLastFrame = new Rect();
5943
5944 final Rect mContainingFrame = new Rect();
5945 final Rect mDisplayFrame = new Rect();
5946 final Rect mContentFrame = new Rect();
5947 final Rect mVisibleFrame = new Rect();
5948
5949 float mShownAlpha = 1;
5950 float mAlpha = 1;
5951 float mLastAlpha = 1;
5952
5953 // Set to true if, when the window gets displayed, it should perform
5954 // an enter animation.
5955 boolean mEnterAnimationPending;
5956
5957 // Currently running animation.
5958 boolean mAnimating;
5959 boolean mLocalAnimating;
5960 Animation mAnimation;
5961 boolean mAnimationIsEntrance;
5962 boolean mHasTransformation;
5963 boolean mHasLocalTransformation;
5964 final Transformation mTransformation = new Transformation();
5965
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005966 // If a window showing a wallpaper: the requested offset for the
5967 // wallpaper; if a wallpaper window: the currently applied offset.
5968 float mWallpaperX = -1;
5969 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005970
5971 // If a window showing a wallpaper: what fraction of the offset
5972 // range corresponds to a full virtual screen.
5973 float mWallpaperXStep = -1;
5974 float mWallpaperYStep = -1;
5975
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005976 // Wallpaper windows: pixels offset based on above variables.
5977 int mXOffset;
5978 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005980 // This is set after IWindowSession.relayout() has been called at
5981 // least once for the window. It allows us to detect the situation
5982 // where we don't yet have a surface, but should have one soon, so
5983 // we can give the window focus before waiting for the relayout.
5984 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005986 // This is set after the Surface has been created but before the
5987 // window has been drawn. During this time the surface is hidden.
5988 boolean mDrawPending;
5989
5990 // This is set after the window has finished drawing for the first
5991 // time but before its surface is shown. The surface will be
5992 // displayed when the next layout is run.
5993 boolean mCommitDrawPending;
5994
5995 // This is set during the time after the window's drawing has been
5996 // committed, and before its surface is actually shown. It is used
5997 // to delay showing the surface until all windows in a token are ready
5998 // to be shown.
5999 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001 // Set when the window has been shown in the screen the first time.
6002 boolean mHasDrawn;
6003
6004 // Currently running an exit animation?
6005 boolean mExiting;
6006
6007 // Currently on the mDestroySurface list?
6008 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006010 // Completely remove from window manager after exit animation?
6011 boolean mRemoveOnExit;
6012
6013 // Set when the orientation is changing and this window has not yet
6014 // been updated for the new orientation.
6015 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017 // Is this window now (or just being) removed?
6018 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006019
Dianne Hackborn16064f92010-03-25 00:47:24 -07006020 // For debugging, this is the last information given to the surface flinger.
6021 boolean mSurfaceShown;
6022 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6023 int mSurfaceLayer;
6024 float mSurfaceAlpha;
6025
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006026 // Input channel
6027 InputChannel mInputChannel;
6028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006029 WindowState(Session s, IWindow c, WindowToken token,
6030 WindowState attachedWindow, WindowManager.LayoutParams a,
6031 int viewVisibility) {
6032 mSession = s;
6033 mClient = c;
6034 mToken = token;
6035 mAttrs.copyFrom(a);
6036 mViewVisibility = viewVisibility;
6037 DeathRecipient deathRecipient = new DeathRecipient();
6038 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006039 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006040 TAG, "Window " + this + " client=" + c.asBinder()
6041 + " token=" + token + " (" + mAttrs.token + ")");
6042 try {
6043 c.asBinder().linkToDeath(deathRecipient, 0);
6044 } catch (RemoteException e) {
6045 mDeathRecipient = null;
6046 mAttachedWindow = null;
6047 mLayoutAttached = false;
6048 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006049 mIsWallpaper = false;
6050 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006051 mBaseLayer = 0;
6052 mSubLayer = 0;
6053 return;
6054 }
6055 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006057 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6058 mAttrs.type <= LAST_SUB_WINDOW)) {
6059 // The multiplier here is to reserve space for multiple
6060 // windows in the same type layer.
6061 mBaseLayer = mPolicy.windowTypeToLayerLw(
6062 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6063 + TYPE_LAYER_OFFSET;
6064 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6065 mAttachedWindow = attachedWindow;
6066 mAttachedWindow.mChildWindows.add(this);
6067 mLayoutAttached = mAttrs.type !=
6068 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6069 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6070 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006071 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6072 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006073 } else {
6074 // The multiplier here is to reserve space for multiple
6075 // windows in the same type layer.
6076 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6077 * TYPE_LAYER_MULTIPLIER
6078 + TYPE_LAYER_OFFSET;
6079 mSubLayer = 0;
6080 mAttachedWindow = null;
6081 mLayoutAttached = false;
6082 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6083 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006084 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6085 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006086 }
6087
6088 WindowState appWin = this;
6089 while (appWin.mAttachedWindow != null) {
6090 appWin = mAttachedWindow;
6091 }
6092 WindowToken appToken = appWin.mToken;
6093 while (appToken.appWindowToken == null) {
6094 WindowToken parent = mTokenMap.get(appToken.token);
6095 if (parent == null || appToken == parent) {
6096 break;
6097 }
6098 appToken = parent;
6099 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006100 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 mAppToken = appToken.appWindowToken;
6102
6103 mSurface = null;
6104 mRequestedWidth = 0;
6105 mRequestedHeight = 0;
6106 mLastRequestedWidth = 0;
6107 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006108 mXOffset = 0;
6109 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006110 mLayer = 0;
6111 mAnimLayer = 0;
6112 mLastLayer = 0;
6113 }
6114
6115 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006116 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117 TAG, "Attaching " + this + " token=" + mToken
6118 + ", list=" + mToken.windows);
6119 mSession.windowAddedLocked();
6120 }
6121
6122 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6123 mHaveFrame = true;
6124
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006125 final Rect container = mContainingFrame;
6126 container.set(pf);
6127
6128 final Rect display = mDisplayFrame;
6129 display.set(df);
6130
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006131 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006132 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006133 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6134 display.intersect(mCompatibleScreenFrame);
6135 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006136 }
6137
6138 final int pw = container.right - container.left;
6139 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006140
6141 int w,h;
6142 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6143 w = mAttrs.width < 0 ? pw : mAttrs.width;
6144 h = mAttrs.height< 0 ? ph : mAttrs.height;
6145 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006146 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6147 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 }
Romain Guy06882f82009-06-10 13:36:04 -07006149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 final Rect content = mContentFrame;
6151 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 final Rect visible = mVisibleFrame;
6154 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006156 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006157 final int fw = frame.width();
6158 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006160 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6161 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6162
6163 Gravity.apply(mAttrs.gravity, w, h, container,
6164 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6165 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6166
6167 //System.out.println("Out: " + mFrame);
6168
6169 // Now make sure the window fits in the overall display.
6170 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 // Make sure the content and visible frames are inside of the
6173 // final window frame.
6174 if (content.left < frame.left) content.left = frame.left;
6175 if (content.top < frame.top) content.top = frame.top;
6176 if (content.right > frame.right) content.right = frame.right;
6177 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6178 if (visible.left < frame.left) visible.left = frame.left;
6179 if (visible.top < frame.top) visible.top = frame.top;
6180 if (visible.right > frame.right) visible.right = frame.right;
6181 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006183 final Rect contentInsets = mContentInsets;
6184 contentInsets.left = content.left-frame.left;
6185 contentInsets.top = content.top-frame.top;
6186 contentInsets.right = frame.right-content.right;
6187 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006189 final Rect visibleInsets = mVisibleInsets;
6190 visibleInsets.left = visible.left-frame.left;
6191 visibleInsets.top = visible.top-frame.top;
6192 visibleInsets.right = frame.right-visible.right;
6193 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006194
Dianne Hackborn284ac932009-08-28 10:34:25 -07006195 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6196 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006197 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006198 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 if (localLOGV) {
6201 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6202 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006203 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006204 + mRequestedWidth + ", mRequestedheight="
6205 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6206 + "): frame=" + mFrame.toShortString()
6207 + " ci=" + contentInsets.toShortString()
6208 + " vi=" + visibleInsets.toShortString());
6209 //}
6210 }
6211 }
Romain Guy06882f82009-06-10 13:36:04 -07006212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006213 public Rect getFrameLw() {
6214 return mFrame;
6215 }
6216
6217 public Rect getShownFrameLw() {
6218 return mShownFrame;
6219 }
6220
6221 public Rect getDisplayFrameLw() {
6222 return mDisplayFrame;
6223 }
6224
6225 public Rect getContentFrameLw() {
6226 return mContentFrame;
6227 }
6228
6229 public Rect getVisibleFrameLw() {
6230 return mVisibleFrame;
6231 }
6232
6233 public boolean getGivenInsetsPendingLw() {
6234 return mGivenInsetsPending;
6235 }
6236
6237 public Rect getGivenContentInsetsLw() {
6238 return mGivenContentInsets;
6239 }
Romain Guy06882f82009-06-10 13:36:04 -07006240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006241 public Rect getGivenVisibleInsetsLw() {
6242 return mGivenVisibleInsets;
6243 }
Romain Guy06882f82009-06-10 13:36:04 -07006244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006245 public WindowManager.LayoutParams getAttrs() {
6246 return mAttrs;
6247 }
6248
6249 public int getSurfaceLayer() {
6250 return mLayer;
6251 }
Romain Guy06882f82009-06-10 13:36:04 -07006252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006253 public IApplicationToken getAppToken() {
6254 return mAppToken != null ? mAppToken.appToken : null;
6255 }
Jeff Brown349703e2010-06-22 01:27:15 -07006256
6257 public long getInputDispatchingTimeoutNanos() {
6258 return mAppToken != null
6259 ? mAppToken.inputDispatchingTimeoutNanos
6260 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006262
6263 public boolean hasAppShownWindows() {
6264 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6265 }
6266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006267 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006268 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006269 TAG, "Setting animation in " + this + ": " + anim);
6270 mAnimating = false;
6271 mLocalAnimating = false;
6272 mAnimation = anim;
6273 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6274 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6275 }
6276
6277 public void clearAnimation() {
6278 if (mAnimation != null) {
6279 mAnimating = true;
6280 mLocalAnimating = false;
6281 mAnimation = null;
6282 }
6283 }
Romain Guy06882f82009-06-10 13:36:04 -07006284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 Surface createSurfaceLocked() {
6286 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006287 mReportDestroySurface = false;
6288 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006289 mDrawPending = true;
6290 mCommitDrawPending = false;
6291 mReadyToShow = false;
6292 if (mAppToken != null) {
6293 mAppToken.allDrawn = false;
6294 }
6295
6296 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006297 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006298 flags |= Surface.PUSH_BUFFERS;
6299 }
6300
6301 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6302 flags |= Surface.SECURE;
6303 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006304 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305 TAG, "Creating surface in session "
6306 + mSession.mSurfaceSession + " window " + this
6307 + " w=" + mFrame.width()
6308 + " h=" + mFrame.height() + " format="
6309 + mAttrs.format + " flags=" + flags);
6310
6311 int w = mFrame.width();
6312 int h = mFrame.height();
6313 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6314 // for a scaled surface, we always want the requested
6315 // size.
6316 w = mRequestedWidth;
6317 h = mRequestedHeight;
6318 }
6319
Romain Guy9825ec62009-10-01 00:58:09 -07006320 // Something is wrong and SurfaceFlinger will not like this,
6321 // try to revert to sane values
6322 if (w <= 0) w = 1;
6323 if (h <= 0) h = 1;
6324
Dianne Hackborn16064f92010-03-25 00:47:24 -07006325 mSurfaceShown = false;
6326 mSurfaceLayer = 0;
6327 mSurfaceAlpha = 1;
6328 mSurfaceX = 0;
6329 mSurfaceY = 0;
6330 mSurfaceW = w;
6331 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006332 try {
6333 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006334 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006335 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006337 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006338 + mSurface + " IN SESSION "
6339 + mSession.mSurfaceSession
6340 + ": pid=" + mSession.mPid + " format="
6341 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006342 + Integer.toHexString(flags)
6343 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006344 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006345 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006346 reclaimSomeSurfaceMemoryLocked(this, "create");
6347 return null;
6348 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006349 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006350 return null;
6351 }
Romain Guy06882f82009-06-10 13:36:04 -07006352
Joe Onorato8a9b2202010-02-26 18:56:32 -08006353 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 TAG, "Got surface: " + mSurface
6355 + ", set left=" + mFrame.left + " top=" + mFrame.top
6356 + ", animLayer=" + mAnimLayer);
6357 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006358 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006359 if (SHOW_TRANSACTIONS) logSurface(this,
6360 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6361 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6362 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006363 }
6364 Surface.openTransaction();
6365 try {
6366 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006367 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006368 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006369 mSurface.setPosition(mSurfaceX, mSurfaceY);
6370 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006371 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006372 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006373 mSurface.hide();
6374 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006375 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 mSurface.setFlags(Surface.SURFACE_DITHER,
6377 Surface.SURFACE_DITHER);
6378 }
6379 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006380 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006381 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6382 }
6383 mLastHidden = true;
6384 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006385 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 Surface.closeTransaction();
6387 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006388 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 TAG, "Created surface " + this);
6390 }
6391 return mSurface;
6392 }
Romain Guy06882f82009-06-10 13:36:04 -07006393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006395 if (mAppToken != null && this == mAppToken.startingWindow) {
6396 mAppToken.startingDisplayed = false;
6397 }
Romain Guy06882f82009-06-10 13:36:04 -07006398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006399 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006400 mDrawPending = false;
6401 mCommitDrawPending = false;
6402 mReadyToShow = false;
6403
6404 int i = mChildWindows.size();
6405 while (i > 0) {
6406 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006407 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006408 c.mAttachedHidden = true;
6409 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006410
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006411 if (mReportDestroySurface) {
6412 mReportDestroySurface = false;
6413 mSurfacePendingDestroy = true;
6414 try {
6415 mClient.dispatchGetNewSurface();
6416 // We'll really destroy on the next time around.
6417 return;
6418 } catch (RemoteException e) {
6419 }
6420 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006422 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006423 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006424 RuntimeException e = null;
6425 if (!HIDE_STACK_CRAWLS) {
6426 e = new RuntimeException();
6427 e.fillInStackTrace();
6428 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006429 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006430 + mSurface + ", session " + mSession, e);
6431 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006433 RuntimeException e = null;
6434 if (!HIDE_STACK_CRAWLS) {
6435 e = new RuntimeException();
6436 e.fillInStackTrace();
6437 }
6438 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006440 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006442 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 + " surface " + mSurface + " session " + mSession
6444 + ": " + e.toString());
6445 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006446
Dianne Hackborn16064f92010-03-25 00:47:24 -07006447 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006448 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006449 }
6450 }
6451
6452 boolean finishDrawingLocked() {
6453 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006454 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006455 TAG, "finishDrawingLocked: " + mSurface);
6456 mCommitDrawPending = true;
6457 mDrawPending = false;
6458 return true;
6459 }
6460 return false;
6461 }
6462
6463 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006464 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006465 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006467 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006468 }
6469 mCommitDrawPending = false;
6470 mReadyToShow = true;
6471 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6472 final AppWindowToken atoken = mAppToken;
6473 if (atoken == null || atoken.allDrawn || starting) {
6474 performShowLocked();
6475 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006476 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006477 }
6478
6479 // This must be called while inside a transaction.
6480 boolean performShowLocked() {
6481 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006482 RuntimeException e = null;
6483 if (!HIDE_STACK_CRAWLS) {
6484 e = new RuntimeException();
6485 e.fillInStackTrace();
6486 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006487 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6489 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6490 }
6491 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006492 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6493 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006494 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006495 + " during animation: policyVis=" + mPolicyVisibility
6496 + " attHidden=" + mAttachedHidden
6497 + " tok.hiddenRequested="
6498 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006499 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006500 + (mAppToken != null ? mAppToken.hidden : false)
6501 + " animating=" + mAnimating
6502 + " tok animating="
6503 + (mAppToken != null ? mAppToken.animating : false));
6504 if (!showSurfaceRobustlyLocked(this)) {
6505 return false;
6506 }
6507 mLastAlpha = -1;
6508 mHasDrawn = true;
6509 mLastHidden = false;
6510 mReadyToShow = false;
6511 enableScreenIfNeededLocked();
6512
6513 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 int i = mChildWindows.size();
6516 while (i > 0) {
6517 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006518 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006519 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006520 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006521 if (c.mSurface != null) {
6522 c.performShowLocked();
6523 // It hadn't been shown, which means layout not
6524 // performed on it, so now we want to make sure to
6525 // do a layout. If called from within the transaction
6526 // loop, this will cause it to restart with a new
6527 // layout.
6528 mLayoutNeeded = true;
6529 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006530 }
6531 }
Romain Guy06882f82009-06-10 13:36:04 -07006532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 if (mAttrs.type != TYPE_APPLICATION_STARTING
6534 && mAppToken != null) {
6535 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006536
Dianne Hackborn248b1882009-09-16 16:46:44 -07006537 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006538 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006539 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006540 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006541 // If this initial window is animating, stop it -- we
6542 // will do an animation to reveal it from behind the
6543 // starting window, so there is no need for it to also
6544 // be doing its own stuff.
6545 if (mAnimation != null) {
6546 mAnimation = null;
6547 // Make sure we clean up the animation.
6548 mAnimating = true;
6549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006550 mFinishedStarting.add(mAppToken);
6551 mH.sendEmptyMessage(H.FINISHED_STARTING);
6552 }
6553 mAppToken.updateReportedVisibilityLocked();
6554 }
6555 }
6556 return true;
6557 }
Romain Guy06882f82009-06-10 13:36:04 -07006558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006559 // This must be called while inside a transaction. Returns true if
6560 // there is more animation to run.
6561 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006562 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006565 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6566 mHasTransformation = true;
6567 mHasLocalTransformation = true;
6568 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006569 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 TAG, "Starting animation in " + this +
6571 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6572 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6573 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6574 mAnimation.setStartTime(currentTime);
6575 mLocalAnimating = true;
6576 mAnimating = true;
6577 }
6578 mTransformation.clear();
6579 final boolean more = mAnimation.getTransformation(
6580 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006581 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006582 TAG, "Stepped animation in " + this +
6583 ": more=" + more + ", xform=" + mTransformation);
6584 if (more) {
6585 // we're not done!
6586 return true;
6587 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006588 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006589 TAG, "Finished animation in " + this +
6590 " @ " + currentTime);
6591 mAnimation = null;
6592 //WindowManagerService.this.dump();
6593 }
6594 mHasLocalTransformation = false;
6595 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006596 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 // When our app token is animating, we kind-of pretend like
6598 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6599 // part of this check means that we will only do this if
6600 // our window is not currently exiting, or it is not
6601 // locally animating itself. The idea being that one that
6602 // is exiting and doing a local animation should be removed
6603 // once that animation is done.
6604 mAnimating = true;
6605 mHasTransformation = true;
6606 mTransformation.clear();
6607 return false;
6608 } else if (mHasTransformation) {
6609 // Little trick to get through the path below to act like
6610 // we have finished an animation.
6611 mAnimating = true;
6612 } else if (isAnimating()) {
6613 mAnimating = true;
6614 }
6615 } else if (mAnimation != null) {
6616 // If the display is frozen, and there is a pending animation,
6617 // clear it and make sure we run the cleanup code.
6618 mAnimating = true;
6619 mLocalAnimating = true;
6620 mAnimation = null;
6621 }
Romain Guy06882f82009-06-10 13:36:04 -07006622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006623 if (!mAnimating && !mLocalAnimating) {
6624 return false;
6625 }
6626
Joe Onorato8a9b2202010-02-26 18:56:32 -08006627 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006628 TAG, "Animation done in " + this + ": exiting=" + mExiting
6629 + ", reportedVisible="
6630 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006632 mAnimating = false;
6633 mLocalAnimating = false;
6634 mAnimation = null;
6635 mAnimLayer = mLayer;
6636 if (mIsImWindow) {
6637 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006638 } else if (mIsWallpaper) {
6639 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006641 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642 + " anim layer: " + mAnimLayer);
6643 mHasTransformation = false;
6644 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006645 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6646 if (DEBUG_VISIBILITY) {
6647 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6648 + mPolicyVisibilityAfterAnim);
6649 }
6650 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6651 if (!mPolicyVisibility) {
6652 if (mCurrentFocus == this) {
6653 mFocusMayChange = true;
6654 }
6655 // Window is no longer visible -- make sure if we were waiting
6656 // for it to be displayed before enabling the display, that
6657 // we allow the display to be enabled now.
6658 enableScreenIfNeededLocked();
6659 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006661 mTransformation.clear();
6662 if (mHasDrawn
6663 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6664 && mAppToken != null
6665 && mAppToken.firstWindowDrawn
6666 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006667 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006668 + mToken + ": first real window done animating");
6669 mFinishedStarting.add(mAppToken);
6670 mH.sendEmptyMessage(H.FINISHED_STARTING);
6671 }
Romain Guy06882f82009-06-10 13:36:04 -07006672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006673 finishExit();
6674
6675 if (mAppToken != null) {
6676 mAppToken.updateReportedVisibilityLocked();
6677 }
6678
6679 return false;
6680 }
6681
6682 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006683 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006684 TAG, "finishExit in " + this
6685 + ": exiting=" + mExiting
6686 + " remove=" + mRemoveOnExit
6687 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006689 final int N = mChildWindows.size();
6690 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006691 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006692 }
Romain Guy06882f82009-06-10 13:36:04 -07006693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006694 if (!mExiting) {
6695 return;
6696 }
Romain Guy06882f82009-06-10 13:36:04 -07006697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006698 if (isWindowAnimating()) {
6699 return;
6700 }
6701
Joe Onorato8a9b2202010-02-26 18:56:32 -08006702 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 TAG, "Exit animation finished in " + this
6704 + ": remove=" + mRemoveOnExit);
6705 if (mSurface != null) {
6706 mDestroySurface.add(this);
6707 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006708 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006709 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006710 try {
6711 mSurface.hide();
6712 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006713 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006714 }
6715 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 }
6717 mExiting = false;
6718 if (mRemoveOnExit) {
6719 mPendingRemove.add(this);
6720 mRemoveOnExit = false;
6721 }
6722 }
Romain Guy06882f82009-06-10 13:36:04 -07006723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006724 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6725 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6726 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6727 if (dtdx < -.000001f || dtdx > .000001f) return false;
6728 if (dsdy < -.000001f || dsdy > .000001f) return false;
6729 return true;
6730 }
Romain Guy06882f82009-06-10 13:36:04 -07006731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 void computeShownFrameLocked() {
6733 final boolean selfTransformation = mHasLocalTransformation;
6734 Transformation attachedTransformation =
6735 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6736 ? mAttachedWindow.mTransformation : null;
6737 Transformation appTransformation =
6738 (mAppToken != null && mAppToken.hasTransformation)
6739 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006740
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006741 // Wallpapers are animated based on the "real" window they
6742 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006743 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006744 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006745 if (mWallpaperTarget.mHasLocalTransformation &&
6746 mWallpaperTarget.mAnimation != null &&
6747 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006748 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006749 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006750 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006751 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006752 }
6753 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006754 mWallpaperTarget.mAppToken.hasTransformation &&
6755 mWallpaperTarget.mAppToken.animation != null &&
6756 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006757 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006758 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006759 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006760 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006761 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006762 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006764 if (selfTransformation || attachedTransformation != null
6765 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006766 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 final Rect frame = mFrame;
6768 final float tmpFloats[] = mTmpFloats;
6769 final Matrix tmpMatrix = mTmpMatrix;
6770
6771 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006772 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006774 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006775 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006776 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006777 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006778 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006779 }
6780 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006781 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006782 }
6783
6784 // "convert" it into SurfaceFlinger's format
6785 // (a 2x2 matrix + an offset)
6786 // Here we must not transform the position of the surface
6787 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006788 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006790 tmpMatrix.getValues(tmpFloats);
6791 mDsDx = tmpFloats[Matrix.MSCALE_X];
6792 mDtDx = tmpFloats[Matrix.MSKEW_X];
6793 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6794 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006795 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6796 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 int w = frame.width();
6798 int h = frame.height();
6799 mShownFrame.set(x, y, x+w, y+h);
6800
6801 // Now set the alpha... but because our current hardware
6802 // can't do alpha transformation on a non-opaque surface,
6803 // turn it off if we are running an animation that is also
6804 // transforming since it is more important to have that
6805 // animation be smooth.
6806 mShownAlpha = mAlpha;
6807 if (!mLimitedAlphaCompositing
6808 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6809 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6810 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006811 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 if (selfTransformation) {
6813 mShownAlpha *= mTransformation.getAlpha();
6814 }
6815 if (attachedTransformation != null) {
6816 mShownAlpha *= attachedTransformation.getAlpha();
6817 }
6818 if (appTransformation != null) {
6819 mShownAlpha *= appTransformation.getAlpha();
6820 }
6821 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006822 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 }
Romain Guy06882f82009-06-10 13:36:04 -07006824
Joe Onorato8a9b2202010-02-26 18:56:32 -08006825 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006826 TAG, "Continuing animation in " + this +
6827 ": " + mShownFrame +
6828 ", alpha=" + mTransformation.getAlpha());
6829 return;
6830 }
Romain Guy06882f82009-06-10 13:36:04 -07006831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006832 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006833 if (mXOffset != 0 || mYOffset != 0) {
6834 mShownFrame.offset(mXOffset, mYOffset);
6835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 mShownAlpha = mAlpha;
6837 mDsDx = 1;
6838 mDtDx = 0;
6839 mDsDy = 0;
6840 mDtDy = 1;
6841 }
Romain Guy06882f82009-06-10 13:36:04 -07006842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 /**
6844 * Is this window visible? It is not visible if there is no
6845 * surface, or we are in the process of running an exit animation
6846 * that will remove the surface, or its app token has been hidden.
6847 */
6848 public boolean isVisibleLw() {
6849 final AppWindowToken atoken = mAppToken;
6850 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6851 && (atoken == null || !atoken.hiddenRequested)
6852 && !mExiting && !mDestroying;
6853 }
6854
6855 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006856 * Like {@link #isVisibleLw}, but also counts a window that is currently
6857 * "hidden" behind the keyguard as visible. This allows us to apply
6858 * things like window flags that impact the keyguard.
6859 * XXX I am starting to think we need to have ANOTHER visibility flag
6860 * for this "hidden behind keyguard" state rather than overloading
6861 * mPolicyVisibility. Ungh.
6862 */
6863 public boolean isVisibleOrBehindKeyguardLw() {
6864 final AppWindowToken atoken = mAppToken;
6865 return mSurface != null && !mAttachedHidden
6866 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006867 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006868 && !mExiting && !mDestroying;
6869 }
6870
6871 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006872 * Is this window visible, ignoring its app token? It is not visible
6873 * if there is no surface, or we are in the process of running an exit animation
6874 * that will remove the surface.
6875 */
6876 public boolean isWinVisibleLw() {
6877 final AppWindowToken atoken = mAppToken;
6878 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6879 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6880 && !mExiting && !mDestroying;
6881 }
6882
6883 /**
6884 * The same as isVisible(), but follows the current hidden state of
6885 * the associated app token, not the pending requested hidden state.
6886 */
6887 boolean isVisibleNow() {
6888 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006889 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006890 }
6891
6892 /**
6893 * Same as isVisible(), but we also count it as visible between the
6894 * call to IWindowSession.add() and the first relayout().
6895 */
6896 boolean isVisibleOrAdding() {
6897 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006898 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006899 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6900 && mPolicyVisibility && !mAttachedHidden
6901 && (atoken == null || !atoken.hiddenRequested)
6902 && !mExiting && !mDestroying;
6903 }
6904
6905 /**
6906 * Is this window currently on-screen? It is on-screen either if it
6907 * is visible or it is currently running an animation before no longer
6908 * being visible.
6909 */
6910 boolean isOnScreen() {
6911 final AppWindowToken atoken = mAppToken;
6912 if (atoken != null) {
6913 return mSurface != null && mPolicyVisibility && !mDestroying
6914 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006915 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006916 } else {
6917 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006918 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006919 }
6920 }
Romain Guy06882f82009-06-10 13:36:04 -07006921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 /**
6923 * Like isOnScreen(), but we don't return true if the window is part
6924 * of a transition that has not yet been started.
6925 */
6926 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006927 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006928 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006929 return false;
6930 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006931 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006932 final boolean animating = atoken != null
6933 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006934 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006935 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6936 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006937 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006938 }
6939
6940 /** Is the window or its container currently animating? */
6941 boolean isAnimating() {
6942 final WindowState attached = mAttachedWindow;
6943 final AppWindowToken atoken = mAppToken;
6944 return mAnimation != null
6945 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006946 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 (atoken.animation != null
6948 || atoken.inPendingTransaction));
6949 }
6950
6951 /** Is this window currently animating? */
6952 boolean isWindowAnimating() {
6953 return mAnimation != null;
6954 }
6955
6956 /**
6957 * Like isOnScreen, but returns false if the surface hasn't yet
6958 * been drawn.
6959 */
6960 public boolean isDisplayedLw() {
6961 final AppWindowToken atoken = mAppToken;
6962 return mSurface != null && mPolicyVisibility && !mDestroying
6963 && !mDrawPending && !mCommitDrawPending
6964 && ((!mAttachedHidden &&
6965 (atoken == null || !atoken.hiddenRequested))
6966 || mAnimating);
6967 }
6968
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006969 /**
6970 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006971 * complete UI in to. Note that this returns true if the orientation
6972 * is changing even if the window hasn't redrawn because we don't want
6973 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006974 */
6975 public boolean isDrawnLw() {
6976 final AppWindowToken atoken = mAppToken;
6977 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006978 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006979 }
6980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6982 boolean shownFrame, boolean onlyOpaque) {
6983 if (mSurface == null) {
6984 return false;
6985 }
6986 if (mAppToken != null && !mAppToken.appFullscreen) {
6987 return false;
6988 }
6989 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6990 return false;
6991 }
6992 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006993
6994 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6995 return frame.left <= mCompatibleScreenFrame.left &&
6996 frame.top <= mCompatibleScreenFrame.top &&
6997 frame.right >= mCompatibleScreenFrame.right &&
6998 frame.bottom >= mCompatibleScreenFrame.bottom;
6999 } else {
7000 return frame.left <= 0 && frame.top <= 0
7001 && frame.right >= screenWidth
7002 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007004 }
Romain Guy06882f82009-06-10 13:36:04 -07007005
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007006 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007007 * Return true if the window is opaque and fully drawn. This indicates
7008 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007009 */
7010 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007011 return (mAttrs.format == PixelFormat.OPAQUE
7012 || mAttrs.type == TYPE_WALLPAPER)
7013 && mSurface != null && mAnimation == null
7014 && (mAppToken == null || mAppToken.animation == null)
7015 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007016 }
7017
7018 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7019 return
7020 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007021 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7022 // only if it's visible
7023 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007024 // and only if the application fills the compatible screen
7025 mFrame.left <= mCompatibleScreenFrame.left &&
7026 mFrame.top <= mCompatibleScreenFrame.top &&
7027 mFrame.right >= mCompatibleScreenFrame.right &&
7028 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007029 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007030 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007031 }
7032
7033 boolean isFullscreen(int screenWidth, int screenHeight) {
7034 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007035 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007036 }
7037
7038 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007039 disposeInputChannel();
7040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007041 if (mAttachedWindow != null) {
7042 mAttachedWindow.mChildWindows.remove(this);
7043 }
7044 destroySurfaceLocked();
7045 mSession.windowRemovedLocked();
7046 try {
7047 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7048 } catch (RuntimeException e) {
7049 // Ignore if it has already been removed (usually because
7050 // we are doing this as part of processing a death note.)
7051 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007052 }
7053
7054 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007055 if (mInputChannel != null) {
7056 mInputManager.unregisterInputChannel(mInputChannel);
7057
7058 mInputChannel.dispose();
7059 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 }
7062
7063 private class DeathRecipient implements IBinder.DeathRecipient {
7064 public void binderDied() {
7065 try {
7066 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007067 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007068 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007069 if (win != null) {
7070 removeWindowLocked(mSession, win);
7071 }
7072 }
7073 } catch (IllegalArgumentException ex) {
7074 // This will happen if the window has already been
7075 // removed.
7076 }
7077 }
7078 }
7079
7080 /** Returns true if this window desires key events. */
7081 public final boolean canReceiveKeys() {
7082 return isVisibleOrAdding()
7083 && (mViewVisibility == View.VISIBLE)
7084 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7085 }
7086
7087 public boolean hasDrawnLw() {
7088 return mHasDrawn;
7089 }
7090
7091 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007092 return showLw(doAnimation, true);
7093 }
7094
7095 boolean showLw(boolean doAnimation, boolean requestAnim) {
7096 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7097 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007098 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007099 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007100 if (doAnimation) {
7101 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7102 + mPolicyVisibility + " mAnimation=" + mAnimation);
7103 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7104 doAnimation = false;
7105 } else if (mPolicyVisibility && mAnimation == null) {
7106 // Check for the case where we are currently visible and
7107 // not animating; we do not want to do animation at such a
7108 // point to become visible when we already are.
7109 doAnimation = false;
7110 }
7111 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007112 mPolicyVisibility = true;
7113 mPolicyVisibilityAfterAnim = true;
7114 if (doAnimation) {
7115 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7116 }
7117 if (requestAnim) {
7118 requestAnimationLocked(0);
7119 }
7120 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007121 }
7122
7123 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007124 return hideLw(doAnimation, true);
7125 }
7126
7127 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007128 if (doAnimation) {
7129 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7130 doAnimation = false;
7131 }
7132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007133 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7134 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007135 if (!current) {
7136 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007137 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007138 if (doAnimation) {
7139 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7140 if (mAnimation == null) {
7141 doAnimation = false;
7142 }
7143 }
7144 if (doAnimation) {
7145 mPolicyVisibilityAfterAnim = false;
7146 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007147 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007148 mPolicyVisibilityAfterAnim = false;
7149 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007150 // Window is no longer visible -- make sure if we were waiting
7151 // for it to be displayed before enabling the display, that
7152 // we allow the display to be enabled now.
7153 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007154 if (mCurrentFocus == this) {
7155 mFocusMayChange = true;
7156 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007157 }
7158 if (requestAnim) {
7159 requestAnimationLocked(0);
7160 }
7161 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 }
7163
7164 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007165 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7166 pw.print(" mClient="); pw.println(mClient.asBinder());
7167 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7168 if (mAttachedWindow != null || mLayoutAttached) {
7169 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7170 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7171 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007172 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7173 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7174 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007175 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7176 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007177 }
7178 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7179 pw.print(" mSubLayer="); pw.print(mSubLayer);
7180 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7181 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7182 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7183 pw.print("="); pw.print(mAnimLayer);
7184 pw.print(" mLastLayer="); pw.println(mLastLayer);
7185 if (mSurface != null) {
7186 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007187 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7188 pw.print(" layer="); pw.print(mSurfaceLayer);
7189 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7190 pw.print(" rect=("); pw.print(mSurfaceX);
7191 pw.print(","); pw.print(mSurfaceY);
7192 pw.print(") "); pw.print(mSurfaceW);
7193 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007194 }
7195 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7196 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7197 if (mAppToken != null) {
7198 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7199 }
7200 if (mTargetAppToken != null) {
7201 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7202 }
7203 pw.print(prefix); pw.print("mViewVisibility=0x");
7204 pw.print(Integer.toHexString(mViewVisibility));
7205 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007206 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7207 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007208 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7209 pw.print(prefix); pw.print("mPolicyVisibility=");
7210 pw.print(mPolicyVisibility);
7211 pw.print(" mPolicyVisibilityAfterAnim=");
7212 pw.print(mPolicyVisibilityAfterAnim);
7213 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7214 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007215 if (!mRelayoutCalled) {
7216 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7217 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007218 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007219 pw.print(" h="); pw.print(mRequestedHeight);
7220 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007221 if (mXOffset != 0 || mYOffset != 0) {
7222 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7223 pw.print(" y="); pw.println(mYOffset);
7224 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007225 pw.print(prefix); pw.print("mGivenContentInsets=");
7226 mGivenContentInsets.printShortString(pw);
7227 pw.print(" mGivenVisibleInsets=");
7228 mGivenVisibleInsets.printShortString(pw);
7229 pw.println();
7230 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7231 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7232 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7233 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007234 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007235 pw.print(prefix); pw.print("mShownFrame=");
7236 mShownFrame.printShortString(pw);
7237 pw.print(" last="); mLastShownFrame.printShortString(pw);
7238 pw.println();
7239 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7240 pw.print(" last="); mLastFrame.printShortString(pw);
7241 pw.println();
7242 pw.print(prefix); pw.print("mContainingFrame=");
7243 mContainingFrame.printShortString(pw);
7244 pw.print(" mDisplayFrame=");
7245 mDisplayFrame.printShortString(pw);
7246 pw.println();
7247 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7248 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7249 pw.println();
7250 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7251 pw.print(" last="); mLastContentInsets.printShortString(pw);
7252 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7253 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7254 pw.println();
7255 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7256 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7257 pw.print(" mAlpha="); pw.print(mAlpha);
7258 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7259 }
7260 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7261 || mAnimation != null) {
7262 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7263 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7264 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7265 pw.print(" mAnimation="); pw.println(mAnimation);
7266 }
7267 if (mHasTransformation || mHasLocalTransformation) {
7268 pw.print(prefix); pw.print("XForm: has=");
7269 pw.print(mHasTransformation);
7270 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7271 pw.print(" "); mTransformation.printShortString(pw);
7272 pw.println();
7273 }
7274 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7275 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7276 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7277 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7278 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7279 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7280 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7281 pw.print(" mDestroying="); pw.print(mDestroying);
7282 pw.print(" mRemoved="); pw.println(mRemoved);
7283 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007284 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007285 pw.print(prefix); pw.print("mOrientationChanging=");
7286 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007287 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7288 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007289 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007290 if (mHScale != 1 || mVScale != 1) {
7291 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7292 pw.print(" mVScale="); pw.println(mVScale);
7293 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007294 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007295 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7296 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7297 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007298 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7299 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7300 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7301 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007302 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007303
7304 String makeInputChannelName() {
7305 return Integer.toHexString(System.identityHashCode(this))
7306 + " " + mAttrs.getTitle();
7307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007308
7309 @Override
7310 public String toString() {
7311 return "Window{"
7312 + Integer.toHexString(System.identityHashCode(this))
7313 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7314 }
7315 }
Romain Guy06882f82009-06-10 13:36:04 -07007316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 // -------------------------------------------------------------
7318 // Window Token State
7319 // -------------------------------------------------------------
7320
7321 class WindowToken {
7322 // The actual token.
7323 final IBinder token;
7324
7325 // The type of window this token is for, as per WindowManager.LayoutParams.
7326 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007328 // Set if this token was explicitly added by a client, so should
7329 // not be removed when all windows are removed.
7330 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007331
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007332 // For printing.
7333 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007335 // If this is an AppWindowToken, this is non-null.
7336 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 // All of the windows associated with this token.
7339 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7340
7341 // Is key dispatching paused for this token?
7342 boolean paused = false;
7343
7344 // Should this token's windows be hidden?
7345 boolean hidden;
7346
7347 // Temporary for finding which tokens no longer have visible windows.
7348 boolean hasVisible;
7349
Dianne Hackborna8f60182009-09-01 19:01:50 -07007350 // Set to true when this token is in a pending transaction where it
7351 // will be shown.
7352 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007353
Dianne Hackborna8f60182009-09-01 19:01:50 -07007354 // Set to true when this token is in a pending transaction where it
7355 // will be hidden.
7356 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007357
Dianne Hackborna8f60182009-09-01 19:01:50 -07007358 // Set to true when this token is in a pending transaction where its
7359 // windows will be put to the bottom of the list.
7360 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007361
Dianne Hackborna8f60182009-09-01 19:01:50 -07007362 // Set to true when this token is in a pending transaction where its
7363 // windows will be put to the top of the list.
7364 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007366 WindowToken(IBinder _token, int type, boolean _explicit) {
7367 token = _token;
7368 windowType = type;
7369 explicit = _explicit;
7370 }
7371
7372 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007373 pw.print(prefix); pw.print("token="); pw.println(token);
7374 pw.print(prefix); pw.print("windows="); pw.println(windows);
7375 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7376 pw.print(" hidden="); pw.print(hidden);
7377 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007378 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7379 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7380 pw.print(" waitingToHide="); pw.print(waitingToHide);
7381 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7382 pw.print(" sendingToTop="); pw.println(sendingToTop);
7383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007384 }
7385
7386 @Override
7387 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007388 if (stringName == null) {
7389 StringBuilder sb = new StringBuilder();
7390 sb.append("WindowToken{");
7391 sb.append(Integer.toHexString(System.identityHashCode(this)));
7392 sb.append(" token="); sb.append(token); sb.append('}');
7393 stringName = sb.toString();
7394 }
7395 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007396 }
7397 };
7398
7399 class AppWindowToken extends WindowToken {
7400 // Non-null only for application tokens.
7401 final IApplicationToken appToken;
7402
7403 // All of the windows and child windows that are included in this
7404 // application token. Note this list is NOT sorted!
7405 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7406
7407 int groupId = -1;
7408 boolean appFullscreen;
7409 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007410
7411 // The input dispatching timeout for this application token in nanoseconds.
7412 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007414 // These are used for determining when all windows associated with
7415 // an activity have been drawn, so they can be made visible together
7416 // at the same time.
7417 int lastTransactionSequence = mTransactionSequence-1;
7418 int numInterestingWindows;
7419 int numDrawnWindows;
7420 boolean inPendingTransaction;
7421 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007423 // Is this token going to be hidden in a little while? If so, it
7424 // won't be taken into account for setting the screen orientation.
7425 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 // Is this window's surface needed? This is almost like hidden, except
7428 // it will sometimes be true a little earlier: when the token has
7429 // been shown, but is still waiting for its app transition to execute
7430 // before making its windows shown.
7431 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 // Have we told the window clients to hide themselves?
7434 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 // Last visibility state we reported to the app token.
7437 boolean reportedVisible;
7438
7439 // Set to true when the token has been removed from the window mgr.
7440 boolean removed;
7441
7442 // Have we been asked to have this token keep the screen frozen?
7443 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 boolean animating;
7446 Animation animation;
7447 boolean hasTransformation;
7448 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 // Offset to the window of all layers in the token, for use by
7451 // AppWindowToken animations.
7452 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 // Information about an application starting window if displayed.
7455 StartingData startingData;
7456 WindowState startingWindow;
7457 View startingView;
7458 boolean startingDisplayed;
7459 boolean startingMoved;
7460 boolean firstWindowDrawn;
7461
7462 AppWindowToken(IApplicationToken _token) {
7463 super(_token.asBinder(),
7464 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7465 appWindowToken = this;
7466 appToken = _token;
7467 }
Romain Guy06882f82009-06-10 13:36:04 -07007468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007469 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007470 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007471 TAG, "Setting animation in " + this + ": " + anim);
7472 animation = anim;
7473 animating = false;
7474 anim.restrictDuration(MAX_ANIMATION_DURATION);
7475 anim.scaleCurrentDuration(mTransitionAnimationScale);
7476 int zorder = anim.getZAdjustment();
7477 int adj = 0;
7478 if (zorder == Animation.ZORDER_TOP) {
7479 adj = TYPE_LAYER_OFFSET;
7480 } else if (zorder == Animation.ZORDER_BOTTOM) {
7481 adj = -TYPE_LAYER_OFFSET;
7482 }
Romain Guy06882f82009-06-10 13:36:04 -07007483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007484 if (animLayerAdjustment != adj) {
7485 animLayerAdjustment = adj;
7486 updateLayers();
7487 }
7488 }
Romain Guy06882f82009-06-10 13:36:04 -07007489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 public void setDummyAnimation() {
7491 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007492 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 TAG, "Setting dummy animation in " + this);
7494 animation = sDummyAnimation;
7495 }
7496 }
7497
7498 public void clearAnimation() {
7499 if (animation != null) {
7500 animation = null;
7501 animating = true;
7502 }
7503 }
Romain Guy06882f82009-06-10 13:36:04 -07007504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 void updateLayers() {
7506 final int N = allAppWindows.size();
7507 final int adj = animLayerAdjustment;
7508 for (int i=0; i<N; i++) {
7509 WindowState w = allAppWindows.get(i);
7510 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007511 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 + w.mAnimLayer);
7513 if (w == mInputMethodTarget) {
7514 setInputMethodAnimLayerAdjustment(adj);
7515 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007516 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007517 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007518 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007519 }
7520 }
Romain Guy06882f82009-06-10 13:36:04 -07007521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 void sendAppVisibilityToClients() {
7523 final int N = allAppWindows.size();
7524 for (int i=0; i<N; i++) {
7525 WindowState win = allAppWindows.get(i);
7526 if (win == startingWindow && clientHidden) {
7527 // Don't hide the starting window.
7528 continue;
7529 }
7530 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007531 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 "Setting visibility of " + win + ": " + (!clientHidden));
7533 win.mClient.dispatchAppVisibility(!clientHidden);
7534 } catch (RemoteException e) {
7535 }
7536 }
7537 }
Romain Guy06882f82009-06-10 13:36:04 -07007538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007539 void showAllWindowsLocked() {
7540 final int NW = allAppWindows.size();
7541 for (int i=0; i<NW; i++) {
7542 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007543 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007544 "performing show on: " + w);
7545 w.performShowLocked();
7546 }
7547 }
Romain Guy06882f82009-06-10 13:36:04 -07007548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007549 // This must be called while inside a transaction.
7550 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007551 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007552 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007554 if (animation == sDummyAnimation) {
7555 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007556 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 // when it is really time to animate, this will be set to
7558 // a real animation and the next call will execute normally.
7559 return false;
7560 }
Romain Guy06882f82009-06-10 13:36:04 -07007561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7563 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007564 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 TAG, "Starting animation in " + this +
7566 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7567 + " scale=" + mTransitionAnimationScale
7568 + " allDrawn=" + allDrawn + " animating=" + animating);
7569 animation.initialize(dw, dh, dw, dh);
7570 animation.setStartTime(currentTime);
7571 animating = true;
7572 }
7573 transformation.clear();
7574 final boolean more = animation.getTransformation(
7575 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007576 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007577 TAG, "Stepped animation in " + this +
7578 ": more=" + more + ", xform=" + transformation);
7579 if (more) {
7580 // we're done!
7581 hasTransformation = true;
7582 return true;
7583 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007584 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 TAG, "Finished animation in " + this +
7586 " @ " + currentTime);
7587 animation = null;
7588 }
7589 } else if (animation != null) {
7590 // If the display is frozen, and there is a pending animation,
7591 // clear it and make sure we run the cleanup code.
7592 animating = true;
7593 animation = null;
7594 }
7595
7596 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007598 if (!animating) {
7599 return false;
7600 }
7601
7602 clearAnimation();
7603 animating = false;
7604 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7605 moveInputMethodWindowsIfNeededLocked(true);
7606 }
Romain Guy06882f82009-06-10 13:36:04 -07007607
Joe Onorato8a9b2202010-02-26 18:56:32 -08007608 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 TAG, "Animation done in " + this
7610 + ": reportedVisible=" + reportedVisible);
7611
7612 transformation.clear();
7613 if (animLayerAdjustment != 0) {
7614 animLayerAdjustment = 0;
7615 updateLayers();
7616 }
Romain Guy06882f82009-06-10 13:36:04 -07007617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 final int N = windows.size();
7619 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007620 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 }
7622 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007624 return false;
7625 }
7626
7627 void updateReportedVisibilityLocked() {
7628 if (appToken == null) {
7629 return;
7630 }
Romain Guy06882f82009-06-10 13:36:04 -07007631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 int numInteresting = 0;
7633 int numVisible = 0;
7634 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007635
Joe Onorato8a9b2202010-02-26 18:56:32 -08007636 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007637 final int N = allAppWindows.size();
7638 for (int i=0; i<N; i++) {
7639 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007640 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007641 || win.mViewVisibility != View.VISIBLE
7642 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 continue;
7644 }
7645 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007646 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007647 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007648 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007649 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007650 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 + " pv=" + win.mPolicyVisibility
7652 + " dp=" + win.mDrawPending
7653 + " cdp=" + win.mCommitDrawPending
7654 + " ah=" + win.mAttachedHidden
7655 + " th="
7656 + (win.mAppToken != null
7657 ? win.mAppToken.hiddenRequested : false)
7658 + " a=" + win.mAnimating);
7659 }
7660 }
7661 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007662 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 if (!win.isAnimating()) {
7664 numVisible++;
7665 }
7666 nowGone = false;
7667 } else if (win.isAnimating()) {
7668 nowGone = false;
7669 }
7670 }
Romain Guy06882f82009-06-10 13:36:04 -07007671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007672 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007673 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007674 + numInteresting + " visible=" + numVisible);
7675 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007676 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007677 TAG, "Visibility changed in " + this
7678 + ": vis=" + nowVisible);
7679 reportedVisible = nowVisible;
7680 Message m = mH.obtainMessage(
7681 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7682 nowVisible ? 1 : 0,
7683 nowGone ? 1 : 0,
7684 this);
7685 mH.sendMessage(m);
7686 }
7687 }
Romain Guy06882f82009-06-10 13:36:04 -07007688
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007689 WindowState findMainWindow() {
7690 int j = windows.size();
7691 while (j > 0) {
7692 j--;
7693 WindowState win = windows.get(j);
7694 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7695 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7696 return win;
7697 }
7698 }
7699 return null;
7700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 void dump(PrintWriter pw, String prefix) {
7703 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007704 if (appToken != null) {
7705 pw.print(prefix); pw.println("app=true");
7706 }
7707 if (allAppWindows.size() > 0) {
7708 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7709 }
7710 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007711 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007712 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7713 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7714 pw.print(" clientHidden="); pw.print(clientHidden);
7715 pw.print(" willBeHidden="); pw.print(willBeHidden);
7716 pw.print(" reportedVisible="); pw.println(reportedVisible);
7717 if (paused || freezingScreen) {
7718 pw.print(prefix); pw.print("paused="); pw.print(paused);
7719 pw.print(" freezingScreen="); pw.println(freezingScreen);
7720 }
7721 if (numInterestingWindows != 0 || numDrawnWindows != 0
7722 || inPendingTransaction || allDrawn) {
7723 pw.print(prefix); pw.print("numInterestingWindows=");
7724 pw.print(numInterestingWindows);
7725 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7726 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7727 pw.print(" allDrawn="); pw.println(allDrawn);
7728 }
7729 if (animating || animation != null) {
7730 pw.print(prefix); pw.print("animating="); pw.print(animating);
7731 pw.print(" animation="); pw.println(animation);
7732 }
7733 if (animLayerAdjustment != 0) {
7734 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7735 }
7736 if (hasTransformation) {
7737 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7738 pw.print(" transformation="); transformation.printShortString(pw);
7739 pw.println();
7740 }
7741 if (startingData != null || removed || firstWindowDrawn) {
7742 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7743 pw.print(" removed="); pw.print(removed);
7744 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7745 }
7746 if (startingWindow != null || startingView != null
7747 || startingDisplayed || startingMoved) {
7748 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7749 pw.print(" startingView="); pw.print(startingView);
7750 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7751 pw.print(" startingMoved"); pw.println(startingMoved);
7752 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 }
7754
7755 @Override
7756 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007757 if (stringName == null) {
7758 StringBuilder sb = new StringBuilder();
7759 sb.append("AppWindowToken{");
7760 sb.append(Integer.toHexString(System.identityHashCode(this)));
7761 sb.append(" token="); sb.append(token); sb.append('}');
7762 stringName = sb.toString();
7763 }
7764 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 }
7766 }
Romain Guy06882f82009-06-10 13:36:04 -07007767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007768 // -------------------------------------------------------------
7769 // DummyAnimation
7770 // -------------------------------------------------------------
7771
7772 // This is an animation that does nothing: it just immediately finishes
7773 // itself every time it is called. It is used as a stub animation in cases
7774 // where we want to synchronize multiple things that may be animating.
7775 static final class DummyAnimation extends Animation {
7776 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7777 return false;
7778 }
7779 }
7780 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007782 // -------------------------------------------------------------
7783 // Async Handler
7784 // -------------------------------------------------------------
7785
7786 static final class StartingData {
7787 final String pkg;
7788 final int theme;
7789 final CharSequence nonLocalizedLabel;
7790 final int labelRes;
7791 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007793 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7794 int _labelRes, int _icon) {
7795 pkg = _pkg;
7796 theme = _theme;
7797 nonLocalizedLabel = _nonLocalizedLabel;
7798 labelRes = _labelRes;
7799 icon = _icon;
7800 }
7801 }
7802
7803 private final class H extends Handler {
7804 public static final int REPORT_FOCUS_CHANGE = 2;
7805 public static final int REPORT_LOSING_FOCUS = 3;
7806 public static final int ANIMATE = 4;
7807 public static final int ADD_STARTING = 5;
7808 public static final int REMOVE_STARTING = 6;
7809 public static final int FINISHED_STARTING = 7;
7810 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007811 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7812 public static final int HOLD_SCREEN_CHANGED = 12;
7813 public static final int APP_TRANSITION_TIMEOUT = 13;
7814 public static final int PERSIST_ANIMATION_SCALE = 14;
7815 public static final int FORCE_GC = 15;
7816 public static final int ENABLE_SCREEN = 16;
7817 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007818 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007819 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007823 public H() {
7824 }
Romain Guy06882f82009-06-10 13:36:04 -07007825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 @Override
7827 public void handleMessage(Message msg) {
7828 switch (msg.what) {
7829 case REPORT_FOCUS_CHANGE: {
7830 WindowState lastFocus;
7831 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 synchronized(mWindowMap) {
7834 lastFocus = mLastFocus;
7835 newFocus = mCurrentFocus;
7836 if (lastFocus == newFocus) {
7837 // Focus is not changing, so nothing to do.
7838 return;
7839 }
7840 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007841 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 // + " to " + newFocus);
7843 if (newFocus != null && lastFocus != null
7844 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007845 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007846 mLosingFocus.add(lastFocus);
7847 lastFocus = null;
7848 }
7849 }
7850
7851 if (lastFocus != newFocus) {
7852 //System.out.println("Changing focus from " + lastFocus
7853 // + " to " + newFocus);
7854 if (newFocus != null) {
7855 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007856 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007857 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7858 } catch (RemoteException e) {
7859 // Ignore if process has died.
7860 }
7861 }
7862
7863 if (lastFocus != null) {
7864 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007865 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7867 } catch (RemoteException e) {
7868 // Ignore if process has died.
7869 }
Konstantin Lopyrev321f7fa2010-08-02 20:01:01 -07007870 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 }
7872 }
7873 } break;
7874
7875 case REPORT_LOSING_FOCUS: {
7876 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007878 synchronized(mWindowMap) {
7879 losers = mLosingFocus;
7880 mLosingFocus = new ArrayList<WindowState>();
7881 }
7882
7883 final int N = losers.size();
7884 for (int i=0; i<N; i++) {
7885 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007886 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007887 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7888 } catch (RemoteException e) {
7889 // Ignore if process has died.
7890 }
7891 }
7892 } break;
7893
7894 case ANIMATE: {
7895 synchronized(mWindowMap) {
7896 mAnimationPending = false;
7897 performLayoutAndPlaceSurfacesLocked();
7898 }
7899 } break;
7900
7901 case ADD_STARTING: {
7902 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7903 final StartingData sd = wtoken.startingData;
7904
7905 if (sd == null) {
7906 // Animation has been canceled... do nothing.
7907 return;
7908 }
Romain Guy06882f82009-06-10 13:36:04 -07007909
Joe Onorato8a9b2202010-02-26 18:56:32 -08007910 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007911 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 View view = null;
7914 try {
7915 view = mPolicy.addStartingWindow(
7916 wtoken.token, sd.pkg,
7917 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7918 sd.icon);
7919 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007920 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007921 }
7922
7923 if (view != null) {
7924 boolean abort = false;
7925
7926 synchronized(mWindowMap) {
7927 if (wtoken.removed || wtoken.startingData == null) {
7928 // If the window was successfully added, then
7929 // we need to remove it.
7930 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007931 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 "Aborted starting " + wtoken
7933 + ": removed=" + wtoken.removed
7934 + " startingData=" + wtoken.startingData);
7935 wtoken.startingWindow = null;
7936 wtoken.startingData = null;
7937 abort = true;
7938 }
7939 } else {
7940 wtoken.startingView = view;
7941 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007942 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007943 "Added starting " + wtoken
7944 + ": startingWindow="
7945 + wtoken.startingWindow + " startingView="
7946 + wtoken.startingView);
7947 }
7948
7949 if (abort) {
7950 try {
7951 mPolicy.removeStartingWindow(wtoken.token, view);
7952 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007953 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007954 }
7955 }
7956 }
7957 } break;
7958
7959 case REMOVE_STARTING: {
7960 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7961 IBinder token = null;
7962 View view = null;
7963 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007964 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007965 + wtoken + ": startingWindow="
7966 + wtoken.startingWindow + " startingView="
7967 + wtoken.startingView);
7968 if (wtoken.startingWindow != null) {
7969 view = wtoken.startingView;
7970 token = wtoken.token;
7971 wtoken.startingData = null;
7972 wtoken.startingView = null;
7973 wtoken.startingWindow = null;
7974 }
7975 }
7976 if (view != null) {
7977 try {
7978 mPolicy.removeStartingWindow(token, view);
7979 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007980 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007981 }
7982 }
7983 } break;
7984
7985 case FINISHED_STARTING: {
7986 IBinder token = null;
7987 View view = null;
7988 while (true) {
7989 synchronized (mWindowMap) {
7990 final int N = mFinishedStarting.size();
7991 if (N <= 0) {
7992 break;
7993 }
7994 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7995
Joe Onorato8a9b2202010-02-26 18:56:32 -08007996 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007997 "Finished starting " + wtoken
7998 + ": startingWindow=" + wtoken.startingWindow
7999 + " startingView=" + wtoken.startingView);
8000
8001 if (wtoken.startingWindow == null) {
8002 continue;
8003 }
8004
8005 view = wtoken.startingView;
8006 token = wtoken.token;
8007 wtoken.startingData = null;
8008 wtoken.startingView = null;
8009 wtoken.startingWindow = null;
8010 }
8011
8012 try {
8013 mPolicy.removeStartingWindow(token, view);
8014 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008015 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 }
8017 }
8018 } break;
8019
8020 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8021 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8022
8023 boolean nowVisible = msg.arg1 != 0;
8024 boolean nowGone = msg.arg2 != 0;
8025
8026 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008027 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008028 TAG, "Reporting visible in " + wtoken
8029 + " visible=" + nowVisible
8030 + " gone=" + nowGone);
8031 if (nowVisible) {
8032 wtoken.appToken.windowsVisible();
8033 } else {
8034 wtoken.appToken.windowsGone();
8035 }
8036 } catch (RemoteException ex) {
8037 }
8038 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008040 case WINDOW_FREEZE_TIMEOUT: {
8041 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008042 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 int i = mWindows.size();
8044 while (i > 0) {
8045 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008046 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 if (w.mOrientationChanging) {
8048 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008049 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 }
8051 }
8052 performLayoutAndPlaceSurfacesLocked();
8053 }
8054 break;
8055 }
Romain Guy06882f82009-06-10 13:36:04 -07008056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008057 case HOLD_SCREEN_CHANGED: {
8058 Session oldHold;
8059 Session newHold;
8060 synchronized (mWindowMap) {
8061 oldHold = mLastReportedHold;
8062 newHold = (Session)msg.obj;
8063 mLastReportedHold = newHold;
8064 }
Romain Guy06882f82009-06-10 13:36:04 -07008065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008066 if (oldHold != newHold) {
8067 try {
8068 if (oldHold != null) {
8069 mBatteryStats.noteStopWakelock(oldHold.mUid,
8070 "window",
8071 BatteryStats.WAKE_TYPE_WINDOW);
8072 }
8073 if (newHold != null) {
8074 mBatteryStats.noteStartWakelock(newHold.mUid,
8075 "window",
8076 BatteryStats.WAKE_TYPE_WINDOW);
8077 }
8078 } catch (RemoteException e) {
8079 }
8080 }
8081 break;
8082 }
Romain Guy06882f82009-06-10 13:36:04 -07008083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008084 case APP_TRANSITION_TIMEOUT: {
8085 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008086 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008087 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008088 "*** APP TRANSITION TIMEOUT");
8089 mAppTransitionReady = true;
8090 mAppTransitionTimeout = true;
8091 performLayoutAndPlaceSurfacesLocked();
8092 }
8093 }
8094 break;
8095 }
Romain Guy06882f82009-06-10 13:36:04 -07008096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008097 case PERSIST_ANIMATION_SCALE: {
8098 Settings.System.putFloat(mContext.getContentResolver(),
8099 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8100 Settings.System.putFloat(mContext.getContentResolver(),
8101 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8102 break;
8103 }
Romain Guy06882f82009-06-10 13:36:04 -07008104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008105 case FORCE_GC: {
8106 synchronized(mWindowMap) {
8107 if (mAnimationPending) {
8108 // If we are animating, don't do the gc now but
8109 // delay a bit so we don't interrupt the animation.
8110 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8111 2000);
8112 return;
8113 }
8114 // If we are currently rotating the display, it will
8115 // schedule a new message when done.
8116 if (mDisplayFrozen) {
8117 return;
8118 }
8119 mFreezeGcPending = 0;
8120 }
8121 Runtime.getRuntime().gc();
8122 break;
8123 }
Romain Guy06882f82009-06-10 13:36:04 -07008124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 case ENABLE_SCREEN: {
8126 performEnableScreen();
8127 break;
8128 }
Romain Guy06882f82009-06-10 13:36:04 -07008129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008130 case APP_FREEZE_TIMEOUT: {
8131 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008132 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 int i = mAppTokens.size();
8134 while (i > 0) {
8135 i--;
8136 AppWindowToken tok = mAppTokens.get(i);
8137 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008138 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008139 unsetAppFreezingScreenLocked(tok, true, true);
8140 }
8141 }
8142 }
8143 break;
8144 }
Romain Guy06882f82009-06-10 13:36:04 -07008145
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008146 case SEND_NEW_CONFIGURATION: {
8147 removeMessages(SEND_NEW_CONFIGURATION);
8148 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008149 break;
8150 }
Romain Guy06882f82009-06-10 13:36:04 -07008151
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008152 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008153 if (mWindowsChanged) {
8154 synchronized (mWindowMap) {
8155 mWindowsChanged = false;
8156 }
8157 notifyWindowsChanged();
8158 }
8159 break;
8160 }
8161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 }
8163 }
8164 }
8165
8166 // -------------------------------------------------------------
8167 // IWindowManager API
8168 // -------------------------------------------------------------
8169
8170 public IWindowSession openSession(IInputMethodClient client,
8171 IInputContext inputContext) {
8172 if (client == null) throw new IllegalArgumentException("null client");
8173 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008174 Session session = new Session(client, inputContext);
8175 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008176 }
8177
8178 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8179 synchronized (mWindowMap) {
8180 // The focus for the client is the window immediately below
8181 // where we would place the input method window.
8182 int idx = findDesiredInputMethodWindowIndexLocked(false);
8183 WindowState imFocus;
8184 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008185 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008186 if (imFocus != null) {
8187 if (imFocus.mSession.mClient != null &&
8188 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8189 return true;
8190 }
8191 }
8192 }
8193 }
8194 return false;
8195 }
Romain Guy06882f82009-06-10 13:36:04 -07008196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008197 // -------------------------------------------------------------
8198 // Internals
8199 // -------------------------------------------------------------
8200
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008201 final WindowState windowForClientLocked(Session session, IWindow client,
8202 boolean throwOnError) {
8203 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008204 }
Romain Guy06882f82009-06-10 13:36:04 -07008205
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008206 final WindowState windowForClientLocked(Session session, IBinder client,
8207 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008208 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008209 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008210 TAG, "Looking up client " + client + ": " + win);
8211 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008212 RuntimeException ex = new IllegalArgumentException(
8213 "Requested window " + client + " does not exist");
8214 if (throwOnError) {
8215 throw ex;
8216 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008217 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008218 return null;
8219 }
8220 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008221 RuntimeException ex = new IllegalArgumentException(
8222 "Requested window " + client + " is in session " +
8223 win.mSession + ", not " + session);
8224 if (throwOnError) {
8225 throw ex;
8226 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008227 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008228 return null;
8229 }
8230
8231 return win;
8232 }
8233
Dianne Hackborna8f60182009-09-01 19:01:50 -07008234 final void rebuildAppWindowListLocked() {
8235 int NW = mWindows.size();
8236 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008237 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008238 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008239
Dianne Hackborna8f60182009-09-01 19:01:50 -07008240 // First remove all existing app windows.
8241 i=0;
8242 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008243 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008244 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008245 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008246 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008247 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008248 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008249 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008250 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008251 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008252 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8253 && lastWallpaper == i-1) {
8254 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008255 }
8256 i++;
8257 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008258
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008259 // The wallpaper window(s) typically live at the bottom of the stack,
8260 // so skip them before adding app tokens.
8261 lastWallpaper++;
8262 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008263
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008264 // First add all of the exiting app tokens... these are no longer
8265 // in the main app list, but still have windows shown. We put them
8266 // in the back because now that the animation is over we no longer
8267 // will care about them.
8268 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008269 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008270 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008272
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008273 // And add in the still active app tokens in Z order.
8274 NT = mAppTokens.size();
8275 for (int j=0; j<NT; j++) {
8276 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008277 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008278
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008279 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008280 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008281 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008282 + " windows but added " + i);
8283 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008284 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008286 private final void assignLayersLocked() {
8287 int N = mWindows.size();
8288 int curBaseLayer = 0;
8289 int curLayer = 0;
8290 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008292 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008293 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008294 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8295 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008296 curLayer += WINDOW_LAYER_MULTIPLIER;
8297 w.mLayer = curLayer;
8298 } else {
8299 curBaseLayer = curLayer = w.mBaseLayer;
8300 w.mLayer = curLayer;
8301 }
8302 if (w.mTargetAppToken != null) {
8303 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8304 } else if (w.mAppToken != null) {
8305 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8306 } else {
8307 w.mAnimLayer = w.mLayer;
8308 }
8309 if (w.mIsImWindow) {
8310 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008311 } else if (w.mIsWallpaper) {
8312 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008314 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008315 + w.mAnimLayer);
8316 //System.out.println(
8317 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8318 }
8319 }
8320
8321 private boolean mInLayout = false;
8322 private final void performLayoutAndPlaceSurfacesLocked() {
8323 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008324 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008325 throw new RuntimeException("Recursive call!");
8326 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008327 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 return;
8329 }
8330
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008331 if (mWaitingForConfig) {
8332 // Our configuration has changed (most likely rotation), but we
8333 // don't yet have the complete configuration to report to
8334 // applications. Don't do any window layout until we have it.
8335 return;
8336 }
8337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008338 boolean recoveringMemory = false;
8339 if (mForceRemoves != null) {
8340 recoveringMemory = true;
8341 // Wait a little it for things to settle down, and off we go.
8342 for (int i=0; i<mForceRemoves.size(); i++) {
8343 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008344 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008345 removeWindowInnerLocked(ws.mSession, ws);
8346 }
8347 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008348 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008349 Object tmp = new Object();
8350 synchronized (tmp) {
8351 try {
8352 tmp.wait(250);
8353 } catch (InterruptedException e) {
8354 }
8355 }
8356 }
Romain Guy06882f82009-06-10 13:36:04 -07008357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008358 mInLayout = true;
8359 try {
8360 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008362 int i = mPendingRemove.size()-1;
8363 if (i >= 0) {
8364 while (i >= 0) {
8365 WindowState w = mPendingRemove.get(i);
8366 removeWindowInnerLocked(w.mSession, w);
8367 i--;
8368 }
8369 mPendingRemove.clear();
8370
8371 mInLayout = false;
8372 assignLayersLocked();
8373 mLayoutNeeded = true;
8374 performLayoutAndPlaceSurfacesLocked();
8375
8376 } else {
8377 mInLayout = false;
8378 if (mLayoutNeeded) {
8379 requestAnimationLocked(0);
8380 }
8381 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008382 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008383 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8384 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008386 } catch (RuntimeException e) {
8387 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008388 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008389 }
8390 }
8391
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008392 private final int performLayoutLockedInner() {
8393 if (!mLayoutNeeded) {
8394 return 0;
8395 }
8396
8397 mLayoutNeeded = false;
8398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 final int dw = mDisplay.getWidth();
8400 final int dh = mDisplay.getHeight();
8401
8402 final int N = mWindows.size();
8403 int i;
8404
Joe Onorato8a9b2202010-02-26 18:56:32 -08008405 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008406 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8407
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008408 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008409
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008410 int seq = mLayoutSeq+1;
8411 if (seq < 0) seq = 0;
8412 mLayoutSeq = seq;
8413
8414 // First perform layout of any root windows (not attached
8415 // to another window).
8416 int topAttached = -1;
8417 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008418 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008419
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008420 // Don't do layout of a window if it is not visible, or
8421 // soon won't be visible, to avoid wasting time and funky
8422 // changes while a window is animating away.
8423 final AppWindowToken atoken = win.mAppToken;
8424 final boolean gone = win.mViewVisibility == View.GONE
8425 || !win.mRelayoutCalled
8426 || win.mRootToken.hidden
8427 || (atoken != null && atoken.hiddenRequested)
8428 || win.mAttachedHidden
8429 || win.mExiting || win.mDestroying;
8430
8431 if (!win.mLayoutAttached) {
8432 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8433 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8434 + " mLayoutAttached=" + win.mLayoutAttached);
8435 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8436 + win.mViewVisibility + " mRelayoutCalled="
8437 + win.mRelayoutCalled + " hidden="
8438 + win.mRootToken.hidden + " hiddenRequested="
8439 + (atoken != null && atoken.hiddenRequested)
8440 + " mAttachedHidden=" + win.mAttachedHidden);
8441 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008442
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008443 // If this view is GONE, then skip it -- keep the current
8444 // frame, and let the caller know so they can ignore it
8445 // if they want. (We do the normal layout for INVISIBLE
8446 // windows, since that means "perform layout as normal,
8447 // just don't display").
8448 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008449 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008450 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8451 win.mLayoutSeq = seq;
8452 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8453 + win.mFrame + " mContainingFrame="
8454 + win.mContainingFrame + " mDisplayFrame="
8455 + win.mDisplayFrame);
8456 } else {
8457 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008458 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008460 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008461
8462 // Now perform layout of attached windows, which usually
8463 // depend on the position of the window they are attached to.
8464 // XXX does not deal with windows that are attached to windows
8465 // that are themselves attached.
8466 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008467 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008468
8469 // If this view is GONE, then skip it -- keep the current
8470 // frame, and let the caller know so they can ignore it
8471 // if they want. (We do the normal layout for INVISIBLE
8472 // windows, since that means "perform layout as normal,
8473 // just don't display").
8474 if (win.mLayoutAttached) {
8475 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8476 + " mHaveFrame=" + win.mHaveFrame
8477 + " mViewVisibility=" + win.mViewVisibility
8478 + " mRelayoutCalled=" + win.mRelayoutCalled);
8479 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8480 || !win.mHaveFrame) {
8481 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8482 win.mLayoutSeq = seq;
8483 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8484 + win.mFrame + " mContainingFrame="
8485 + win.mContainingFrame + " mDisplayFrame="
8486 + win.mDisplayFrame);
8487 }
8488 }
8489 }
Jeff Brown349703e2010-06-22 01:27:15 -07008490
8491 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008492 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008493
8494 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008495 }
Romain Guy06882f82009-06-10 13:36:04 -07008496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008497 private final void performLayoutAndPlaceSurfacesLockedInner(
8498 boolean recoveringMemory) {
8499 final long currentTime = SystemClock.uptimeMillis();
8500 final int dw = mDisplay.getWidth();
8501 final int dh = mDisplay.getHeight();
8502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 int i;
8504
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008505 if (mFocusMayChange) {
8506 mFocusMayChange = false;
8507 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8508 }
8509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008510 if (mFxSession == null) {
8511 mFxSession = new SurfaceSession();
8512 }
Romain Guy06882f82009-06-10 13:36:04 -07008513
Joe Onorato8a9b2202010-02-26 18:56:32 -08008514 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008515
8516 // Initialize state of exiting tokens.
8517 for (i=mExitingTokens.size()-1; i>=0; i--) {
8518 mExitingTokens.get(i).hasVisible = false;
8519 }
8520
8521 // Initialize state of exiting applications.
8522 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8523 mExitingAppTokens.get(i).hasVisible = false;
8524 }
8525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 boolean orientationChangeComplete = true;
8527 Session holdScreen = null;
8528 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008529 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530 boolean focusDisplayed = false;
8531 boolean animating = false;
8532
8533 Surface.openTransaction();
8534 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008535 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008536 int repeats = 0;
8537 int changes = 0;
8538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008540 repeats++;
8541 if (repeats > 6) {
8542 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8543 mLayoutNeeded = false;
8544 break;
8545 }
8546
8547 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8548 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8549 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8550 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8551 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8552 assignLayersLocked();
8553 mLayoutNeeded = true;
8554 }
8555 }
8556 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8557 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8558 if (updateOrientationFromAppTokensLocked()) {
8559 mLayoutNeeded = true;
8560 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8561 }
8562 }
8563 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8564 mLayoutNeeded = true;
8565 }
8566 }
8567
8568 // FIRST LOOP: Perform a layout, if needed.
8569 if (repeats < 4) {
8570 changes = performLayoutLockedInner();
8571 if (changes != 0) {
8572 continue;
8573 }
8574 } else {
8575 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8576 changes = 0;
8577 }
8578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008579 final int transactionSequence = ++mTransactionSequence;
8580
8581 // Update animations of all applications, including those
8582 // associated with exiting/removed apps
8583 boolean tokensAnimating = false;
8584 final int NAT = mAppTokens.size();
8585 for (i=0; i<NAT; i++) {
8586 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8587 tokensAnimating = true;
8588 }
8589 }
8590 final int NEAT = mExitingAppTokens.size();
8591 for (i=0; i<NEAT; i++) {
8592 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8593 tokensAnimating = true;
8594 }
8595 }
8596
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008597 // SECOND LOOP: Execute animations and update visibility of windows.
8598
Joe Onorato8a9b2202010-02-26 18:56:32 -08008599 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008600 + transactionSequence + " tokensAnimating="
8601 + tokensAnimating);
8602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008603 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008604
8605 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008606 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008607 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008608
8609 mPolicy.beginAnimationLw(dw, dh);
8610
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008611 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008613 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008614 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008615
8616 final WindowManager.LayoutParams attrs = w.mAttrs;
8617
8618 if (w.mSurface != null) {
8619 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008620 if (w.commitFinishDrawingLocked(currentTime)) {
8621 if ((w.mAttrs.flags
8622 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008623 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008624 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008625 wallpaperMayChange = true;
8626 }
8627 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008628
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008629 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8631 animating = true;
8632 //w.dump(" ");
8633 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008634 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8635 wallpaperMayChange = true;
8636 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008637
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008638 if (mPolicy.doesForceHide(w, attrs)) {
8639 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008640 if (DEBUG_VISIBILITY) Slog.v(TAG,
8641 "Animation done that could impact force hide: "
8642 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008643 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008644 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008645 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8646 forceHiding = true;
8647 }
8648 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8649 boolean changed;
8650 if (forceHiding) {
8651 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008652 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8653 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008654 } else {
8655 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008656 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8657 "Now policy shown: " + w);
8658 if (changed) {
8659 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008660 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008661 // Assume we will need to animate. If
8662 // we don't (because the wallpaper will
8663 // stay with the lock screen), then we will
8664 // clean up later.
8665 Animation a = mPolicy.createForceHideEnterAnimation();
8666 if (a != null) {
8667 w.setAnimation(a);
8668 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008669 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008670 if (mCurrentFocus == null ||
8671 mCurrentFocus.mLayer < w.mLayer) {
8672 // We are showing on to of the current
8673 // focus, so re-evaluate focus to make
8674 // sure it is correct.
8675 mFocusMayChange = true;
8676 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008677 }
8678 }
8679 if (changed && (attrs.flags
8680 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8681 wallpaperMayChange = true;
8682 }
8683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008685 mPolicy.animatingWindowLw(w, attrs);
8686 }
8687
8688 final AppWindowToken atoken = w.mAppToken;
8689 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8690 if (atoken.lastTransactionSequence != transactionSequence) {
8691 atoken.lastTransactionSequence = transactionSequence;
8692 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8693 atoken.startingDisplayed = false;
8694 }
8695 if ((w.isOnScreen() || w.mAttrs.type
8696 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8697 && !w.mExiting && !w.mDestroying) {
8698 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008699 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008700 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008701 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008702 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008703 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 + " pv=" + w.mPolicyVisibility
8705 + " dp=" + w.mDrawPending
8706 + " cdp=" + w.mCommitDrawPending
8707 + " ah=" + w.mAttachedHidden
8708 + " th=" + atoken.hiddenRequested
8709 + " a=" + w.mAnimating);
8710 }
8711 }
8712 if (w != atoken.startingWindow) {
8713 if (!atoken.freezingScreen || !w.mAppFreezing) {
8714 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008715 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008716 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008717 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008718 "tokenMayBeDrawn: " + atoken
8719 + " freezingScreen=" + atoken.freezingScreen
8720 + " mAppFreezing=" + w.mAppFreezing);
8721 tokenMayBeDrawn = true;
8722 }
8723 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008724 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008725 atoken.startingDisplayed = true;
8726 }
8727 }
8728 } else if (w.mReadyToShow) {
8729 w.performShowLocked();
8730 }
8731 }
8732
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008733 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734
8735 if (tokenMayBeDrawn) {
8736 // See if any windows have been drawn, so they (and others
8737 // associated with them) can now be shown.
8738 final int NT = mTokenList.size();
8739 for (i=0; i<NT; i++) {
8740 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8741 if (wtoken == null) {
8742 continue;
8743 }
8744 if (wtoken.freezingScreen) {
8745 int numInteresting = wtoken.numInterestingWindows;
8746 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008747 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008748 "allDrawn: " + wtoken
8749 + " interesting=" + numInteresting
8750 + " drawn=" + wtoken.numDrawnWindows);
8751 wtoken.showAllWindowsLocked();
8752 unsetAppFreezingScreenLocked(wtoken, false, true);
8753 orientationChangeComplete = true;
8754 }
8755 } else if (!wtoken.allDrawn) {
8756 int numInteresting = wtoken.numInterestingWindows;
8757 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008758 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008759 "allDrawn: " + wtoken
8760 + " interesting=" + numInteresting
8761 + " drawn=" + wtoken.numDrawnWindows);
8762 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008763 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008764
8765 // We can now show all of the drawn windows!
8766 if (!mOpeningApps.contains(wtoken)) {
8767 wtoken.showAllWindowsLocked();
8768 }
8769 }
8770 }
8771 }
8772 }
8773
8774 // If we are ready to perform an app transition, check through
8775 // all of the app tokens to be shown and see if they are ready
8776 // to go.
8777 if (mAppTransitionReady) {
8778 int NN = mOpeningApps.size();
8779 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008780 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008781 "Checking " + NN + " opening apps (frozen="
8782 + mDisplayFrozen + " timeout="
8783 + mAppTransitionTimeout + ")...");
8784 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8785 // If the display isn't frozen, wait to do anything until
8786 // all of the apps are ready. Otherwise just go because
8787 // we'll unfreeze the display when everyone is ready.
8788 for (i=0; i<NN && goodToGo; i++) {
8789 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008790 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008791 "Check opening app" + wtoken + ": allDrawn="
8792 + wtoken.allDrawn + " startingDisplayed="
8793 + wtoken.startingDisplayed);
8794 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8795 && !wtoken.startingMoved) {
8796 goodToGo = false;
8797 }
8798 }
8799 }
8800 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008801 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008802 int transit = mNextAppTransition;
8803 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008804 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008805 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008806 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008807 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008808 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008809 mAppTransitionTimeout = false;
8810 mStartingIconInTransition = false;
8811 mSkipAppTransitionAnimation = false;
8812
8813 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8814
Dianne Hackborna8f60182009-09-01 19:01:50 -07008815 // If there are applications waiting to come to the
8816 // top of the stack, now is the time to move their windows.
8817 // (Note that we don't do apps going to the bottom
8818 // here -- we want to keep their windows in the old
8819 // Z-order until the animation completes.)
8820 if (mToTopApps.size() > 0) {
8821 NN = mAppTokens.size();
8822 for (i=0; i<NN; i++) {
8823 AppWindowToken wtoken = mAppTokens.get(i);
8824 if (wtoken.sendingToTop) {
8825 wtoken.sendingToTop = false;
8826 moveAppWindowsLocked(wtoken, NN, false);
8827 }
8828 }
8829 mToTopApps.clear();
8830 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008831
Dianne Hackborn25994b42009-09-04 14:21:19 -07008832 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008833
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008834 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008835 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008836
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008837 // The top-most window will supply the layout params,
8838 // and we will determine it below.
8839 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008840 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008841 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008842
Joe Onorato8a9b2202010-02-26 18:56:32 -08008843 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008844 "New wallpaper target=" + mWallpaperTarget
8845 + ", lower target=" + mLowerWallpaperTarget
8846 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008847 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008848 // Do a first pass through the tokens for two
8849 // things:
8850 // (1) Determine if both the closing and opening
8851 // app token sets are wallpaper targets, in which
8852 // case special animations are needed
8853 // (since the wallpaper needs to stay static
8854 // behind them).
8855 // (2) Find the layout params of the top-most
8856 // application window in the tokens, which is
8857 // what will control the animation theme.
8858 final int NC = mClosingApps.size();
8859 NN = NC + mOpeningApps.size();
8860 for (i=0; i<NN; i++) {
8861 AppWindowToken wtoken;
8862 int mode;
8863 if (i < NC) {
8864 wtoken = mClosingApps.get(i);
8865 mode = 1;
8866 } else {
8867 wtoken = mOpeningApps.get(i-NC);
8868 mode = 2;
8869 }
8870 if (mLowerWallpaperTarget != null) {
8871 if (mLowerWallpaperTarget.mAppToken == wtoken
8872 || mUpperWallpaperTarget.mAppToken == wtoken) {
8873 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008874 }
8875 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008876 if (wtoken.appFullscreen) {
8877 WindowState ws = wtoken.findMainWindow();
8878 if (ws != null) {
8879 // If this is a compatibility mode
8880 // window, we will always use its anim.
8881 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8882 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008883 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008884 bestAnimLayer = Integer.MAX_VALUE;
8885 } else if (ws.mLayer > bestAnimLayer) {
8886 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008887 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008888 bestAnimLayer = ws.mLayer;
8889 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008890 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008891 }
8892 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008893
Dianne Hackborn25994b42009-09-04 14:21:19 -07008894 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008895 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008896 "Wallpaper animation!");
8897 switch (transit) {
8898 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8899 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8900 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8901 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8902 break;
8903 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8904 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8905 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8906 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8907 break;
8908 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008909 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008910 "New transit: " + transit);
8911 } else if (oldWallpaper != null) {
8912 // We are transitioning from an activity with
8913 // a wallpaper to one without.
8914 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008915 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008916 "New transit away from wallpaper: " + transit);
8917 } else if (mWallpaperTarget != null) {
8918 // We are transitioning from an activity without
8919 // a wallpaper to now showing the wallpaper
8920 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008921 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008922 "New transit into wallpaper: " + transit);
8923 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008924
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008925 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8926 mLastEnterAnimToken = animToken;
8927 mLastEnterAnimParams = animLp;
8928 } else if (mLastEnterAnimParams != null) {
8929 animLp = mLastEnterAnimParams;
8930 mLastEnterAnimToken = null;
8931 mLastEnterAnimParams = null;
8932 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008933
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008934 // If all closing windows are obscured, then there is
8935 // no need to do an animation. This is the case, for
8936 // example, when this transition is being done behind
8937 // the lock screen.
8938 if (!mPolicy.allowAppAnimationsLw()) {
8939 animLp = null;
8940 }
8941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008942 NN = mOpeningApps.size();
8943 for (i=0; i<NN; i++) {
8944 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008945 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008946 "Now opening app" + wtoken);
8947 wtoken.reportedVisible = false;
8948 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008949 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008950 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008951 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008952 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008953 wtoken.showAllWindowsLocked();
8954 }
8955 NN = mClosingApps.size();
8956 for (i=0; i<NN; i++) {
8957 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008958 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008959 "Now closing app" + wtoken);
8960 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008961 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008962 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008963 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008964 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008965 // Force the allDrawn flag, because we want to start
8966 // this guy's animations regardless of whether it's
8967 // gotten drawn.
8968 wtoken.allDrawn = true;
8969 }
8970
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008971 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 mOpeningApps.clear();
8974 mClosingApps.clear();
8975
8976 // This has changed the visibility of windows, so perform
8977 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008978 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008979 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008980 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8981 assignLayersLocked();
8982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008983 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008984 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008985 }
8986 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008987
Dianne Hackborn16064f92010-03-25 00:47:24 -07008988 int adjResult = 0;
8989
Dianne Hackborna8f60182009-09-01 19:01:50 -07008990 if (!animating && mAppTransitionRunning) {
8991 // We have finished the animation of an app transition. To do
8992 // this, we have delayed a lot of operations like showing and
8993 // hiding apps, moving apps in Z-order, etc. The app token list
8994 // reflects the correct Z-order, but the window list may now
8995 // be out of sync with it. So here we will just rebuild the
8996 // entire app window list. Fun!
8997 mAppTransitionRunning = false;
8998 // Clear information about apps that were moving.
8999 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009000
Dianne Hackborna8f60182009-09-01 19:01:50 -07009001 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009002 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009003 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009004 moveInputMethodWindowsIfNeededLocked(false);
9005 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009006 // Since the window list has been rebuilt, focus might
9007 // have to be recomputed since the actual order of windows
9008 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009009 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009010 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009011
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009012 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009013 // At this point, there was a window with a wallpaper that
9014 // was force hiding other windows behind it, but now it
9015 // is going away. This may be simple -- just animate
9016 // away the wallpaper and its window -- or it may be
9017 // hard -- the wallpaper now needs to be shown behind
9018 // something that was hidden.
9019 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009020 if (mLowerWallpaperTarget != null
9021 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009022 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009023 "wallpaperForceHiding changed with lower="
9024 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009025 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009026 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9027 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9028 if (mLowerWallpaperTarget.mAppToken.hidden) {
9029 // The lower target has become hidden before we
9030 // actually started the animation... let's completely
9031 // re-evaluate everything.
9032 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009033 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009034 }
9035 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009036 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009037 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009038 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009039 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009040 + " NEW: " + mWallpaperTarget
9041 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009042 if (mLowerWallpaperTarget == null) {
9043 // Whoops, we don't need a special wallpaper animation.
9044 // Clear them out.
9045 forceHiding = false;
9046 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009047 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009048 if (w.mSurface != null) {
9049 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009050 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009051 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009052 forceHiding = true;
9053 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9054 if (!w.mAnimating) {
9055 // We set the animation above so it
9056 // is not yet running.
9057 w.clearAnimation();
9058 }
9059 }
9060 }
9061 }
9062 }
9063 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009064
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009065 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009066 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009067 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009068 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009069 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009070
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009071 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009072 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009073 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009074 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009075 assignLayersLocked();
9076 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009077 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009078 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009079 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009080 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009081
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009082 if (mFocusMayChange) {
9083 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009084 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009085 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009086 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009087 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009088 }
9089
9090 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009091 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009093
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009094 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9095 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009096
Jeff Browne33348b2010-07-15 23:54:05 -07009097 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009098 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009099
9100 // THIRD LOOP: Update the surfaces of all windows.
9101
9102 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9103
9104 boolean obscured = false;
9105 boolean blurring = false;
9106 boolean dimming = false;
9107 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009108 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009109 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009110
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009111 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009113 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009114 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009115
9116 boolean displayed = false;
9117 final WindowManager.LayoutParams attrs = w.mAttrs;
9118 final int attrFlags = attrs.flags;
9119
9120 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009121 // XXX NOTE: The logic here could be improved. We have
9122 // the decision about whether to resize a window separated
9123 // from whether to hide the surface. This can cause us to
9124 // resize a surface even if we are going to hide it. You
9125 // can see this by (1) holding device in landscape mode on
9126 // home screen; (2) tapping browser icon (device will rotate
9127 // to landscape; (3) tap home. The wallpaper will be resized
9128 // in step 2 but then immediately hidden, causing us to
9129 // have to resize and then redraw it again in step 3. It
9130 // would be nice to figure out how to avoid this, but it is
9131 // difficult because we do need to resize surfaces in some
9132 // cases while they are hidden such as when first showing a
9133 // window.
9134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009135 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009136 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009137 TAG, "Placing surface #" + i + " " + w.mSurface
9138 + ": new=" + w.mShownFrame + ", old="
9139 + w.mLastShownFrame);
9140
9141 boolean resize;
9142 int width, height;
9143 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9144 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9145 w.mLastRequestedHeight != w.mRequestedHeight;
9146 // for a scaled surface, we just want to use
9147 // the requested size.
9148 width = w.mRequestedWidth;
9149 height = w.mRequestedHeight;
9150 w.mLastRequestedWidth = width;
9151 w.mLastRequestedHeight = height;
9152 w.mLastShownFrame.set(w.mShownFrame);
9153 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009154 if (SHOW_TRANSACTIONS) logSurface(w,
9155 "POS " + w.mShownFrame.left
9156 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009157 w.mSurfaceX = w.mShownFrame.left;
9158 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009159 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9160 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009161 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 if (!recoveringMemory) {
9163 reclaimSomeSurfaceMemoryLocked(w, "position");
9164 }
9165 }
9166 } else {
9167 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9168 width = w.mShownFrame.width();
9169 height = w.mShownFrame.height();
9170 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 }
9172
9173 if (resize) {
9174 if (width < 1) width = 1;
9175 if (height < 1) height = 1;
9176 if (w.mSurface != null) {
9177 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009178 if (SHOW_TRANSACTIONS) logSurface(w,
9179 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009180 + w.mShownFrame.top + " SIZE "
9181 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009182 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009183 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009184 w.mSurfaceW = width;
9185 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009186 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009187 w.mSurfaceX = w.mShownFrame.left;
9188 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009189 w.mSurface.setPosition(w.mShownFrame.left,
9190 w.mShownFrame.top);
9191 } catch (RuntimeException e) {
9192 // If something goes wrong with the surface (such
9193 // as running out of memory), don't take down the
9194 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009195 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009196 + "size=(" + width + "x" + height
9197 + "), pos=(" + w.mShownFrame.left
9198 + "," + w.mShownFrame.top + ")", e);
9199 if (!recoveringMemory) {
9200 reclaimSomeSurfaceMemoryLocked(w, "size");
9201 }
9202 }
9203 }
9204 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009205 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009206 w.mContentInsetsChanged =
9207 !w.mLastContentInsets.equals(w.mContentInsets);
9208 w.mVisibleInsetsChanged =
9209 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009210 boolean configChanged =
9211 w.mConfiguration != mCurConfiguration
9212 && (w.mConfiguration == null
9213 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009214 if (DEBUG_CONFIGURATION && configChanged) {
9215 Slog.v(TAG, "Win " + w + " config changed: "
9216 + mCurConfiguration);
9217 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009218 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009219 + ": configChanged=" + configChanged
9220 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009221 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009223 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009224 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009225 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 w.mLastFrame.set(w.mFrame);
9227 w.mLastContentInsets.set(w.mContentInsets);
9228 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009229 // If the screen is currently frozen, then keep
9230 // it frozen until this window draws at its new
9231 // orientation.
9232 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009233 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009234 "Resizing while display frozen: " + w);
9235 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009236 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009237 mWindowsFreezingScreen = true;
9238 // XXX should probably keep timeout from
9239 // when we first froze the display.
9240 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9241 mH.sendMessageDelayed(mH.obtainMessage(
9242 H.WINDOW_FREEZE_TIMEOUT), 2000);
9243 }
9244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009245 // If the orientation is changing, then we need to
9246 // hold off on unfreezing the display until this
9247 // window has been redrawn; to do that, we need
9248 // to go through the process of getting informed
9249 // by the application when it has finished drawing.
9250 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009251 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009252 "Orientation start waiting for draw in "
9253 + w + ", surface " + w.mSurface);
9254 w.mDrawPending = true;
9255 w.mCommitDrawPending = false;
9256 w.mReadyToShow = false;
9257 if (w.mAppToken != null) {
9258 w.mAppToken.allDrawn = false;
9259 }
9260 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009261 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 "Resizing window " + w + " to " + w.mFrame);
9263 mResizingWindows.add(w);
9264 } else if (w.mOrientationChanging) {
9265 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009266 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009267 "Orientation not waiting for draw in "
9268 + w + ", surface " + w.mSurface);
9269 w.mOrientationChanging = false;
9270 }
9271 }
9272 }
9273
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009274 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009275 if (!w.mLastHidden) {
9276 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009277 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9278 + w.mRootToken.waitingToShow + " polvis="
9279 + w.mPolicyVisibility + " atthid="
9280 + w.mAttachedHidden + " tokhid="
9281 + w.mRootToken.hidden + " vis="
9282 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009284 if (SHOW_TRANSACTIONS) logSurface(w,
9285 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009286 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009287 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009288 try {
9289 w.mSurface.hide();
9290 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009291 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009292 }
9293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009294 }
9295 // If we are waiting for this window to handle an
9296 // orientation change, well, it is hidden, so
9297 // doesn't really matter. Note that this does
9298 // introduce a potential glitch if the window
9299 // becomes unhidden before it has drawn for the
9300 // new orientation.
9301 if (w.mOrientationChanging) {
9302 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009303 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009304 "Orientation change skips hidden " + w);
9305 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009306 } else if (w.mLastLayer != w.mAnimLayer
9307 || w.mLastAlpha != w.mShownAlpha
9308 || w.mLastDsDx != w.mDsDx
9309 || w.mLastDtDx != w.mDtDx
9310 || w.mLastDsDy != w.mDsDy
9311 || w.mLastDtDy != w.mDtDy
9312 || w.mLastHScale != w.mHScale
9313 || w.mLastVScale != w.mVScale
9314 || w.mLastHidden) {
9315 displayed = true;
9316 w.mLastAlpha = w.mShownAlpha;
9317 w.mLastLayer = w.mAnimLayer;
9318 w.mLastDsDx = w.mDsDx;
9319 w.mLastDtDx = w.mDtDx;
9320 w.mLastDsDy = w.mDsDy;
9321 w.mLastDtDy = w.mDtDy;
9322 w.mLastHScale = w.mHScale;
9323 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009324 if (SHOW_TRANSACTIONS) logSurface(w,
9325 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009326 + " matrix=[" + (w.mDsDx*w.mHScale)
9327 + "," + (w.mDtDx*w.mVScale)
9328 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009329 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009330 if (w.mSurface != null) {
9331 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009332 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009334 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335 w.mSurface.setLayer(w.mAnimLayer);
9336 w.mSurface.setMatrix(
9337 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9338 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9339 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009340 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009341 if (!recoveringMemory) {
9342 reclaimSomeSurfaceMemoryLocked(w, "update");
9343 }
9344 }
9345 }
9346
9347 if (w.mLastHidden && !w.mDrawPending
9348 && !w.mCommitDrawPending
9349 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009350 if (SHOW_TRANSACTIONS) logSurface(w,
9351 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009352 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009353 + " during relayout");
9354 if (showSurfaceRobustlyLocked(w)) {
9355 w.mHasDrawn = true;
9356 w.mLastHidden = false;
9357 } else {
9358 w.mOrientationChanging = false;
9359 }
9360 }
9361 if (w.mSurface != null) {
9362 w.mToken.hasVisible = true;
9363 }
9364 } else {
9365 displayed = true;
9366 }
9367
9368 if (displayed) {
9369 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009370 if (attrs.width == LayoutParams.MATCH_PARENT
9371 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009372 covered = true;
9373 }
9374 }
9375 if (w.mOrientationChanging) {
9376 if (w.mDrawPending || w.mCommitDrawPending) {
9377 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009378 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 "Orientation continue waiting for draw in " + w);
9380 } else {
9381 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009382 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 "Orientation change complete in " + w);
9384 }
9385 }
9386 w.mToken.hasVisible = true;
9387 }
9388 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009389 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009390 "Orientation change skips hidden " + w);
9391 w.mOrientationChanging = false;
9392 }
9393
9394 final boolean canBeSeen = w.isDisplayedLw();
9395
9396 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9397 focusDisplayed = true;
9398 }
9399
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009400 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009402 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009403 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 if (w.mSurface != null) {
9405 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9406 holdScreen = w.mSession;
9407 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009408 if (!syswin && w.mAttrs.screenBrightness >= 0
9409 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 screenBrightness = w.mAttrs.screenBrightness;
9411 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009412 if (!syswin && w.mAttrs.buttonBrightness >= 0
9413 && buttonBrightness < 0) {
9414 buttonBrightness = w.mAttrs.buttonBrightness;
9415 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009416 if (canBeSeen
9417 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9418 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9419 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009420 syswin = true;
9421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009423
Dianne Hackborn25994b42009-09-04 14:21:19 -07009424 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9425 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 // This window completely covers everything behind it,
9427 // so we want to leave all of them as unblurred (for
9428 // performance reasons).
9429 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009430 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009431 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009432 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009433 obscured = true;
9434 if (mBackgroundFillerSurface == null) {
9435 try {
9436 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009437 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009438 0, dw, dh,
9439 PixelFormat.OPAQUE,
9440 Surface.FX_SURFACE_NORMAL);
9441 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009442 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009443 }
9444 }
9445 try {
9446 mBackgroundFillerSurface.setPosition(0, 0);
9447 mBackgroundFillerSurface.setSize(dw, dh);
9448 // Using the same layer as Dim because they will never be shown at the
9449 // same time.
9450 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9451 mBackgroundFillerSurface.show();
9452 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009453 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009454 }
9455 backgroundFillerShown = true;
9456 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009457 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009458 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009459 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009460 + ": blurring=" + blurring
9461 + " obscured=" + obscured
9462 + " displayed=" + displayed);
9463 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9464 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009465 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009466 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009467 if (mDimAnimator == null) {
9468 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009470 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009471 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009472 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009473 }
9474 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9475 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009476 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009477 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009478 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009479 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 + mBlurSurface + ": CREATE");
9481 try {
Romain Guy06882f82009-06-10 13:36:04 -07009482 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009483 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009484 -1, 16, 16,
9485 PixelFormat.OPAQUE,
9486 Surface.FX_SURFACE_BLUR);
9487 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009488 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489 }
9490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009492 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9493 + mBlurSurface + ": pos=(0,0) (" +
9494 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009495 mBlurSurface.setPosition(0, 0);
9496 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009497 mBlurSurface.setLayer(w.mAnimLayer-2);
9498 if (!mBlurShown) {
9499 try {
9500 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9501 + mBlurSurface + ": SHOW");
9502 mBlurSurface.show();
9503 } catch (RuntimeException e) {
9504 Slog.w(TAG, "Failure showing blur surface", e);
9505 }
9506 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009507 }
9508 }
9509 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510 }
9511 }
9512 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009513
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009514 if (obscuredChanged && mWallpaperTarget == w) {
9515 // This is the wallpaper target and its obscured state
9516 // changed... make sure the current wallaper's visibility
9517 // has been updated accordingly.
9518 updateWallpaperVisibilityLocked();
9519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009520 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009521
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009522 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9523 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009524 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009525 try {
9526 mBackgroundFillerSurface.hide();
9527 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009528 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009529 }
9530 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009531
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009532 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009533 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9534 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009535 }
Romain Guy06882f82009-06-10 13:36:04 -07009536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009537 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009538 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 + ": HIDE");
9540 try {
9541 mBlurSurface.hide();
9542 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009543 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009544 }
9545 mBlurShown = false;
9546 }
9547
Joe Onorato8a9b2202010-02-26 18:56:32 -08009548 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009549 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009550 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 }
9552
Jeff Browne33348b2010-07-15 23:54:05 -07009553 mInputMonitor.updateInputWindowsLw();
9554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009555 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009556
Joe Onorato8a9b2202010-02-26 18:56:32 -08009557 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 "With display frozen, orientationChangeComplete="
9559 + orientationChangeComplete);
9560 if (orientationChangeComplete) {
9561 if (mWindowsFreezingScreen) {
9562 mWindowsFreezingScreen = false;
9563 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9564 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009565 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009566 }
Romain Guy06882f82009-06-10 13:36:04 -07009567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009568 i = mResizingWindows.size();
9569 if (i > 0) {
9570 do {
9571 i--;
9572 WindowState win = mResizingWindows.get(i);
9573 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009574 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9575 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009576 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009577 boolean configChanged =
9578 win.mConfiguration != mCurConfiguration
9579 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009580 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9581 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9582 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009583 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009584 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009585 + " / " + mCurConfiguration + " / 0x"
9586 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009587 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009588 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 win.mClient.resized(win.mFrame.width(),
9590 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009591 win.mLastVisibleInsets, win.mDrawPending,
9592 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 win.mContentInsetsChanged = false;
9594 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009595 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009596 } catch (RemoteException e) {
9597 win.mOrientationChanging = false;
9598 }
9599 } while (i > 0);
9600 mResizingWindows.clear();
9601 }
Romain Guy06882f82009-06-10 13:36:04 -07009602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009604 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009605 i = mDestroySurface.size();
9606 if (i > 0) {
9607 do {
9608 i--;
9609 WindowState win = mDestroySurface.get(i);
9610 win.mDestroying = false;
9611 if (mInputMethodWindow == win) {
9612 mInputMethodWindow = null;
9613 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009614 if (win == mWallpaperTarget) {
9615 wallpaperDestroyed = true;
9616 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009617 win.destroySurfaceLocked();
9618 } while (i > 0);
9619 mDestroySurface.clear();
9620 }
9621
9622 // Time to remove any exiting tokens?
9623 for (i=mExitingTokens.size()-1; i>=0; i--) {
9624 WindowToken token = mExitingTokens.get(i);
9625 if (!token.hasVisible) {
9626 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009627 if (token.windowType == TYPE_WALLPAPER) {
9628 mWallpaperTokens.remove(token);
9629 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009630 }
9631 }
9632
9633 // Time to remove any exiting applications?
9634 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9635 AppWindowToken token = mExitingAppTokens.get(i);
9636 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009637 // Make sure there is no animation running on this token,
9638 // so any windows associated with it will be removed as
9639 // soon as their animations are complete
9640 token.animation = null;
9641 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009642 mAppTokens.remove(token);
9643 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009644 if (mLastEnterAnimToken == token) {
9645 mLastEnterAnimToken = null;
9646 mLastEnterAnimParams = null;
9647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009648 }
9649 }
9650
Dianne Hackborna8f60182009-09-01 19:01:50 -07009651 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009652
Dianne Hackborna8f60182009-09-01 19:01:50 -07009653 if (!animating && mAppTransitionRunning) {
9654 // We have finished the animation of an app transition. To do
9655 // this, we have delayed a lot of operations like showing and
9656 // hiding apps, moving apps in Z-order, etc. The app token list
9657 // reflects the correct Z-order, but the window list may now
9658 // be out of sync with it. So here we will just rebuild the
9659 // entire app window list. Fun!
9660 mAppTransitionRunning = false;
9661 needRelayout = true;
9662 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009663 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009664 // Clear information about apps that were moving.
9665 mToBottomApps.clear();
9666 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009668 if (focusDisplayed) {
9669 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9670 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009671 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009672 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009673 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009674 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009675 requestAnimationLocked(0);
9676 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009677 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9678 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009679
Jeff Browne33348b2010-07-15 23:54:05 -07009680 mInputMonitor.updateInputWindowsLw();
9681
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009682 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9683 + " holdScreen=" + holdScreen);
9684 if (!mDisplayFrozen) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009685 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009686 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9687 mPowerManager.setScreenBrightnessOverride(-1);
9688 } else {
9689 mPowerManager.setScreenBrightnessOverride((int)
9690 (screenBrightness * Power.BRIGHTNESS_ON));
9691 }
9692 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9693 mPowerManager.setButtonBrightnessOverride(-1);
9694 } else {
9695 mPowerManager.setButtonBrightnessOverride((int)
9696 (buttonBrightness * Power.BRIGHTNESS_ON));
9697 }
9698 if (holdScreen != mHoldingScreenOn) {
9699 mHoldingScreenOn = holdScreen;
9700 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9701 mH.sendMessage(m);
9702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009703 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009704
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009705 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009706 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009707 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9708 LocalPowerManager.BUTTON_EVENT, true);
9709 mTurnOnScreen = false;
9710 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009711
9712 // Check to see if we are now in a state where the screen should
9713 // be enabled, because the window obscured flags have changed.
9714 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009715 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009716
9717 /**
9718 * Must be called with the main window manager lock held.
9719 */
9720 void setHoldScreenLocked(boolean holding) {
9721 boolean state = mHoldingScreenWakeLock.isHeld();
9722 if (holding != state) {
9723 if (holding) {
9724 mHoldingScreenWakeLock.acquire();
9725 } else {
9726 mPolicy.screenOnStoppedLw();
9727 mHoldingScreenWakeLock.release();
9728 }
9729 }
9730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009731
9732 void requestAnimationLocked(long delay) {
9733 if (!mAnimationPending) {
9734 mAnimationPending = true;
9735 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9736 }
9737 }
Romain Guy06882f82009-06-10 13:36:04 -07009738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739 /**
9740 * Have the surface flinger show a surface, robustly dealing with
9741 * error conditions. In particular, if there is not enough memory
9742 * to show the surface, then we will try to get rid of other surfaces
9743 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009744 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009745 * @return Returns true if the surface was successfully shown.
9746 */
9747 boolean showSurfaceRobustlyLocked(WindowState win) {
9748 try {
9749 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009750 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009751 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009752 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009753 if (DEBUG_VISIBILITY) Slog.v(TAG,
9754 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009755 win.mTurnOnScreen = false;
9756 mTurnOnScreen = true;
9757 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 }
9759 return true;
9760 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009761 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009762 }
Romain Guy06882f82009-06-10 13:36:04 -07009763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009766 return false;
9767 }
Romain Guy06882f82009-06-10 13:36:04 -07009768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9770 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009771
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009772 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009773 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 if (mForceRemoves == null) {
9776 mForceRemoves = new ArrayList<WindowState>();
9777 }
Romain Guy06882f82009-06-10 13:36:04 -07009778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009779 long callingIdentity = Binder.clearCallingIdentity();
9780 try {
9781 // There was some problem... first, do a sanity check of the
9782 // window list to make sure we haven't left any dangling surfaces
9783 // around.
9784 int N = mWindows.size();
9785 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009786 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009788 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009789 if (ws.mSurface != null) {
9790 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009791 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009792 + ws + " surface=" + ws.mSurface
9793 + " token=" + win.mToken
9794 + " pid=" + ws.mSession.mPid
9795 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009796 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009797 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009798 ws.mSurface = null;
9799 mForceRemoves.add(ws);
9800 i--;
9801 N--;
9802 leakedSurface = true;
9803 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009804 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 + ws + " surface=" + ws.mSurface
9806 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009807 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009808 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009809 ws.mSurface = null;
9810 leakedSurface = true;
9811 }
9812 }
9813 }
Romain Guy06882f82009-06-10 13:36:04 -07009814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009815 boolean killedApps = false;
9816 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009817 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 SparseIntArray pidCandidates = new SparseIntArray();
9819 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009820 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009821 if (ws.mSurface != null) {
9822 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9823 }
9824 }
9825 if (pidCandidates.size() > 0) {
9826 int[] pids = new int[pidCandidates.size()];
9827 for (int i=0; i<pids.length; i++) {
9828 pids[i] = pidCandidates.keyAt(i);
9829 }
9830 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009831 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009832 killedApps = true;
9833 }
9834 } catch (RemoteException e) {
9835 }
9836 }
9837 }
Romain Guy06882f82009-06-10 13:36:04 -07009838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 if (leakedSurface || killedApps) {
9840 // We managed to reclaim some memory, so get rid of the trouble
9841 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009842 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009843 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009844 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009845 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 win.mSurface = null;
9847 }
Romain Guy06882f82009-06-10 13:36:04 -07009848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009849 try {
9850 win.mClient.dispatchGetNewSurface();
9851 } catch (RemoteException e) {
9852 }
9853 }
9854 } finally {
9855 Binder.restoreCallingIdentity(callingIdentity);
9856 }
9857 }
Romain Guy06882f82009-06-10 13:36:04 -07009858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859 private boolean updateFocusedWindowLocked(int mode) {
9860 WindowState newFocus = computeFocusedWindowLocked();
9861 if (mCurrentFocus != newFocus) {
9862 // This check makes sure that we don't already have the focus
9863 // change message pending.
9864 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9865 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009866 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9868 final WindowState oldFocus = mCurrentFocus;
9869 mCurrentFocus = newFocus;
9870 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 final WindowState imWindow = mInputMethodWindow;
9873 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009874 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009875 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009876 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9877 mLayoutNeeded = true;
9878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009879 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9880 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009881 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9882 // Client will do the layout, but we need to assign layers
9883 // for handleNewWindowLocked() below.
9884 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 }
9886 }
Jeff Brown349703e2010-06-22 01:27:15 -07009887
9888 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9889 // If we defer assigning layers, then the caller is responsible for
9890 // doing this part.
9891 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893 return true;
9894 }
9895 return false;
9896 }
Jeff Brown349703e2010-06-22 01:27:15 -07009897
9898 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009899 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009901
9902 private WindowState computeFocusedWindowLocked() {
9903 WindowState result = null;
9904 WindowState win;
9905
9906 int i = mWindows.size() - 1;
9907 int nextAppIndex = mAppTokens.size()-1;
9908 WindowToken nextApp = nextAppIndex >= 0
9909 ? mAppTokens.get(nextAppIndex) : null;
9910
9911 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009912 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009913
Joe Onorato8a9b2202010-02-26 18:56:32 -08009914 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 TAG, "Looking for focus: " + i
9916 + " = " + win
9917 + ", flags=" + win.mAttrs.flags
9918 + ", canReceive=" + win.canReceiveKeys());
9919
9920 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 // If this window's application has been removed, just skip it.
9923 if (thisApp != null && thisApp.removed) {
9924 i--;
9925 continue;
9926 }
Romain Guy06882f82009-06-10 13:36:04 -07009927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009928 // If there is a focused app, don't allow focus to go to any
9929 // windows below it. If this is an application window, step
9930 // through the app tokens until we find its app.
9931 if (thisApp != null && nextApp != null && thisApp != nextApp
9932 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9933 int origAppIndex = nextAppIndex;
9934 while (nextAppIndex > 0) {
9935 if (nextApp == mFocusedApp) {
9936 // Whoops, we are below the focused app... no focus
9937 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009938 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 TAG, "Reached focused app: " + mFocusedApp);
9940 return null;
9941 }
9942 nextAppIndex--;
9943 nextApp = mAppTokens.get(nextAppIndex);
9944 if (nextApp == thisApp) {
9945 break;
9946 }
9947 }
9948 if (thisApp != nextApp) {
9949 // Uh oh, the app token doesn't exist! This shouldn't
9950 // happen, but if it does we can get totally hosed...
9951 // so restart at the original app.
9952 nextAppIndex = origAppIndex;
9953 nextApp = mAppTokens.get(nextAppIndex);
9954 }
9955 }
9956
9957 // Dispatch to this window if it is wants key events.
9958 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009959 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009960 TAG, "Found focus @ " + i + " = " + win);
9961 result = win;
9962 break;
9963 }
9964
9965 i--;
9966 }
9967
9968 return result;
9969 }
9970
9971 private void startFreezingDisplayLocked() {
9972 if (mDisplayFrozen) {
9973 return;
9974 }
Romain Guy06882f82009-06-10 13:36:04 -07009975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009976 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009978 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009979 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009980 if (mFreezeGcPending != 0) {
9981 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009982 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 mH.removeMessages(H.FORCE_GC);
9984 Runtime.getRuntime().gc();
9985 mFreezeGcPending = now;
9986 }
9987 } else {
9988 mFreezeGcPending = now;
9989 }
Romain Guy06882f82009-06-10 13:36:04 -07009990
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009991 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
9992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009994
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009995 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009996
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009997 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9998 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009999 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 mAppTransitionReady = true;
10001 }
Romain Guy06882f82009-06-10 13:36:04 -070010002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 if (PROFILE_ORIENTATION) {
10004 File file = new File("/data/system/frozen");
10005 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10006 }
10007 Surface.freezeDisplay(0);
10008 }
Romain Guy06882f82009-06-10 13:36:04 -070010009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010010 private void stopFreezingDisplayLocked() {
10011 if (!mDisplayFrozen) {
10012 return;
10013 }
Romain Guy06882f82009-06-10 13:36:04 -070010014
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010015 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10016 return;
10017 }
10018
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010019 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
10020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 mDisplayFrozen = false;
10022 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10023 if (PROFILE_ORIENTATION) {
10024 Debug.stopMethodTracing();
10025 }
10026 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010027
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010028 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010029
Christopher Tateb696aee2010-04-02 19:08:30 -070010030 // While the display is frozen we don't re-compute the orientation
10031 // to avoid inconsistent states. However, something interesting
10032 // could have actually changed during that time so re-evaluate it
10033 // now to catch that.
10034 if (updateOrientationFromAppTokensLocked()) {
10035 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10036 }
10037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010038 // A little kludge: a lot could have happened while the
10039 // display was frozen, so now that we are coming back we
10040 // do a gc so that any remote references the system
10041 // processes holds on others can be released if they are
10042 // no longer needed.
10043 mH.removeMessages(H.FORCE_GC);
10044 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10045 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010047 mScreenFrozenLock.release();
10048 }
Romain Guy06882f82009-06-10 13:36:04 -070010049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 @Override
10051 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10052 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10053 != PackageManager.PERMISSION_GRANTED) {
10054 pw.println("Permission Denial: can't dump WindowManager from from pid="
10055 + Binder.getCallingPid()
10056 + ", uid=" + Binder.getCallingUid());
10057 return;
10058 }
Romain Guy06882f82009-06-10 13:36:04 -070010059
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010060 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010061 pw.println(" ");
10062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 synchronized(mWindowMap) {
10064 pw.println("Current Window Manager state:");
10065 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010066 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010067 pw.print(" Window #"); pw.print(i); pw.print(' ');
10068 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 w.dump(pw, " ");
10070 }
10071 if (mInputMethodDialogs.size() > 0) {
10072 pw.println(" ");
10073 pw.println(" Input method dialogs:");
10074 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10075 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010076 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 }
10078 }
10079 if (mPendingRemove.size() > 0) {
10080 pw.println(" ");
10081 pw.println(" Remove pending for:");
10082 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10083 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010084 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10085 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010086 w.dump(pw, " ");
10087 }
10088 }
10089 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10090 pw.println(" ");
10091 pw.println(" Windows force removing:");
10092 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10093 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010094 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10095 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010096 w.dump(pw, " ");
10097 }
10098 }
10099 if (mDestroySurface.size() > 0) {
10100 pw.println(" ");
10101 pw.println(" Windows waiting to destroy their surface:");
10102 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10103 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010104 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10105 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 w.dump(pw, " ");
10107 }
10108 }
10109 if (mLosingFocus.size() > 0) {
10110 pw.println(" ");
10111 pw.println(" Windows losing focus:");
10112 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10113 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010114 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10115 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010116 w.dump(pw, " ");
10117 }
10118 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010119 if (mResizingWindows.size() > 0) {
10120 pw.println(" ");
10121 pw.println(" Windows waiting to resize:");
10122 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10123 WindowState w = mResizingWindows.get(i);
10124 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10125 pw.print(w); pw.println(":");
10126 w.dump(pw, " ");
10127 }
10128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010129 if (mSessions.size() > 0) {
10130 pw.println(" ");
10131 pw.println(" All active sessions:");
10132 Iterator<Session> it = mSessions.iterator();
10133 while (it.hasNext()) {
10134 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010135 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010136 s.dump(pw, " ");
10137 }
10138 }
10139 if (mTokenMap.size() > 0) {
10140 pw.println(" ");
10141 pw.println(" All tokens:");
10142 Iterator<WindowToken> it = mTokenMap.values().iterator();
10143 while (it.hasNext()) {
10144 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010145 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010146 token.dump(pw, " ");
10147 }
10148 }
10149 if (mTokenList.size() > 0) {
10150 pw.println(" ");
10151 pw.println(" Window token list:");
10152 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010153 pw.print(" #"); pw.print(i); pw.print(": ");
10154 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010155 }
10156 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010157 if (mWallpaperTokens.size() > 0) {
10158 pw.println(" ");
10159 pw.println(" Wallpaper tokens:");
10160 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10161 WindowToken token = mWallpaperTokens.get(i);
10162 pw.print(" Wallpaper #"); pw.print(i);
10163 pw.print(' '); pw.print(token); pw.println(':');
10164 token.dump(pw, " ");
10165 }
10166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010167 if (mAppTokens.size() > 0) {
10168 pw.println(" ");
10169 pw.println(" Application tokens in Z order:");
10170 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010171 pw.print(" App #"); pw.print(i); pw.print(": ");
10172 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010173 }
10174 }
10175 if (mFinishedStarting.size() > 0) {
10176 pw.println(" ");
10177 pw.println(" Finishing start of application tokens:");
10178 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10179 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010180 pw.print(" Finished Starting #"); pw.print(i);
10181 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010182 token.dump(pw, " ");
10183 }
10184 }
10185 if (mExitingTokens.size() > 0) {
10186 pw.println(" ");
10187 pw.println(" Exiting tokens:");
10188 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10189 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010190 pw.print(" Exiting #"); pw.print(i);
10191 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010192 token.dump(pw, " ");
10193 }
10194 }
10195 if (mExitingAppTokens.size() > 0) {
10196 pw.println(" ");
10197 pw.println(" Exiting application tokens:");
10198 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10199 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010200 pw.print(" Exiting App #"); pw.print(i);
10201 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010202 token.dump(pw, " ");
10203 }
10204 }
10205 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010206 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10207 pw.print(" mLastFocus="); pw.println(mLastFocus);
10208 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10209 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10210 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010211 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010212 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10213 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10214 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10215 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010216 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10217 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10218 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010219 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10220 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10221 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10222 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010223 if (mDimAnimator != null) {
10224 mDimAnimator.printTo(pw);
10225 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010226 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010227 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010228 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010229 pw.print(mInputMethodAnimLayerAdjustment);
10230 pw.print(" mWallpaperAnimLayerAdjustment=");
10231 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010232 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10233 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010234 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10235 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010236 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10237 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010238 pw.print(" mRotation="); pw.print(mRotation);
10239 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10240 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10241 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10242 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10243 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10244 pw.print(" mNextAppTransition=0x");
10245 pw.print(Integer.toHexString(mNextAppTransition));
10246 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010247 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010248 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010249 if (mNextAppTransitionPackage != null) {
10250 pw.print(" mNextAppTransitionPackage=");
10251 pw.print(mNextAppTransitionPackage);
10252 pw.print(", mNextAppTransitionEnter=0x");
10253 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10254 pw.print(", mNextAppTransitionExit=0x");
10255 pw.print(Integer.toHexString(mNextAppTransitionExit));
10256 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010257 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10258 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010259 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10260 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10261 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10262 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010263 if (mOpeningApps.size() > 0) {
10264 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10265 }
10266 if (mClosingApps.size() > 0) {
10267 pw.print(" mClosingApps="); pw.println(mClosingApps);
10268 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010269 if (mToTopApps.size() > 0) {
10270 pw.print(" mToTopApps="); pw.println(mToTopApps);
10271 }
10272 if (mToBottomApps.size() > 0) {
10273 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10274 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010275 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10276 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010277 }
10278 }
10279
Jeff Brown349703e2010-06-22 01:27:15 -070010280 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 public void monitor() {
10282 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010283 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010284 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010285
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010286 /**
10287 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010288 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010289 */
10290 private static class DimAnimator {
10291 Surface mDimSurface;
10292 boolean mDimShown = false;
10293 float mDimCurrentAlpha;
10294 float mDimTargetAlpha;
10295 float mDimDeltaPerMs;
10296 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010297
10298 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010299
10300 DimAnimator (SurfaceSession session) {
10301 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010302 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010303 + mDimSurface + ": CREATE");
10304 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010305 mDimSurface = new Surface(session, 0,
10306 "DimSurface",
10307 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010308 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010309 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010310 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010311 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010312 }
10313 }
10314 }
10315
10316 /**
10317 * Show the dim surface.
10318 */
10319 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010320 if (!mDimShown) {
10321 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10322 dw + "x" + dh + ")");
10323 mDimShown = true;
10324 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010325 mLastDimWidth = dw;
10326 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010327 mDimSurface.setPosition(0, 0);
10328 mDimSurface.setSize(dw, dh);
10329 mDimSurface.show();
10330 } catch (RuntimeException e) {
10331 Slog.w(TAG, "Failure showing dim surface", e);
10332 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010333 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10334 mLastDimWidth = dw;
10335 mLastDimHeight = dh;
10336 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010337 }
10338 }
10339
10340 /**
10341 * Set's the dim surface's layer and update dim parameters that will be used in
10342 * {@link updateSurface} after all windows are examined.
10343 */
10344 void updateParameters(WindowState w, long currentTime) {
10345 mDimSurface.setLayer(w.mAnimLayer-1);
10346
10347 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010348 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010349 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010350 if (mDimTargetAlpha != target) {
10351 // If the desired dim level has changed, then
10352 // start an animation to it.
10353 mLastDimAnimTime = currentTime;
10354 long duration = (w.mAnimating && w.mAnimation != null)
10355 ? w.mAnimation.computeDurationHint()
10356 : DEFAULT_DIM_DURATION;
10357 if (target > mDimTargetAlpha) {
10358 // This is happening behind the activity UI,
10359 // so we can make it run a little longer to
10360 // give a stronger impression without disrupting
10361 // the user.
10362 duration *= DIM_DURATION_MULTIPLIER;
10363 }
10364 if (duration < 1) {
10365 // Don't divide by zero
10366 duration = 1;
10367 }
10368 mDimTargetAlpha = target;
10369 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10370 }
10371 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010372
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010373 /**
10374 * Updating the surface's alpha. Returns true if the animation continues, or returns
10375 * false when the animation is finished and the dim surface is hidden.
10376 */
10377 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10378 if (!dimming) {
10379 if (mDimTargetAlpha != 0) {
10380 mLastDimAnimTime = currentTime;
10381 mDimTargetAlpha = 0;
10382 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10383 }
10384 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010385
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010386 boolean animating = false;
10387 if (mLastDimAnimTime != 0) {
10388 mDimCurrentAlpha += mDimDeltaPerMs
10389 * (currentTime-mLastDimAnimTime);
10390 boolean more = true;
10391 if (displayFrozen) {
10392 // If the display is frozen, there is no reason to animate.
10393 more = false;
10394 } else if (mDimDeltaPerMs > 0) {
10395 if (mDimCurrentAlpha > mDimTargetAlpha) {
10396 more = false;
10397 }
10398 } else if (mDimDeltaPerMs < 0) {
10399 if (mDimCurrentAlpha < mDimTargetAlpha) {
10400 more = false;
10401 }
10402 } else {
10403 more = false;
10404 }
10405
10406 // Do we need to continue animating?
10407 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010408 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010409 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10410 mLastDimAnimTime = currentTime;
10411 mDimSurface.setAlpha(mDimCurrentAlpha);
10412 animating = true;
10413 } else {
10414 mDimCurrentAlpha = mDimTargetAlpha;
10415 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010416 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010417 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10418 mDimSurface.setAlpha(mDimCurrentAlpha);
10419 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010420 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010421 + ": HIDE");
10422 try {
10423 mDimSurface.hide();
10424 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010425 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010426 }
10427 mDimShown = false;
10428 }
10429 }
10430 }
10431 return animating;
10432 }
10433
10434 public void printTo(PrintWriter pw) {
10435 pw.print(" mDimShown="); pw.print(mDimShown);
10436 pw.print(" current="); pw.print(mDimCurrentAlpha);
10437 pw.print(" target="); pw.print(mDimTargetAlpha);
10438 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10439 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10440 }
10441 }
10442
10443 /**
10444 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10445 * This is used for opening/closing transition for apps in compatible mode.
10446 */
10447 private static class FadeInOutAnimation extends Animation {
10448 int mWidth;
10449 boolean mFadeIn;
10450
10451 public FadeInOutAnimation(boolean fadeIn) {
10452 setInterpolator(new AccelerateInterpolator());
10453 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10454 mFadeIn = fadeIn;
10455 }
10456
10457 @Override
10458 protected void applyTransformation(float interpolatedTime, Transformation t) {
10459 float x = interpolatedTime;
10460 if (!mFadeIn) {
10461 x = 1.0f - x; // reverse the interpolation for fade out
10462 }
10463 if (x < 0.5) {
10464 // move the window out of the screen.
10465 t.getMatrix().setTranslate(mWidth, 0);
10466 } else {
10467 t.getMatrix().setTranslate(0, 0);// show
10468 t.setAlpha((x - 0.5f) * 2);
10469 }
10470 }
10471
10472 @Override
10473 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10474 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10475 mWidth = width;
10476 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010477
10478 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010479 public int getZAdjustment() {
10480 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010481 }
10482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010483}