blob: 11fcca8d89c008cbe582e458e8ffa53be85bb9ea [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 }
Jeff Browna41ca772010-08-11 14:46:32 -07004385
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
Jeff Browna41ca772010-08-11 14:46:32 -07004390 public InputChannel monitorInput(String inputChannelName) {
4391 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4392 "monitorInput()")) {
4393 throw new SecurityException("Requires READ_INPUT_STATE permission");
4394 }
4395 return mInputManager.monitorInput(inputChannelName);
4396 }
4397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 public void enableScreenAfterBoot() {
4399 synchronized(mWindowMap) {
4400 if (mSystemBooted) {
4401 return;
4402 }
4403 mSystemBooted = true;
4404 }
Romain Guy06882f82009-06-10 13:36:04 -07004405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 performEnableScreen();
4407 }
Romain Guy06882f82009-06-10 13:36:04 -07004408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 public void enableScreenIfNeededLocked() {
4410 if (mDisplayEnabled) {
4411 return;
4412 }
4413 if (!mSystemBooted) {
4414 return;
4415 }
4416 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4417 }
Romain Guy06882f82009-06-10 13:36:04 -07004418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004419 public void performEnableScreen() {
4420 synchronized(mWindowMap) {
4421 if (mDisplayEnabled) {
4422 return;
4423 }
4424 if (!mSystemBooted) {
4425 return;
4426 }
Romain Guy06882f82009-06-10 13:36:04 -07004427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 // Don't enable the screen until all existing windows
4429 // have been drawn.
4430 final int N = mWindows.size();
4431 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004432 WindowState w = mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004433 if (w.isVisibleLw() && !w.mObscured
4434 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 return;
4436 }
4437 }
Romain Guy06882f82009-06-10 13:36:04 -07004438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 mDisplayEnabled = true;
4440 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004441 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004442 StringWriter sw = new StringWriter();
4443 PrintWriter pw = new PrintWriter(sw);
4444 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004445 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 }
4447 try {
4448 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4449 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004450 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 Parcel data = Parcel.obtain();
4452 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4453 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4454 data, null, 0);
4455 data.recycle();
4456 }
4457 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004458 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 }
4460 }
Romain Guy06882f82009-06-10 13:36:04 -07004461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004465 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4466 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 }
Romain Guy06882f82009-06-10 13:36:04 -07004468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 public void setInTouchMode(boolean mode) {
4470 synchronized(mWindowMap) {
4471 mInTouchMode = mode;
4472 }
4473 }
4474
Romain Guy06882f82009-06-10 13:36:04 -07004475 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004476 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004478 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004479 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 }
4481
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004482 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 }
Romain Guy06882f82009-06-10 13:36:04 -07004484
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004485 public void setRotationUnchecked(int rotation,
4486 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004487 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 long origId = Binder.clearCallingIdentity();
4491 boolean changed;
4492 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004493 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 }
Romain Guy06882f82009-06-10 13:36:04 -07004495
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004496 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 sendNewConfiguration();
4498 }
Romain Guy06882f82009-06-10 13:36:04 -07004499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004500 Binder.restoreCallingIdentity(origId);
4501 }
Romain Guy06882f82009-06-10 13:36:04 -07004502
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004503 /**
4504 * Apply a new rotation to the screen, respecting the requests of
4505 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4506 * re-evaluate the desired rotation.
4507 *
4508 * Returns null if the rotation has been changed. In this case YOU
4509 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4510 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004511 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 boolean changed;
4513 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4514 rotation = mRequestedRotation;
4515 } else {
4516 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004517 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004518 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004519 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004520 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004522 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004526 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 "Rotation changed to " + rotation
4528 + " from " + mRotation
4529 + " (forceApp=" + mForcedAppOrientation
4530 + ", req=" + mRequestedRotation + ")");
4531 mRotation = rotation;
4532 mWindowsFreezingScreen = true;
4533 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4534 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4535 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004536 mWaitingForConfig = true;
4537 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004539 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004540 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004541 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004542 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 }
4544 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004545 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004546 if (w.mSurface != null) {
4547 w.mOrientationChanging = true;
4548 }
4549 }
4550 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4551 try {
4552 mRotationWatchers.get(i).onRotationChanged(rotation);
4553 } catch (RemoteException e) {
4554 }
4555 }
4556 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004558 return changed;
4559 }
Romain Guy06882f82009-06-10 13:36:04 -07004560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004561 public int getRotation() {
4562 return mRotation;
4563 }
4564
4565 public int watchRotation(IRotationWatcher watcher) {
4566 final IBinder watcherBinder = watcher.asBinder();
4567 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4568 public void binderDied() {
4569 synchronized (mWindowMap) {
4570 for (int i=0; i<mRotationWatchers.size(); i++) {
4571 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004572 IRotationWatcher removed = mRotationWatchers.remove(i);
4573 if (removed != null) {
4574 removed.asBinder().unlinkToDeath(this, 0);
4575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004576 i--;
4577 }
4578 }
4579 }
4580 }
4581 };
Romain Guy06882f82009-06-10 13:36:04 -07004582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004583 synchronized (mWindowMap) {
4584 try {
4585 watcher.asBinder().linkToDeath(dr, 0);
4586 mRotationWatchers.add(watcher);
4587 } catch (RemoteException e) {
4588 // Client died, no cleanup needed.
4589 }
Romain Guy06882f82009-06-10 13:36:04 -07004590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004591 return mRotation;
4592 }
4593 }
4594
4595 /**
4596 * Starts the view server on the specified port.
4597 *
4598 * @param port The port to listener to.
4599 *
4600 * @return True if the server was successfully started, false otherwise.
4601 *
4602 * @see com.android.server.ViewServer
4603 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4604 */
4605 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004606 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004607 return false;
4608 }
4609
4610 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4611 return false;
4612 }
4613
4614 if (port < 1024) {
4615 return false;
4616 }
4617
4618 if (mViewServer != null) {
4619 if (!mViewServer.isRunning()) {
4620 try {
4621 return mViewServer.start();
4622 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004623 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004624 }
4625 }
4626 return false;
4627 }
4628
4629 try {
4630 mViewServer = new ViewServer(this, port);
4631 return mViewServer.start();
4632 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004633 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004634 }
4635 return false;
4636 }
4637
Romain Guy06882f82009-06-10 13:36:04 -07004638 private boolean isSystemSecure() {
4639 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4640 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4641 }
4642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004643 /**
4644 * Stops the view server if it exists.
4645 *
4646 * @return True if the server stopped, false if it wasn't started or
4647 * couldn't be stopped.
4648 *
4649 * @see com.android.server.ViewServer
4650 */
4651 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004652 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 return false;
4654 }
4655
4656 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4657 return false;
4658 }
4659
4660 if (mViewServer != null) {
4661 return mViewServer.stop();
4662 }
4663 return false;
4664 }
4665
4666 /**
4667 * Indicates whether the view server is running.
4668 *
4669 * @return True if the server is running, false otherwise.
4670 *
4671 * @see com.android.server.ViewServer
4672 */
4673 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004674 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004675 return false;
4676 }
4677
4678 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4679 return false;
4680 }
4681
4682 return mViewServer != null && mViewServer.isRunning();
4683 }
4684
4685 /**
4686 * Lists all availble windows in the system. The listing is written in the
4687 * specified Socket's output stream with the following syntax:
4688 * windowHashCodeInHexadecimal windowName
4689 * Each line of the ouput represents a different window.
4690 *
4691 * @param client The remote client to send the listing to.
4692 * @return False if an error occured, true otherwise.
4693 */
4694 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004695 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 return false;
4697 }
4698
4699 boolean result = true;
4700
Jeff Browne33348b2010-07-15 23:54:05 -07004701 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004703 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004704 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004705 }
4706
4707 BufferedWriter out = null;
4708
4709 // Any uncaught exception will crash the system process
4710 try {
4711 OutputStream clientStream = client.getOutputStream();
4712 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4713
4714 final int count = windows.length;
4715 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004716 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 out.write(Integer.toHexString(System.identityHashCode(w)));
4718 out.write(' ');
4719 out.append(w.mAttrs.getTitle());
4720 out.write('\n');
4721 }
4722
4723 out.write("DONE.\n");
4724 out.flush();
4725 } catch (Exception e) {
4726 result = false;
4727 } finally {
4728 if (out != null) {
4729 try {
4730 out.close();
4731 } catch (IOException e) {
4732 result = false;
4733 }
4734 }
4735 }
4736
4737 return result;
4738 }
4739
4740 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004741 * Returns the focused window in the following format:
4742 * windowHashCodeInHexadecimal windowName
4743 *
4744 * @param client The remote client to send the listing to.
4745 * @return False if an error occurred, true otherwise.
4746 */
4747 boolean viewServerGetFocusedWindow(Socket client) {
4748 if (isSystemSecure()) {
4749 return false;
4750 }
4751
4752 boolean result = true;
4753
4754 WindowState focusedWindow = getFocusedWindow();
4755
4756 BufferedWriter out = null;
4757
4758 // Any uncaught exception will crash the system process
4759 try {
4760 OutputStream clientStream = client.getOutputStream();
4761 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4762
4763 if(focusedWindow != null) {
4764 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4765 out.write(' ');
4766 out.append(focusedWindow.mAttrs.getTitle());
4767 }
4768 out.write('\n');
4769 out.flush();
4770 } catch (Exception e) {
4771 result = false;
4772 } finally {
4773 if (out != null) {
4774 try {
4775 out.close();
4776 } catch (IOException e) {
4777 result = false;
4778 }
4779 }
4780 }
4781
4782 return result;
4783 }
4784
4785 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004786 * Sends a command to a target window. The result of the command, if any, will be
4787 * written in the output stream of the specified socket.
4788 *
4789 * The parameters must follow this syntax:
4790 * windowHashcode extra
4791 *
4792 * Where XX is the length in characeters of the windowTitle.
4793 *
4794 * The first parameter is the target window. The window with the specified hashcode
4795 * will be the target. If no target can be found, nothing happens. The extra parameters
4796 * will be delivered to the target window and as parameters to the command itself.
4797 *
4798 * @param client The remote client to sent the result, if any, to.
4799 * @param command The command to execute.
4800 * @param parameters The command parameters.
4801 *
4802 * @return True if the command was successfully delivered, false otherwise. This does
4803 * not indicate whether the command itself was successful.
4804 */
4805 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004806 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 return false;
4808 }
4809
4810 boolean success = true;
4811 Parcel data = null;
4812 Parcel reply = null;
4813
4814 // Any uncaught exception will crash the system process
4815 try {
4816 // Find the hashcode of the window
4817 int index = parameters.indexOf(' ');
4818 if (index == -1) {
4819 index = parameters.length();
4820 }
4821 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004822 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823
4824 // Extract the command's parameter after the window description
4825 if (index < parameters.length()) {
4826 parameters = parameters.substring(index + 1);
4827 } else {
4828 parameters = "";
4829 }
4830
4831 final WindowManagerService.WindowState window = findWindow(hashCode);
4832 if (window == null) {
4833 return false;
4834 }
4835
4836 data = Parcel.obtain();
4837 data.writeInterfaceToken("android.view.IWindow");
4838 data.writeString(command);
4839 data.writeString(parameters);
4840 data.writeInt(1);
4841 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4842
4843 reply = Parcel.obtain();
4844
4845 final IBinder binder = window.mClient.asBinder();
4846 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4847 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4848
4849 reply.readException();
4850
4851 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004852 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 success = false;
4854 } finally {
4855 if (data != null) {
4856 data.recycle();
4857 }
4858 if (reply != null) {
4859 reply.recycle();
4860 }
4861 }
4862
4863 return success;
4864 }
4865
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004866 public void addWindowChangeListener(WindowChangeListener listener) {
4867 synchronized(mWindowMap) {
4868 mWindowChangeListeners.add(listener);
4869 }
4870 }
4871
4872 public void removeWindowChangeListener(WindowChangeListener listener) {
4873 synchronized(mWindowMap) {
4874 mWindowChangeListeners.remove(listener);
4875 }
4876 }
4877
4878 private void notifyWindowsChanged() {
4879 WindowChangeListener[] windowChangeListeners;
4880 synchronized(mWindowMap) {
4881 if(mWindowChangeListeners.isEmpty()) {
4882 return;
4883 }
4884 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4885 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4886 }
4887 int N = windowChangeListeners.length;
4888 for(int i = 0; i < N; i++) {
4889 windowChangeListeners[i].windowsChanged();
4890 }
4891 }
4892
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004893 private void notifyFocusChanged() {
4894 WindowChangeListener[] windowChangeListeners;
4895 synchronized(mWindowMap) {
4896 if(mWindowChangeListeners.isEmpty()) {
4897 return;
4898 }
4899 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4900 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4901 }
4902 int N = windowChangeListeners.length;
4903 for(int i = 0; i < N; i++) {
4904 windowChangeListeners[i].focusChanged();
4905 }
4906 }
4907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004908 private WindowState findWindow(int hashCode) {
4909 if (hashCode == -1) {
4910 return getFocusedWindow();
4911 }
4912
4913 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004914 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 final int count = windows.size();
4916
4917 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004918 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 if (System.identityHashCode(w) == hashCode) {
4920 return w;
4921 }
4922 }
4923 }
4924
4925 return null;
4926 }
4927
4928 /*
4929 * Instruct the Activity Manager to fetch the current configuration and broadcast
4930 * that to config-changed listeners if appropriate.
4931 */
4932 void sendNewConfiguration() {
4933 try {
4934 mActivityManager.updateConfiguration(null);
4935 } catch (RemoteException e) {
4936 }
4937 }
Romain Guy06882f82009-06-10 13:36:04 -07004938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004939 public Configuration computeNewConfiguration() {
4940 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004941 return computeNewConfigurationLocked();
4942 }
4943 }
Romain Guy06882f82009-06-10 13:36:04 -07004944
Dianne Hackbornc485a602009-03-24 22:39:49 -07004945 Configuration computeNewConfigurationLocked() {
4946 Configuration config = new Configuration();
4947 if (!computeNewConfigurationLocked(config)) {
4948 return null;
4949 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004950 return config;
4951 }
Romain Guy06882f82009-06-10 13:36:04 -07004952
Dianne Hackbornc485a602009-03-24 22:39:49 -07004953 boolean computeNewConfigurationLocked(Configuration config) {
4954 if (mDisplay == null) {
4955 return false;
4956 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004957
4958 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004959
4960 // Use the effective "visual" dimensions based on current rotation
4961 final boolean rotated = (mRotation == Surface.ROTATION_90
4962 || mRotation == Surface.ROTATION_270);
4963 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4964 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4965
Dianne Hackbornc485a602009-03-24 22:39:49 -07004966 int orientation = Configuration.ORIENTATION_SQUARE;
4967 if (dw < dh) {
4968 orientation = Configuration.ORIENTATION_PORTRAIT;
4969 } else if (dw > dh) {
4970 orientation = Configuration.ORIENTATION_LANDSCAPE;
4971 }
4972 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004973
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004974 DisplayMetrics dm = new DisplayMetrics();
4975 mDisplay.getMetrics(dm);
4976 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4977
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004978 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004979 // Note we only do this once because at this point we don't
4980 // expect the screen to change in this way at runtime, and want
4981 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004982 int longSize = dw;
4983 int shortSize = dh;
4984 if (longSize < shortSize) {
4985 int tmp = longSize;
4986 longSize = shortSize;
4987 shortSize = tmp;
4988 }
4989 longSize = (int)(longSize/dm.density);
4990 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004991
Dianne Hackborn723738c2009-06-25 19:48:04 -07004992 // These semi-magic numbers define our compatibility modes for
4993 // applications with different screens. Don't change unless you
4994 // make sure to test lots and lots of apps!
4995 if (longSize < 470) {
4996 // This is shorter than an HVGA normal density screen (which
4997 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004998 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4999 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005000 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005001 // What size is this screen screen?
5002 if (longSize >= 800 && shortSize >= 600) {
5003 // SVGA or larger screens at medium density are the point
5004 // at which we consider it to be an extra large screen.
5005 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5006 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005007 // VGA or larger screens at medium density are the point
5008 // at which we consider it to be a large screen.
5009 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5010 } else {
5011 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005012
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005013 // If this screen is wider than normal HVGA, or taller
5014 // than FWVGA, then for old apps we want to run in size
5015 // compatibility mode.
5016 if (shortSize > 321 || longSize > 570) {
5017 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5018 }
5019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005020
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005021 // Is this a long screen?
5022 if (((longSize*3)/5) >= (shortSize-1)) {
5023 // Anything wider than WVGA (5:3) is considering to be long.
5024 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5025 } else {
5026 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5027 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005028 }
5029 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005030 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005031
Dianne Hackbornc485a602009-03-24 22:39:49 -07005032 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5033 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5034 mPolicy.adjustConfigurationLw(config);
5035 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005036 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005038 // -------------------------------------------------------------
5039 // Input Events and Focus Management
5040 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005041
Jeff Brown349703e2010-06-22 01:27:15 -07005042 InputMonitor mInputMonitor = new InputMonitor();
5043
5044 /* Tracks the progress of input dispatch and ensures that input dispatch state
5045 * is kept in sync with changes in window focus, visibility, registration, and
5046 * other relevant Window Manager state transitions. */
5047 final class InputMonitor {
5048 // Current window with input focus for keys and other non-touch events. May be null.
5049 private WindowState mInputFocus;
5050
5051 // When true, prevents input dispatch from proceeding until set to false again.
5052 private boolean mInputDispatchFrozen;
5053
5054 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5055 private boolean mInputDispatchEnabled = true;
5056
5057 // Temporary list of windows information to provide to the input dispatcher.
5058 private InputWindowList mTempInputWindows = new InputWindowList();
5059
5060 // Temporary input application object to provide to the input dispatcher.
5061 private InputApplication mTempInputApplication = new InputApplication();
5062
5063 /* Notifies the window manager about a broken input channel.
5064 *
5065 * Called by the InputManager.
5066 */
5067 public void notifyInputChannelBroken(InputChannel inputChannel) {
5068 synchronized (mWindowMap) {
5069 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5070 if (windowState == null) {
5071 return; // irrelevant
5072 }
5073
5074 Slog.i(TAG, "WINDOW DIED " + windowState);
5075 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005076 }
5077 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005078
Jeff Brown349703e2010-06-22 01:27:15 -07005079 /* Notifies the window manager about an input channel that is not responding.
5080 * The method can either cause dispatching to be aborted by returning -2 or
5081 * return a new timeout in nanoseconds.
5082 *
5083 * Called by the InputManager.
5084 */
5085 public long notifyInputChannelANR(InputChannel inputChannel) {
5086 AppWindowToken token;
5087 synchronized (mWindowMap) {
5088 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5089 if (windowState == null) {
5090 return -2; // irrelevant, abort dispatching (-2)
5091 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005092
Jeff Brown349703e2010-06-22 01:27:15 -07005093 Slog.i(TAG, "Input event dispatching timed out sending to "
5094 + windowState.mAttrs.getTitle());
5095 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005096 }
5097
Jeff Brown349703e2010-06-22 01:27:15 -07005098 return notifyANRInternal(token);
5099 }
5100
5101 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5102 * by successfully delivering the event that originally timed out.
5103 *
5104 * Called by the InputManager.
5105 */
5106 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5107 // Nothing to do just now.
5108 // Just wait for the user to dismiss the ANR dialog.
5109 }
5110
5111 /* Notifies the window manager about an application that is not responding
5112 * in general rather than with respect to a particular input channel.
5113 * The method can either cause dispatching to be aborted by returning -2 or
5114 * return a new timeout in nanoseconds.
5115 *
5116 * Called by the InputManager.
5117 */
5118 public long notifyANR(Object token) {
5119 AppWindowToken appWindowToken = (AppWindowToken) token;
5120
5121 Slog.i(TAG, "Input event dispatching timed out sending to application "
5122 + appWindowToken.stringName);
5123 return notifyANRInternal(appWindowToken);
5124 }
5125
5126 private long notifyANRInternal(AppWindowToken token) {
5127 if (token != null && token.appToken != null) {
5128 try {
5129 // Notify the activity manager about the timeout and let it decide whether
5130 // to abort dispatching or keep waiting.
5131 boolean abort = token.appToken.keyDispatchingTimedOut();
5132 if (! abort) {
5133 // The activity manager declined to abort dispatching.
5134 // Wait a bit longer and timeout again later.
5135 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005136 }
Jeff Brown349703e2010-06-22 01:27:15 -07005137 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005138 }
5139 }
Jeff Brown349703e2010-06-22 01:27:15 -07005140 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005141 }
5142
Jeff Brown349703e2010-06-22 01:27:15 -07005143 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5144 synchronized (mWindowMap) {
5145 return getWindowStateForInputChannelLocked(inputChannel);
5146 }
5147 }
5148
5149 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5150 int windowCount = mWindows.size();
5151 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005152 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005153 if (windowState.mInputChannel == inputChannel) {
5154 return windowState;
5155 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005156 }
5157
Jeff Brown349703e2010-06-22 01:27:15 -07005158 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005159 }
5160
Jeff Brown349703e2010-06-22 01:27:15 -07005161 /* Updates the cached window information provided to the input dispatcher. */
5162 public void updateInputWindowsLw() {
5163 // Populate the input window list with information about all of the windows that
5164 // could potentially receive input.
5165 // As an optimization, we could try to prune the list of windows but this turns
5166 // out to be difficult because only the native code knows for sure which window
5167 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005168 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005169 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005170 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005171 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005172 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005173 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005174 continue;
5175 }
5176
Jeff Brown349703e2010-06-22 01:27:15 -07005177 final int flags = child.mAttrs.flags;
5178 final int type = child.mAttrs.type;
5179
5180 final boolean hasFocus = (child == mInputFocus);
5181 final boolean isVisible = child.isVisibleLw();
5182 final boolean hasWallpaper = (child == mWallpaperTarget)
5183 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5184
5185 // Add a window to our list of input windows.
5186 final InputWindow inputWindow = mTempInputWindows.add();
5187 inputWindow.inputChannel = child.mInputChannel;
5188 inputWindow.layoutParamsFlags = flags;
5189 inputWindow.layoutParamsType = type;
5190 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5191 inputWindow.visible = isVisible;
5192 inputWindow.hasFocus = hasFocus;
5193 inputWindow.hasWallpaper = hasWallpaper;
5194 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5195 inputWindow.ownerPid = child.mSession.mPid;
5196 inputWindow.ownerUid = child.mSession.mUid;
5197
5198 final Rect frame = child.mFrame;
5199 inputWindow.frameLeft = frame.left;
5200 inputWindow.frameTop = frame.top;
5201
5202 switch (child.mTouchableInsets) {
5203 default:
5204 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5205 inputWindow.touchableAreaLeft = frame.left;
5206 inputWindow.touchableAreaTop = frame.top;
5207 inputWindow.touchableAreaRight = frame.right;
5208 inputWindow.touchableAreaBottom = frame.bottom;
5209 break;
5210
5211 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5212 Rect inset = child.mGivenContentInsets;
5213 inputWindow.touchableAreaLeft = frame.left + inset.left;
5214 inputWindow.touchableAreaTop = frame.top + inset.top;
5215 inputWindow.touchableAreaRight = frame.right - inset.right;
5216 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5217 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005218 }
Jeff Brown349703e2010-06-22 01:27:15 -07005219
5220 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5221 Rect inset = child.mGivenVisibleInsets;
5222 inputWindow.touchableAreaLeft = frame.left + inset.left;
5223 inputWindow.touchableAreaTop = frame.top + inset.top;
5224 inputWindow.touchableAreaRight = frame.right - inset.right;
5225 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005226 break;
5227 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005228 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005229 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005230
Jeff Brown349703e2010-06-22 01:27:15 -07005231 // Send windows to native code.
5232 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005233
Jeff Brown349703e2010-06-22 01:27:15 -07005234 // Clear the list in preparation for the next round.
5235 // Also avoids keeping InputChannel objects referenced unnecessarily.
5236 mTempInputWindows.clear();
5237 }
5238
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005239 /* Provides feedback for a virtual key down. */
5240 public void virtualKeyDownFeedback() {
5241 synchronized (mWindowMap) {
5242 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5243 }
5244 }
5245
Jeff Brown349703e2010-06-22 01:27:15 -07005246 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5247 * This essentially starts a .5 second timeout for the application to process
5248 * subsequent input events while waiting for the app switch to occur. If it takes longer
5249 * than this, the pending events will be dropped.
5250 */
5251 public void notifyAppSwitchComing() {
5252 // TODO Not implemented yet. Should go in the native side.
5253 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005254
5255 /* Notifies that the lid switch changed state. */
5256 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5257 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5258 }
5259
Jeff Brown349703e2010-06-22 01:27:15 -07005260 /* Provides an opportunity for the window manager policy to intercept early key
5261 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005262 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5263 int policyFlags, boolean isScreenOn) {
5264 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5265 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005266 }
5267
5268 /* Provides an opportunity for the window manager policy to process a key before
5269 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005270 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5271 int action, int flags, int keyCode, int metaState, int repeatCount,
5272 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005273 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005274 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5275 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005276 }
5277
5278 /* Called when the current input focus changes.
5279 * Layer assignment is assumed to be complete by the time this is called.
5280 */
5281 public void setInputFocusLw(WindowState newWindow) {
5282 if (DEBUG_INPUT) {
5283 Slog.d(TAG, "Input focus has changed to " + newWindow);
5284 }
5285
5286 if (newWindow != mInputFocus) {
5287 if (newWindow != null && newWindow.canReceiveKeys()) {
5288 // If the new input focus is an error window or appears above the current
5289 // input focus, preempt any pending synchronous dispatch so that we can
5290 // start delivering events to the new input focus as soon as possible.
5291 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5292 if (DEBUG_INPUT) {
5293 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005294 }
Jeff Brown349703e2010-06-22 01:27:15 -07005295 preemptInputDispatchLw();
5296 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5297 if (DEBUG_INPUT) {
5298 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5299 + "old win layer=" + mInputFocus.mLayer
5300 + ", new win layer=" + newWindow.mLayer);
5301 }
5302 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005303 }
Jeff Brown349703e2010-06-22 01:27:15 -07005304
5305 // Displaying a window implicitly causes dispatching to be unpaused.
5306 // This is to protect against bugs if someone pauses dispatching but
5307 // forgets to resume.
5308 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005309 }
Jeff Brown349703e2010-06-22 01:27:15 -07005310
5311 mInputFocus = newWindow;
5312 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005313 }
5314 }
5315
Jeff Brown349703e2010-06-22 01:27:15 -07005316 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5317 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5318 * can begin.
5319 */
5320 private void preemptInputDispatchLw() {
5321 mInputManager.preemptInputDispatch();
5322 }
5323
5324 public void setFocusedAppLw(AppWindowToken newApp) {
5325 // Focused app has changed.
5326 if (newApp == null) {
5327 mInputManager.setFocusedApplication(null);
5328 } else {
5329 mTempInputApplication.name = newApp.toString();
5330 mTempInputApplication.dispatchingTimeoutNanos =
5331 newApp.inputDispatchingTimeoutNanos;
5332 mTempInputApplication.token = newApp;
5333
5334 mInputManager.setFocusedApplication(mTempInputApplication);
5335 }
5336 }
5337
Jeff Brown349703e2010-06-22 01:27:15 -07005338 public void pauseDispatchingLw(WindowToken window) {
5339 if (! window.paused) {
5340 if (DEBUG_INPUT) {
5341 Slog.v(TAG, "Pausing WindowToken " + window);
5342 }
5343
5344 window.paused = true;
5345 updateInputWindowsLw();
5346 }
5347 }
5348
5349 public void resumeDispatchingLw(WindowToken window) {
5350 if (window.paused) {
5351 if (DEBUG_INPUT) {
5352 Slog.v(TAG, "Resuming WindowToken " + window);
5353 }
5354
5355 window.paused = false;
5356 updateInputWindowsLw();
5357 }
5358 }
5359
5360 public void freezeInputDispatchingLw() {
5361 if (! mInputDispatchFrozen) {
5362 if (DEBUG_INPUT) {
5363 Slog.v(TAG, "Freezing input dispatching");
5364 }
5365
5366 mInputDispatchFrozen = true;
5367 updateInputDispatchModeLw();
5368 }
5369 }
5370
5371 public void thawInputDispatchingLw() {
5372 if (mInputDispatchFrozen) {
5373 if (DEBUG_INPUT) {
5374 Slog.v(TAG, "Thawing input dispatching");
5375 }
5376
5377 mInputDispatchFrozen = false;
5378 updateInputDispatchModeLw();
5379 }
5380 }
5381
5382 public void setEventDispatchingLw(boolean enabled) {
5383 if (mInputDispatchEnabled != enabled) {
5384 if (DEBUG_INPUT) {
5385 Slog.v(TAG, "Setting event dispatching to " + enabled);
5386 }
5387
5388 mInputDispatchEnabled = enabled;
5389 updateInputDispatchModeLw();
5390 }
5391 }
5392
5393 private void updateInputDispatchModeLw() {
5394 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5395 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005398 public void pauseKeyDispatching(IBinder _token) {
5399 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5400 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005401 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005402 }
5403
5404 synchronized (mWindowMap) {
5405 WindowToken token = mTokenMap.get(_token);
5406 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005407 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005408 }
5409 }
5410 }
5411
5412 public void resumeKeyDispatching(IBinder _token) {
5413 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5414 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005415 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005416 }
5417
5418 synchronized (mWindowMap) {
5419 WindowToken token = mTokenMap.get(_token);
5420 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005421 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005422 }
5423 }
5424 }
5425
5426 public void setEventDispatching(boolean enabled) {
5427 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5428 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005429 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005430 }
5431
5432 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005433 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005434 }
5435 }
Romain Guy06882f82009-06-10 13:36:04 -07005436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005437 /**
5438 * Injects a keystroke event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005439 * Even when sync is false, this method may block while waiting for current
5440 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005441 *
5442 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005443 * {@link SystemClock#uptimeMillis()} as the timebase.)
5444 * @param sync If true, wait for the event to be completed before returning to the caller.
5445 * @return Returns true if event was dispatched, false if it was dropped for any reason
5446 */
5447 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5448 long downTime = ev.getDownTime();
5449 long eventTime = ev.getEventTime();
5450
5451 int action = ev.getAction();
5452 int code = ev.getKeyCode();
5453 int repeatCount = ev.getRepeatCount();
5454 int metaState = ev.getMetaState();
5455 int deviceId = ev.getDeviceId();
5456 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005457 int source = ev.getSource();
5458
5459 if (source == InputDevice.SOURCE_UNKNOWN) {
5460 source = InputDevice.SOURCE_KEYBOARD;
5461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005462
5463 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5464 if (downTime == 0) downTime = eventTime;
5465
5466 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005467 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005468
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005469 final int pid = Binder.getCallingPid();
5470 final int uid = Binder.getCallingUid();
5471 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005472
Jeff Brown6ec402b2010-07-28 15:48:59 -07005473 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5474 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5475 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5476 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005477
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005478 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005479 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005480 }
5481
5482 /**
5483 * Inject a pointer (touch) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005484 * Even when sync is false, this method may block while waiting for current
5485 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005486 *
5487 * @param ev A motion event describing the pointer (touch) action. (As noted in
5488 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005489 * {@link SystemClock#uptimeMillis()} as the timebase.)
5490 * @param sync If true, wait for the event to be completed before returning to the caller.
5491 * @return Returns true if event was dispatched, false if it was dropped for any reason
5492 */
5493 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005494 final int pid = Binder.getCallingPid();
5495 final int uid = Binder.getCallingUid();
5496 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005497
Jeff Brownc5ed5912010-07-14 18:48:53 -07005498 MotionEvent newEvent = MotionEvent.obtain(ev);
5499 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5500 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5501 }
5502
Jeff Brown6ec402b2010-07-28 15:48:59 -07005503 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5504 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5505 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5506 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005507
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005508 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005509 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005510 }
Romain Guy06882f82009-06-10 13:36:04 -07005511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005512 /**
5513 * Inject a trackball (navigation device) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005514 * Even when sync is false, this method may block while waiting for current
5515 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005516 *
5517 * @param ev A motion event describing the trackball action. (As noted in
5518 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005519 * {@link SystemClock#uptimeMillis()} as the timebase.)
5520 * @param sync If true, wait for the event to be completed before returning to the caller.
5521 * @return Returns true if event was dispatched, false if it was dropped for any reason
5522 */
5523 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005524 final int pid = Binder.getCallingPid();
5525 final int uid = Binder.getCallingUid();
5526 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005527
Jeff Brownc5ed5912010-07-14 18:48:53 -07005528 MotionEvent newEvent = MotionEvent.obtain(ev);
5529 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5530 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5531 }
5532
Jeff Brown6ec402b2010-07-28 15:48:59 -07005533 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5534 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5535 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5536 INJECTION_TIMEOUT_MILLIS);
5537
5538 Binder.restoreCallingIdentity(ident);
5539 return reportInjectionResult(result);
5540 }
5541
5542 /**
5543 * Inject an input event into the UI without waiting for dispatch to commence.
5544 * This variant is useful for fire-and-forget input event injection. It does not
5545 * block any longer than it takes to enqueue the input event.
5546 *
5547 * @param ev An input event. (Be sure to set the input source correctly.)
5548 * @return Returns true if event was dispatched, false if it was dropped for any reason
5549 */
5550 public boolean injectInputEventNoWait(InputEvent ev) {
5551 final int pid = Binder.getCallingPid();
5552 final int uid = Binder.getCallingUid();
5553 final long ident = Binder.clearCallingIdentity();
5554
5555 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5556 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5557 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005558
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005559 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005560 return reportInjectionResult(result);
5561 }
5562
5563 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005564 switch (result) {
5565 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5566 Slog.w(TAG, "Input event injection permission denied.");
5567 throw new SecurityException(
5568 "Injecting to another application requires INJECT_EVENTS permission");
5569 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005570 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005571 return true;
5572 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5573 Slog.w(TAG, "Input event injection timed out.");
5574 return false;
5575 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5576 default:
5577 Slog.w(TAG, "Input event injection failed.");
5578 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005580 }
Romain Guy06882f82009-06-10 13:36:04 -07005581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005582 private WindowState getFocusedWindow() {
5583 synchronized (mWindowMap) {
5584 return getFocusedWindowLocked();
5585 }
5586 }
5587
5588 private WindowState getFocusedWindowLocked() {
5589 return mCurrentFocus;
5590 }
Romain Guy06882f82009-06-10 13:36:04 -07005591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005592 public boolean detectSafeMode() {
5593 mSafeMode = mPolicy.detectSafeMode();
5594 return mSafeMode;
5595 }
Romain Guy06882f82009-06-10 13:36:04 -07005596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005597 public void systemReady() {
5598 mPolicy.systemReady();
5599 }
Romain Guy06882f82009-06-10 13:36:04 -07005600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005601 // -------------------------------------------------------------
5602 // Client Session State
5603 // -------------------------------------------------------------
5604
5605 private final class Session extends IWindowSession.Stub
5606 implements IBinder.DeathRecipient {
5607 final IInputMethodClient mClient;
5608 final IInputContext mInputContext;
5609 final int mUid;
5610 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005611 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005612 SurfaceSession mSurfaceSession;
5613 int mNumWindow = 0;
5614 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616 public Session(IInputMethodClient client, IInputContext inputContext) {
5617 mClient = client;
5618 mInputContext = inputContext;
5619 mUid = Binder.getCallingUid();
5620 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005621 StringBuilder sb = new StringBuilder();
5622 sb.append("Session{");
5623 sb.append(Integer.toHexString(System.identityHashCode(this)));
5624 sb.append(" uid ");
5625 sb.append(mUid);
5626 sb.append("}");
5627 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005629 synchronized (mWindowMap) {
5630 if (mInputMethodManager == null && mHaveInputMethods) {
5631 IBinder b = ServiceManager.getService(
5632 Context.INPUT_METHOD_SERVICE);
5633 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5634 }
5635 }
5636 long ident = Binder.clearCallingIdentity();
5637 try {
5638 // Note: it is safe to call in to the input method manager
5639 // here because we are not holding our lock.
5640 if (mInputMethodManager != null) {
5641 mInputMethodManager.addClient(client, inputContext,
5642 mUid, mPid);
5643 } else {
5644 client.setUsingInputMethod(false);
5645 }
5646 client.asBinder().linkToDeath(this, 0);
5647 } catch (RemoteException e) {
5648 // The caller has died, so we can just forget about this.
5649 try {
5650 if (mInputMethodManager != null) {
5651 mInputMethodManager.removeClient(client);
5652 }
5653 } catch (RemoteException ee) {
5654 }
5655 } finally {
5656 Binder.restoreCallingIdentity(ident);
5657 }
5658 }
Romain Guy06882f82009-06-10 13:36:04 -07005659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005660 @Override
5661 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5662 throws RemoteException {
5663 try {
5664 return super.onTransact(code, data, reply, flags);
5665 } catch (RuntimeException e) {
5666 // Log all 'real' exceptions thrown to the caller
5667 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005668 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005669 }
5670 throw e;
5671 }
5672 }
5673
5674 public void binderDied() {
5675 // Note: it is safe to call in to the input method manager
5676 // here because we are not holding our lock.
5677 try {
5678 if (mInputMethodManager != null) {
5679 mInputMethodManager.removeClient(mClient);
5680 }
5681 } catch (RemoteException e) {
5682 }
5683 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005684 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005685 mClientDead = true;
5686 killSessionLocked();
5687 }
5688 }
5689
5690 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005691 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5692 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5693 outInputChannel);
5694 }
5695
5696 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005697 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005698 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005699 }
Romain Guy06882f82009-06-10 13:36:04 -07005700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005701 public void remove(IWindow window) {
5702 removeWindow(this, window);
5703 }
Romain Guy06882f82009-06-10 13:36:04 -07005704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005705 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5706 int requestedWidth, int requestedHeight, int viewFlags,
5707 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005708 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005709 return relayoutWindow(this, window, attrs,
5710 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005711 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005712 }
Romain Guy06882f82009-06-10 13:36:04 -07005713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005714 public void setTransparentRegion(IWindow window, Region region) {
5715 setTransparentRegionWindow(this, window, region);
5716 }
Romain Guy06882f82009-06-10 13:36:04 -07005717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005718 public void setInsets(IWindow window, int touchableInsets,
5719 Rect contentInsets, Rect visibleInsets) {
5720 setInsetsWindow(this, window, touchableInsets, contentInsets,
5721 visibleInsets);
5722 }
Romain Guy06882f82009-06-10 13:36:04 -07005723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005724 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5725 getWindowDisplayFrame(this, window, outDisplayFrame);
5726 }
Romain Guy06882f82009-06-10 13:36:04 -07005727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005728 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005729 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005730 TAG, "IWindow finishDrawing called for " + window);
5731 finishDrawingWindow(this, window);
5732 }
5733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005734 public void setInTouchMode(boolean mode) {
5735 synchronized(mWindowMap) {
5736 mInTouchMode = mode;
5737 }
5738 }
5739
5740 public boolean getInTouchMode() {
5741 synchronized(mWindowMap) {
5742 return mInTouchMode;
5743 }
5744 }
5745
5746 public boolean performHapticFeedback(IWindow window, int effectId,
5747 boolean always) {
5748 synchronized(mWindowMap) {
5749 long ident = Binder.clearCallingIdentity();
5750 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005751 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005752 windowForClientLocked(this, window, true),
5753 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005754 } finally {
5755 Binder.restoreCallingIdentity(ident);
5756 }
5757 }
5758 }
Romain Guy06882f82009-06-10 13:36:04 -07005759
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005760 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005761 synchronized(mWindowMap) {
5762 long ident = Binder.clearCallingIdentity();
5763 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005764 setWindowWallpaperPositionLocked(
5765 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005766 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005767 } finally {
5768 Binder.restoreCallingIdentity(ident);
5769 }
5770 }
5771 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005772
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005773 public void wallpaperOffsetsComplete(IBinder window) {
5774 WindowManagerService.this.wallpaperOffsetsComplete(window);
5775 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005776
Dianne Hackborn75804932009-10-20 20:15:20 -07005777 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5778 int z, Bundle extras, boolean sync) {
5779 synchronized(mWindowMap) {
5780 long ident = Binder.clearCallingIdentity();
5781 try {
5782 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005783 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005784 action, x, y, z, extras, sync);
5785 } finally {
5786 Binder.restoreCallingIdentity(ident);
5787 }
5788 }
5789 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005790
Dianne Hackborn75804932009-10-20 20:15:20 -07005791 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5792 WindowManagerService.this.wallpaperCommandComplete(window, result);
5793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005795 void windowAddedLocked() {
5796 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005797 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005798 TAG, "First window added to " + this + ", creating SurfaceSession");
5799 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005800 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005801 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005802 mSessions.add(this);
5803 }
5804 mNumWindow++;
5805 }
5806
5807 void windowRemovedLocked() {
5808 mNumWindow--;
5809 killSessionLocked();
5810 }
Romain Guy06882f82009-06-10 13:36:04 -07005811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005812 void killSessionLocked() {
5813 if (mNumWindow <= 0 && mClientDead) {
5814 mSessions.remove(this);
5815 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005816 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005817 TAG, "Last window removed from " + this
5818 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005819 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005820 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005821 try {
5822 mSurfaceSession.kill();
5823 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005824 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 + mSurfaceSession + " in session " + this
5826 + ": " + e.toString());
5827 }
5828 mSurfaceSession = null;
5829 }
5830 }
5831 }
Romain Guy06882f82009-06-10 13:36:04 -07005832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005833 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005834 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5835 pw.print(" mClientDead="); pw.print(mClientDead);
5836 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 }
5838
5839 @Override
5840 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005841 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005842 }
5843 }
5844
5845 // -------------------------------------------------------------
5846 // Client Window State
5847 // -------------------------------------------------------------
5848
5849 private final class WindowState implements WindowManagerPolicy.WindowState {
5850 final Session mSession;
5851 final IWindow mClient;
5852 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005853 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005854 AppWindowToken mAppToken;
5855 AppWindowToken mTargetAppToken;
5856 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5857 final DeathRecipient mDeathRecipient;
5858 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005859 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005860 final int mBaseLayer;
5861 final int mSubLayer;
5862 final boolean mLayoutAttached;
5863 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005864 final boolean mIsWallpaper;
5865 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005866 int mViewVisibility;
5867 boolean mPolicyVisibility = true;
5868 boolean mPolicyVisibilityAfterAnim = true;
5869 boolean mAppFreezing;
5870 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005871 boolean mReportDestroySurface;
5872 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005873 boolean mAttachedHidden; // is our parent window hidden?
5874 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005875 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005876 int mRequestedWidth;
5877 int mRequestedHeight;
5878 int mLastRequestedWidth;
5879 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 int mLayer;
5881 int mAnimLayer;
5882 int mLastLayer;
5883 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005884 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005885 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005887 int mLayoutSeq = -1;
5888
5889 Configuration mConfiguration = null;
5890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005891 // Actual frame shown on-screen (may be modified by animation)
5892 final Rect mShownFrame = new Rect();
5893 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005895 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005896 * Set when we have changed the size of the surface, to know that
5897 * we must tell them application to resize (and thus redraw itself).
5898 */
5899 boolean mSurfaceResized;
5900
5901 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902 * Insets that determine the actually visible area
5903 */
5904 final Rect mVisibleInsets = new Rect();
5905 final Rect mLastVisibleInsets = new Rect();
5906 boolean mVisibleInsetsChanged;
5907
5908 /**
5909 * Insets that are covered by system windows
5910 */
5911 final Rect mContentInsets = new Rect();
5912 final Rect mLastContentInsets = new Rect();
5913 boolean mContentInsetsChanged;
5914
5915 /**
5916 * Set to true if we are waiting for this window to receive its
5917 * given internal insets before laying out other windows based on it.
5918 */
5919 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005921 /**
5922 * These are the content insets that were given during layout for
5923 * this window, to be applied to windows behind it.
5924 */
5925 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 /**
5928 * These are the visible insets that were given during layout for
5929 * this window, to be applied to windows behind it.
5930 */
5931 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005933 /**
5934 * Flag indicating whether the touchable region should be adjusted by
5935 * the visible insets; if false the area outside the visible insets is
5936 * NOT touchable, so we must use those to adjust the frame during hit
5937 * tests.
5938 */
5939 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005941 // Current transformation being applied.
5942 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5943 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5944 float mHScale=1, mVScale=1;
5945 float mLastHScale=1, mLastVScale=1;
5946 final Matrix mTmpMatrix = new Matrix();
5947
5948 // "Real" frame that the application sees.
5949 final Rect mFrame = new Rect();
5950 final Rect mLastFrame = new Rect();
5951
5952 final Rect mContainingFrame = new Rect();
5953 final Rect mDisplayFrame = new Rect();
5954 final Rect mContentFrame = new Rect();
5955 final Rect mVisibleFrame = new Rect();
5956
5957 float mShownAlpha = 1;
5958 float mAlpha = 1;
5959 float mLastAlpha = 1;
5960
5961 // Set to true if, when the window gets displayed, it should perform
5962 // an enter animation.
5963 boolean mEnterAnimationPending;
5964
5965 // Currently running animation.
5966 boolean mAnimating;
5967 boolean mLocalAnimating;
5968 Animation mAnimation;
5969 boolean mAnimationIsEntrance;
5970 boolean mHasTransformation;
5971 boolean mHasLocalTransformation;
5972 final Transformation mTransformation = new Transformation();
5973
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005974 // If a window showing a wallpaper: the requested offset for the
5975 // wallpaper; if a wallpaper window: the currently applied offset.
5976 float mWallpaperX = -1;
5977 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005978
5979 // If a window showing a wallpaper: what fraction of the offset
5980 // range corresponds to a full virtual screen.
5981 float mWallpaperXStep = -1;
5982 float mWallpaperYStep = -1;
5983
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005984 // Wallpaper windows: pixels offset based on above variables.
5985 int mXOffset;
5986 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005988 // This is set after IWindowSession.relayout() has been called at
5989 // least once for the window. It allows us to detect the situation
5990 // where we don't yet have a surface, but should have one soon, so
5991 // we can give the window focus before waiting for the relayout.
5992 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005994 // This is set after the Surface has been created but before the
5995 // window has been drawn. During this time the surface is hidden.
5996 boolean mDrawPending;
5997
5998 // This is set after the window has finished drawing for the first
5999 // time but before its surface is shown. The surface will be
6000 // displayed when the next layout is run.
6001 boolean mCommitDrawPending;
6002
6003 // This is set during the time after the window's drawing has been
6004 // committed, and before its surface is actually shown. It is used
6005 // to delay showing the surface until all windows in a token are ready
6006 // to be shown.
6007 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006009 // Set when the window has been shown in the screen the first time.
6010 boolean mHasDrawn;
6011
6012 // Currently running an exit animation?
6013 boolean mExiting;
6014
6015 // Currently on the mDestroySurface list?
6016 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006018 // Completely remove from window manager after exit animation?
6019 boolean mRemoveOnExit;
6020
6021 // Set when the orientation is changing and this window has not yet
6022 // been updated for the new orientation.
6023 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006025 // Is this window now (or just being) removed?
6026 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006027
Dianne Hackborn16064f92010-03-25 00:47:24 -07006028 // For debugging, this is the last information given to the surface flinger.
6029 boolean mSurfaceShown;
6030 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6031 int mSurfaceLayer;
6032 float mSurfaceAlpha;
6033
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006034 // Input channel
6035 InputChannel mInputChannel;
6036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006037 WindowState(Session s, IWindow c, WindowToken token,
6038 WindowState attachedWindow, WindowManager.LayoutParams a,
6039 int viewVisibility) {
6040 mSession = s;
6041 mClient = c;
6042 mToken = token;
6043 mAttrs.copyFrom(a);
6044 mViewVisibility = viewVisibility;
6045 DeathRecipient deathRecipient = new DeathRecipient();
6046 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006047 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006048 TAG, "Window " + this + " client=" + c.asBinder()
6049 + " token=" + token + " (" + mAttrs.token + ")");
6050 try {
6051 c.asBinder().linkToDeath(deathRecipient, 0);
6052 } catch (RemoteException e) {
6053 mDeathRecipient = null;
6054 mAttachedWindow = null;
6055 mLayoutAttached = false;
6056 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006057 mIsWallpaper = false;
6058 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006059 mBaseLayer = 0;
6060 mSubLayer = 0;
6061 return;
6062 }
6063 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006065 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6066 mAttrs.type <= LAST_SUB_WINDOW)) {
6067 // The multiplier here is to reserve space for multiple
6068 // windows in the same type layer.
6069 mBaseLayer = mPolicy.windowTypeToLayerLw(
6070 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6071 + TYPE_LAYER_OFFSET;
6072 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6073 mAttachedWindow = attachedWindow;
6074 mAttachedWindow.mChildWindows.add(this);
6075 mLayoutAttached = mAttrs.type !=
6076 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6077 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6078 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006079 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6080 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006081 } else {
6082 // The multiplier here is to reserve space for multiple
6083 // windows in the same type layer.
6084 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6085 * TYPE_LAYER_MULTIPLIER
6086 + TYPE_LAYER_OFFSET;
6087 mSubLayer = 0;
6088 mAttachedWindow = null;
6089 mLayoutAttached = false;
6090 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6091 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006092 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6093 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006094 }
6095
6096 WindowState appWin = this;
6097 while (appWin.mAttachedWindow != null) {
6098 appWin = mAttachedWindow;
6099 }
6100 WindowToken appToken = appWin.mToken;
6101 while (appToken.appWindowToken == null) {
6102 WindowToken parent = mTokenMap.get(appToken.token);
6103 if (parent == null || appToken == parent) {
6104 break;
6105 }
6106 appToken = parent;
6107 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006108 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006109 mAppToken = appToken.appWindowToken;
6110
6111 mSurface = null;
6112 mRequestedWidth = 0;
6113 mRequestedHeight = 0;
6114 mLastRequestedWidth = 0;
6115 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006116 mXOffset = 0;
6117 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 mLayer = 0;
6119 mAnimLayer = 0;
6120 mLastLayer = 0;
6121 }
6122
6123 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006124 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006125 TAG, "Attaching " + this + " token=" + mToken
6126 + ", list=" + mToken.windows);
6127 mSession.windowAddedLocked();
6128 }
6129
6130 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6131 mHaveFrame = true;
6132
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006133 final Rect container = mContainingFrame;
6134 container.set(pf);
6135
6136 final Rect display = mDisplayFrame;
6137 display.set(df);
6138
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006139 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006140 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006141 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6142 display.intersect(mCompatibleScreenFrame);
6143 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006144 }
6145
6146 final int pw = container.right - container.left;
6147 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148
6149 int w,h;
6150 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6151 w = mAttrs.width < 0 ? pw : mAttrs.width;
6152 h = mAttrs.height< 0 ? ph : mAttrs.height;
6153 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006154 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6155 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006156 }
Romain Guy06882f82009-06-10 13:36:04 -07006157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006158 final Rect content = mContentFrame;
6159 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006161 final Rect visible = mVisibleFrame;
6162 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006165 final int fw = frame.width();
6166 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6169 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6170
6171 Gravity.apply(mAttrs.gravity, w, h, container,
6172 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6173 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6174
6175 //System.out.println("Out: " + mFrame);
6176
6177 // Now make sure the window fits in the overall display.
6178 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006180 // Make sure the content and visible frames are inside of the
6181 // final window frame.
6182 if (content.left < frame.left) content.left = frame.left;
6183 if (content.top < frame.top) content.top = frame.top;
6184 if (content.right > frame.right) content.right = frame.right;
6185 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6186 if (visible.left < frame.left) visible.left = frame.left;
6187 if (visible.top < frame.top) visible.top = frame.top;
6188 if (visible.right > frame.right) visible.right = frame.right;
6189 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191 final Rect contentInsets = mContentInsets;
6192 contentInsets.left = content.left-frame.left;
6193 contentInsets.top = content.top-frame.top;
6194 contentInsets.right = frame.right-content.right;
6195 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006197 final Rect visibleInsets = mVisibleInsets;
6198 visibleInsets.left = visible.left-frame.left;
6199 visibleInsets.top = visible.top-frame.top;
6200 visibleInsets.right = frame.right-visible.right;
6201 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006202
Dianne Hackborn284ac932009-08-28 10:34:25 -07006203 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6204 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006205 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006206 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006208 if (localLOGV) {
6209 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6210 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006211 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006212 + mRequestedWidth + ", mRequestedheight="
6213 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6214 + "): frame=" + mFrame.toShortString()
6215 + " ci=" + contentInsets.toShortString()
6216 + " vi=" + visibleInsets.toShortString());
6217 //}
6218 }
6219 }
Romain Guy06882f82009-06-10 13:36:04 -07006220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006221 public Rect getFrameLw() {
6222 return mFrame;
6223 }
6224
6225 public Rect getShownFrameLw() {
6226 return mShownFrame;
6227 }
6228
6229 public Rect getDisplayFrameLw() {
6230 return mDisplayFrame;
6231 }
6232
6233 public Rect getContentFrameLw() {
6234 return mContentFrame;
6235 }
6236
6237 public Rect getVisibleFrameLw() {
6238 return mVisibleFrame;
6239 }
6240
6241 public boolean getGivenInsetsPendingLw() {
6242 return mGivenInsetsPending;
6243 }
6244
6245 public Rect getGivenContentInsetsLw() {
6246 return mGivenContentInsets;
6247 }
Romain Guy06882f82009-06-10 13:36:04 -07006248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006249 public Rect getGivenVisibleInsetsLw() {
6250 return mGivenVisibleInsets;
6251 }
Romain Guy06882f82009-06-10 13:36:04 -07006252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006253 public WindowManager.LayoutParams getAttrs() {
6254 return mAttrs;
6255 }
6256
6257 public int getSurfaceLayer() {
6258 return mLayer;
6259 }
Romain Guy06882f82009-06-10 13:36:04 -07006260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006261 public IApplicationToken getAppToken() {
6262 return mAppToken != null ? mAppToken.appToken : null;
6263 }
Jeff Brown349703e2010-06-22 01:27:15 -07006264
6265 public long getInputDispatchingTimeoutNanos() {
6266 return mAppToken != null
6267 ? mAppToken.inputDispatchingTimeoutNanos
6268 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270
6271 public boolean hasAppShownWindows() {
6272 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6273 }
6274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006275 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006276 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277 TAG, "Setting animation in " + this + ": " + anim);
6278 mAnimating = false;
6279 mLocalAnimating = false;
6280 mAnimation = anim;
6281 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6282 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6283 }
6284
6285 public void clearAnimation() {
6286 if (mAnimation != null) {
6287 mAnimating = true;
6288 mLocalAnimating = false;
6289 mAnimation = null;
6290 }
6291 }
Romain Guy06882f82009-06-10 13:36:04 -07006292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006293 Surface createSurfaceLocked() {
6294 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006295 mReportDestroySurface = false;
6296 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 mDrawPending = true;
6298 mCommitDrawPending = false;
6299 mReadyToShow = false;
6300 if (mAppToken != null) {
6301 mAppToken.allDrawn = false;
6302 }
6303
6304 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006305 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306 flags |= Surface.PUSH_BUFFERS;
6307 }
6308
6309 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6310 flags |= Surface.SECURE;
6311 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006312 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 TAG, "Creating surface in session "
6314 + mSession.mSurfaceSession + " window " + this
6315 + " w=" + mFrame.width()
6316 + " h=" + mFrame.height() + " format="
6317 + mAttrs.format + " flags=" + flags);
6318
6319 int w = mFrame.width();
6320 int h = mFrame.height();
6321 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6322 // for a scaled surface, we always want the requested
6323 // size.
6324 w = mRequestedWidth;
6325 h = mRequestedHeight;
6326 }
6327
Romain Guy9825ec62009-10-01 00:58:09 -07006328 // Something is wrong and SurfaceFlinger will not like this,
6329 // try to revert to sane values
6330 if (w <= 0) w = 1;
6331 if (h <= 0) h = 1;
6332
Dianne Hackborn16064f92010-03-25 00:47:24 -07006333 mSurfaceShown = false;
6334 mSurfaceLayer = 0;
6335 mSurfaceAlpha = 1;
6336 mSurfaceX = 0;
6337 mSurfaceY = 0;
6338 mSurfaceW = w;
6339 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006340 try {
6341 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006342 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006343 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006344 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006345 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006346 + mSurface + " IN SESSION "
6347 + mSession.mSurfaceSession
6348 + ": pid=" + mSession.mPid + " format="
6349 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006350 + Integer.toHexString(flags)
6351 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006353 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 reclaimSomeSurfaceMemoryLocked(this, "create");
6355 return null;
6356 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006357 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006358 return null;
6359 }
Romain Guy06882f82009-06-10 13:36:04 -07006360
Joe Onorato8a9b2202010-02-26 18:56:32 -08006361 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006362 TAG, "Got surface: " + mSurface
6363 + ", set left=" + mFrame.left + " top=" + mFrame.top
6364 + ", animLayer=" + mAnimLayer);
6365 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006366 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006367 if (SHOW_TRANSACTIONS) logSurface(this,
6368 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6369 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6370 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006371 }
6372 Surface.openTransaction();
6373 try {
6374 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006375 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006376 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006377 mSurface.setPosition(mSurfaceX, mSurfaceY);
6378 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006380 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006381 mSurface.hide();
6382 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006383 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006384 mSurface.setFlags(Surface.SURFACE_DITHER,
6385 Surface.SURFACE_DITHER);
6386 }
6387 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006388 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6390 }
6391 mLastHidden = true;
6392 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006393 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 Surface.closeTransaction();
6395 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006396 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 TAG, "Created surface " + this);
6398 }
6399 return mSurface;
6400 }
Romain Guy06882f82009-06-10 13:36:04 -07006401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006403 if (mAppToken != null && this == mAppToken.startingWindow) {
6404 mAppToken.startingDisplayed = false;
6405 }
Romain Guy06882f82009-06-10 13:36:04 -07006406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006407 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006408 mDrawPending = false;
6409 mCommitDrawPending = false;
6410 mReadyToShow = false;
6411
6412 int i = mChildWindows.size();
6413 while (i > 0) {
6414 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006415 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006416 c.mAttachedHidden = true;
6417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006418
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006419 if (mReportDestroySurface) {
6420 mReportDestroySurface = false;
6421 mSurfacePendingDestroy = true;
6422 try {
6423 mClient.dispatchGetNewSurface();
6424 // We'll really destroy on the next time around.
6425 return;
6426 } catch (RemoteException e) {
6427 }
6428 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006430 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006431 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006432 RuntimeException e = null;
6433 if (!HIDE_STACK_CRAWLS) {
6434 e = new RuntimeException();
6435 e.fillInStackTrace();
6436 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006437 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006438 + mSurface + ", session " + mSession, e);
6439 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006441 RuntimeException e = null;
6442 if (!HIDE_STACK_CRAWLS) {
6443 e = new RuntimeException();
6444 e.fillInStackTrace();
6445 }
6446 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006447 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006448 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006449 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006450 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451 + " surface " + mSurface + " session " + mSession
6452 + ": " + e.toString());
6453 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006454
Dianne Hackborn16064f92010-03-25 00:47:24 -07006455 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006457 }
6458 }
6459
6460 boolean finishDrawingLocked() {
6461 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006462 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006463 TAG, "finishDrawingLocked: " + mSurface);
6464 mCommitDrawPending = true;
6465 mDrawPending = false;
6466 return true;
6467 }
6468 return false;
6469 }
6470
6471 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006472 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006473 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006475 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 }
6477 mCommitDrawPending = false;
6478 mReadyToShow = true;
6479 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6480 final AppWindowToken atoken = mAppToken;
6481 if (atoken == null || atoken.allDrawn || starting) {
6482 performShowLocked();
6483 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006484 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006485 }
6486
6487 // This must be called while inside a transaction.
6488 boolean performShowLocked() {
6489 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006490 RuntimeException e = null;
6491 if (!HIDE_STACK_CRAWLS) {
6492 e = new RuntimeException();
6493 e.fillInStackTrace();
6494 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006495 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6497 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6498 }
6499 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006500 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6501 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006502 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 + " during animation: policyVis=" + mPolicyVisibility
6504 + " attHidden=" + mAttachedHidden
6505 + " tok.hiddenRequested="
6506 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006507 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 + (mAppToken != null ? mAppToken.hidden : false)
6509 + " animating=" + mAnimating
6510 + " tok animating="
6511 + (mAppToken != null ? mAppToken.animating : false));
6512 if (!showSurfaceRobustlyLocked(this)) {
6513 return false;
6514 }
6515 mLastAlpha = -1;
6516 mHasDrawn = true;
6517 mLastHidden = false;
6518 mReadyToShow = false;
6519 enableScreenIfNeededLocked();
6520
6521 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006523 int i = mChildWindows.size();
6524 while (i > 0) {
6525 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006526 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006527 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006528 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006529 if (c.mSurface != null) {
6530 c.performShowLocked();
6531 // It hadn't been shown, which means layout not
6532 // performed on it, so now we want to make sure to
6533 // do a layout. If called from within the transaction
6534 // loop, this will cause it to restart with a new
6535 // layout.
6536 mLayoutNeeded = true;
6537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006538 }
6539 }
Romain Guy06882f82009-06-10 13:36:04 -07006540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006541 if (mAttrs.type != TYPE_APPLICATION_STARTING
6542 && mAppToken != null) {
6543 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006544
Dianne Hackborn248b1882009-09-16 16:46:44 -07006545 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006546 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006547 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006549 // If this initial window is animating, stop it -- we
6550 // will do an animation to reveal it from behind the
6551 // starting window, so there is no need for it to also
6552 // be doing its own stuff.
6553 if (mAnimation != null) {
6554 mAnimation = null;
6555 // Make sure we clean up the animation.
6556 mAnimating = true;
6557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 mFinishedStarting.add(mAppToken);
6559 mH.sendEmptyMessage(H.FINISHED_STARTING);
6560 }
6561 mAppToken.updateReportedVisibilityLocked();
6562 }
6563 }
6564 return true;
6565 }
Romain Guy06882f82009-06-10 13:36:04 -07006566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 // This must be called while inside a transaction. Returns true if
6568 // there is more animation to run.
6569 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006570 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6574 mHasTransformation = true;
6575 mHasLocalTransformation = true;
6576 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006577 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006578 TAG, "Starting animation in " + this +
6579 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6580 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6581 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6582 mAnimation.setStartTime(currentTime);
6583 mLocalAnimating = true;
6584 mAnimating = true;
6585 }
6586 mTransformation.clear();
6587 final boolean more = mAnimation.getTransformation(
6588 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006589 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 TAG, "Stepped animation in " + this +
6591 ": more=" + more + ", xform=" + mTransformation);
6592 if (more) {
6593 // we're not done!
6594 return true;
6595 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006596 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 TAG, "Finished animation in " + this +
6598 " @ " + currentTime);
6599 mAnimation = null;
6600 //WindowManagerService.this.dump();
6601 }
6602 mHasLocalTransformation = false;
6603 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006604 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006605 // When our app token is animating, we kind-of pretend like
6606 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6607 // part of this check means that we will only do this if
6608 // our window is not currently exiting, or it is not
6609 // locally animating itself. The idea being that one that
6610 // is exiting and doing a local animation should be removed
6611 // once that animation is done.
6612 mAnimating = true;
6613 mHasTransformation = true;
6614 mTransformation.clear();
6615 return false;
6616 } else if (mHasTransformation) {
6617 // Little trick to get through the path below to act like
6618 // we have finished an animation.
6619 mAnimating = true;
6620 } else if (isAnimating()) {
6621 mAnimating = true;
6622 }
6623 } else if (mAnimation != null) {
6624 // If the display is frozen, and there is a pending animation,
6625 // clear it and make sure we run the cleanup code.
6626 mAnimating = true;
6627 mLocalAnimating = true;
6628 mAnimation = null;
6629 }
Romain Guy06882f82009-06-10 13:36:04 -07006630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006631 if (!mAnimating && !mLocalAnimating) {
6632 return false;
6633 }
6634
Joe Onorato8a9b2202010-02-26 18:56:32 -08006635 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006636 TAG, "Animation done in " + this + ": exiting=" + mExiting
6637 + ", reportedVisible="
6638 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 mAnimating = false;
6641 mLocalAnimating = false;
6642 mAnimation = null;
6643 mAnimLayer = mLayer;
6644 if (mIsImWindow) {
6645 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006646 } else if (mIsWallpaper) {
6647 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006648 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006649 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006650 + " anim layer: " + mAnimLayer);
6651 mHasTransformation = false;
6652 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006653 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6654 if (DEBUG_VISIBILITY) {
6655 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6656 + mPolicyVisibilityAfterAnim);
6657 }
6658 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6659 if (!mPolicyVisibility) {
6660 if (mCurrentFocus == this) {
6661 mFocusMayChange = true;
6662 }
6663 // Window is no longer visible -- make sure if we were waiting
6664 // for it to be displayed before enabling the display, that
6665 // we allow the display to be enabled now.
6666 enableScreenIfNeededLocked();
6667 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006669 mTransformation.clear();
6670 if (mHasDrawn
6671 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6672 && mAppToken != null
6673 && mAppToken.firstWindowDrawn
6674 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006675 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 + mToken + ": first real window done animating");
6677 mFinishedStarting.add(mAppToken);
6678 mH.sendEmptyMessage(H.FINISHED_STARTING);
6679 }
Romain Guy06882f82009-06-10 13:36:04 -07006680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006681 finishExit();
6682
6683 if (mAppToken != null) {
6684 mAppToken.updateReportedVisibilityLocked();
6685 }
6686
6687 return false;
6688 }
6689
6690 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006691 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006692 TAG, "finishExit in " + this
6693 + ": exiting=" + mExiting
6694 + " remove=" + mRemoveOnExit
6695 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006697 final int N = mChildWindows.size();
6698 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006699 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006700 }
Romain Guy06882f82009-06-10 13:36:04 -07006701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 if (!mExiting) {
6703 return;
6704 }
Romain Guy06882f82009-06-10 13:36:04 -07006705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 if (isWindowAnimating()) {
6707 return;
6708 }
6709
Joe Onorato8a9b2202010-02-26 18:56:32 -08006710 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006711 TAG, "Exit animation finished in " + this
6712 + ": remove=" + mRemoveOnExit);
6713 if (mSurface != null) {
6714 mDestroySurface.add(this);
6715 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006716 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006717 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006718 try {
6719 mSurface.hide();
6720 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006721 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 }
6723 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006724 }
6725 mExiting = false;
6726 if (mRemoveOnExit) {
6727 mPendingRemove.add(this);
6728 mRemoveOnExit = false;
6729 }
6730 }
Romain Guy06882f82009-06-10 13:36:04 -07006731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6733 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6734 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6735 if (dtdx < -.000001f || dtdx > .000001f) return false;
6736 if (dsdy < -.000001f || dsdy > .000001f) return false;
6737 return true;
6738 }
Romain Guy06882f82009-06-10 13:36:04 -07006739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006740 void computeShownFrameLocked() {
6741 final boolean selfTransformation = mHasLocalTransformation;
6742 Transformation attachedTransformation =
6743 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6744 ? mAttachedWindow.mTransformation : null;
6745 Transformation appTransformation =
6746 (mAppToken != null && mAppToken.hasTransformation)
6747 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006748
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006749 // Wallpapers are animated based on the "real" window they
6750 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006751 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006752 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006753 if (mWallpaperTarget.mHasLocalTransformation &&
6754 mWallpaperTarget.mAnimation != null &&
6755 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006756 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006757 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006758 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006759 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006760 }
6761 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006762 mWallpaperTarget.mAppToken.hasTransformation &&
6763 mWallpaperTarget.mAppToken.animation != null &&
6764 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006765 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006766 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006767 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006768 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006769 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006770 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 if (selfTransformation || attachedTransformation != null
6773 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006774 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006775 final Rect frame = mFrame;
6776 final float tmpFloats[] = mTmpFloats;
6777 final Matrix tmpMatrix = mTmpMatrix;
6778
6779 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006780 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006781 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006782 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006783 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006784 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006785 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006786 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006787 }
6788 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006789 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006790 }
6791
6792 // "convert" it into SurfaceFlinger's format
6793 // (a 2x2 matrix + an offset)
6794 // Here we must not transform the position of the surface
6795 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006796 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 tmpMatrix.getValues(tmpFloats);
6799 mDsDx = tmpFloats[Matrix.MSCALE_X];
6800 mDtDx = tmpFloats[Matrix.MSKEW_X];
6801 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6802 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006803 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6804 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006805 int w = frame.width();
6806 int h = frame.height();
6807 mShownFrame.set(x, y, x+w, y+h);
6808
6809 // Now set the alpha... but because our current hardware
6810 // can't do alpha transformation on a non-opaque surface,
6811 // turn it off if we are running an animation that is also
6812 // transforming since it is more important to have that
6813 // animation be smooth.
6814 mShownAlpha = mAlpha;
6815 if (!mLimitedAlphaCompositing
6816 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6817 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6818 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006819 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006820 if (selfTransformation) {
6821 mShownAlpha *= mTransformation.getAlpha();
6822 }
6823 if (attachedTransformation != null) {
6824 mShownAlpha *= attachedTransformation.getAlpha();
6825 }
6826 if (appTransformation != null) {
6827 mShownAlpha *= appTransformation.getAlpha();
6828 }
6829 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006830 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831 }
Romain Guy06882f82009-06-10 13:36:04 -07006832
Joe Onorato8a9b2202010-02-26 18:56:32 -08006833 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 TAG, "Continuing animation in " + this +
6835 ": " + mShownFrame +
6836 ", alpha=" + mTransformation.getAlpha());
6837 return;
6838 }
Romain Guy06882f82009-06-10 13:36:04 -07006839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006841 if (mXOffset != 0 || mYOffset != 0) {
6842 mShownFrame.offset(mXOffset, mYOffset);
6843 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006844 mShownAlpha = mAlpha;
6845 mDsDx = 1;
6846 mDtDx = 0;
6847 mDsDy = 0;
6848 mDtDy = 1;
6849 }
Romain Guy06882f82009-06-10 13:36:04 -07006850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851 /**
6852 * Is this window visible? It is not visible if there is no
6853 * surface, or we are in the process of running an exit animation
6854 * that will remove the surface, or its app token has been hidden.
6855 */
6856 public boolean isVisibleLw() {
6857 final AppWindowToken atoken = mAppToken;
6858 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6859 && (atoken == null || !atoken.hiddenRequested)
6860 && !mExiting && !mDestroying;
6861 }
6862
6863 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006864 * Like {@link #isVisibleLw}, but also counts a window that is currently
6865 * "hidden" behind the keyguard as visible. This allows us to apply
6866 * things like window flags that impact the keyguard.
6867 * XXX I am starting to think we need to have ANOTHER visibility flag
6868 * for this "hidden behind keyguard" state rather than overloading
6869 * mPolicyVisibility. Ungh.
6870 */
6871 public boolean isVisibleOrBehindKeyguardLw() {
6872 final AppWindowToken atoken = mAppToken;
6873 return mSurface != null && !mAttachedHidden
6874 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006875 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006876 && !mExiting && !mDestroying;
6877 }
6878
6879 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006880 * Is this window visible, ignoring its app token? It is not visible
6881 * if there is no surface, or we are in the process of running an exit animation
6882 * that will remove the surface.
6883 */
6884 public boolean isWinVisibleLw() {
6885 final AppWindowToken atoken = mAppToken;
6886 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6887 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6888 && !mExiting && !mDestroying;
6889 }
6890
6891 /**
6892 * The same as isVisible(), but follows the current hidden state of
6893 * the associated app token, not the pending requested hidden state.
6894 */
6895 boolean isVisibleNow() {
6896 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006897 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006898 }
6899
6900 /**
6901 * Same as isVisible(), but we also count it as visible between the
6902 * call to IWindowSession.add() and the first relayout().
6903 */
6904 boolean isVisibleOrAdding() {
6905 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006906 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006907 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6908 && mPolicyVisibility && !mAttachedHidden
6909 && (atoken == null || !atoken.hiddenRequested)
6910 && !mExiting && !mDestroying;
6911 }
6912
6913 /**
6914 * Is this window currently on-screen? It is on-screen either if it
6915 * is visible or it is currently running an animation before no longer
6916 * being visible.
6917 */
6918 boolean isOnScreen() {
6919 final AppWindowToken atoken = mAppToken;
6920 if (atoken != null) {
6921 return mSurface != null && mPolicyVisibility && !mDestroying
6922 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006923 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006924 } else {
6925 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006926 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006927 }
6928 }
Romain Guy06882f82009-06-10 13:36:04 -07006929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006930 /**
6931 * Like isOnScreen(), but we don't return true if the window is part
6932 * of a transition that has not yet been started.
6933 */
6934 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006935 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006936 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006937 return false;
6938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006940 final boolean animating = atoken != null
6941 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006942 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006943 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6944 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006945 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 }
6947
6948 /** Is the window or its container currently animating? */
6949 boolean isAnimating() {
6950 final WindowState attached = mAttachedWindow;
6951 final AppWindowToken atoken = mAppToken;
6952 return mAnimation != null
6953 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006954 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 (atoken.animation != null
6956 || atoken.inPendingTransaction));
6957 }
6958
6959 /** Is this window currently animating? */
6960 boolean isWindowAnimating() {
6961 return mAnimation != null;
6962 }
6963
6964 /**
6965 * Like isOnScreen, but returns false if the surface hasn't yet
6966 * been drawn.
6967 */
6968 public boolean isDisplayedLw() {
6969 final AppWindowToken atoken = mAppToken;
6970 return mSurface != null && mPolicyVisibility && !mDestroying
6971 && !mDrawPending && !mCommitDrawPending
6972 && ((!mAttachedHidden &&
6973 (atoken == null || !atoken.hiddenRequested))
6974 || mAnimating);
6975 }
6976
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006977 /**
6978 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006979 * complete UI in to. Note that this returns true if the orientation
6980 * is changing even if the window hasn't redrawn because we don't want
6981 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006982 */
6983 public boolean isDrawnLw() {
6984 final AppWindowToken atoken = mAppToken;
6985 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006986 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006987 }
6988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006989 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6990 boolean shownFrame, boolean onlyOpaque) {
6991 if (mSurface == null) {
6992 return false;
6993 }
6994 if (mAppToken != null && !mAppToken.appFullscreen) {
6995 return false;
6996 }
6997 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6998 return false;
6999 }
7000 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007001
7002 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7003 return frame.left <= mCompatibleScreenFrame.left &&
7004 frame.top <= mCompatibleScreenFrame.top &&
7005 frame.right >= mCompatibleScreenFrame.right &&
7006 frame.bottom >= mCompatibleScreenFrame.bottom;
7007 } else {
7008 return frame.left <= 0 && frame.top <= 0
7009 && frame.right >= screenWidth
7010 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 }
Romain Guy06882f82009-06-10 13:36:04 -07007013
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007014 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007015 * Return true if the window is opaque and fully drawn. This indicates
7016 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007017 */
7018 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007019 return (mAttrs.format == PixelFormat.OPAQUE
7020 || mAttrs.type == TYPE_WALLPAPER)
7021 && mSurface != null && mAnimation == null
7022 && (mAppToken == null || mAppToken.animation == null)
7023 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007024 }
7025
7026 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7027 return
7028 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007029 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7030 // only if it's visible
7031 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007032 // and only if the application fills the compatible screen
7033 mFrame.left <= mCompatibleScreenFrame.left &&
7034 mFrame.top <= mCompatibleScreenFrame.top &&
7035 mFrame.right >= mCompatibleScreenFrame.right &&
7036 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007037 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007038 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007039 }
7040
7041 boolean isFullscreen(int screenWidth, int screenHeight) {
7042 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007043 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044 }
7045
7046 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007047 disposeInputChannel();
7048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007049 if (mAttachedWindow != null) {
7050 mAttachedWindow.mChildWindows.remove(this);
7051 }
7052 destroySurfaceLocked();
7053 mSession.windowRemovedLocked();
7054 try {
7055 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7056 } catch (RuntimeException e) {
7057 // Ignore if it has already been removed (usually because
7058 // we are doing this as part of processing a death note.)
7059 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007060 }
7061
7062 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007063 if (mInputChannel != null) {
7064 mInputManager.unregisterInputChannel(mInputChannel);
7065
7066 mInputChannel.dispose();
7067 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007069 }
7070
7071 private class DeathRecipient implements IBinder.DeathRecipient {
7072 public void binderDied() {
7073 try {
7074 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007075 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007076 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007077 if (win != null) {
7078 removeWindowLocked(mSession, win);
7079 }
7080 }
7081 } catch (IllegalArgumentException ex) {
7082 // This will happen if the window has already been
7083 // removed.
7084 }
7085 }
7086 }
7087
7088 /** Returns true if this window desires key events. */
7089 public final boolean canReceiveKeys() {
7090 return isVisibleOrAdding()
7091 && (mViewVisibility == View.VISIBLE)
7092 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7093 }
7094
7095 public boolean hasDrawnLw() {
7096 return mHasDrawn;
7097 }
7098
7099 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007100 return showLw(doAnimation, true);
7101 }
7102
7103 boolean showLw(boolean doAnimation, boolean requestAnim) {
7104 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7105 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007107 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007108 if (doAnimation) {
7109 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7110 + mPolicyVisibility + " mAnimation=" + mAnimation);
7111 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7112 doAnimation = false;
7113 } else if (mPolicyVisibility && mAnimation == null) {
7114 // Check for the case where we are currently visible and
7115 // not animating; we do not want to do animation at such a
7116 // point to become visible when we already are.
7117 doAnimation = false;
7118 }
7119 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007120 mPolicyVisibility = true;
7121 mPolicyVisibilityAfterAnim = true;
7122 if (doAnimation) {
7123 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7124 }
7125 if (requestAnim) {
7126 requestAnimationLocked(0);
7127 }
7128 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007129 }
7130
7131 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007132 return hideLw(doAnimation, true);
7133 }
7134
7135 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007136 if (doAnimation) {
7137 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7138 doAnimation = false;
7139 }
7140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007141 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7142 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007143 if (!current) {
7144 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007145 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007146 if (doAnimation) {
7147 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7148 if (mAnimation == null) {
7149 doAnimation = false;
7150 }
7151 }
7152 if (doAnimation) {
7153 mPolicyVisibilityAfterAnim = false;
7154 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007155 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007156 mPolicyVisibilityAfterAnim = false;
7157 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007158 // Window is no longer visible -- make sure if we were waiting
7159 // for it to be displayed before enabling the display, that
7160 // we allow the display to be enabled now.
7161 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007162 if (mCurrentFocus == this) {
7163 mFocusMayChange = true;
7164 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007165 }
7166 if (requestAnim) {
7167 requestAnimationLocked(0);
7168 }
7169 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007170 }
7171
7172 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007173 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7174 pw.print(" mClient="); pw.println(mClient.asBinder());
7175 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7176 if (mAttachedWindow != null || mLayoutAttached) {
7177 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7178 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7179 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007180 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7181 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7182 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007183 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7184 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007185 }
7186 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7187 pw.print(" mSubLayer="); pw.print(mSubLayer);
7188 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7189 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7190 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7191 pw.print("="); pw.print(mAnimLayer);
7192 pw.print(" mLastLayer="); pw.println(mLastLayer);
7193 if (mSurface != null) {
7194 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007195 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7196 pw.print(" layer="); pw.print(mSurfaceLayer);
7197 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7198 pw.print(" rect=("); pw.print(mSurfaceX);
7199 pw.print(","); pw.print(mSurfaceY);
7200 pw.print(") "); pw.print(mSurfaceW);
7201 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007202 }
7203 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7204 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7205 if (mAppToken != null) {
7206 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7207 }
7208 if (mTargetAppToken != null) {
7209 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7210 }
7211 pw.print(prefix); pw.print("mViewVisibility=0x");
7212 pw.print(Integer.toHexString(mViewVisibility));
7213 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007214 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7215 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007216 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7217 pw.print(prefix); pw.print("mPolicyVisibility=");
7218 pw.print(mPolicyVisibility);
7219 pw.print(" mPolicyVisibilityAfterAnim=");
7220 pw.print(mPolicyVisibilityAfterAnim);
7221 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7222 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007223 if (!mRelayoutCalled) {
7224 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7225 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007226 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007227 pw.print(" h="); pw.print(mRequestedHeight);
7228 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007229 if (mXOffset != 0 || mYOffset != 0) {
7230 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7231 pw.print(" y="); pw.println(mYOffset);
7232 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007233 pw.print(prefix); pw.print("mGivenContentInsets=");
7234 mGivenContentInsets.printShortString(pw);
7235 pw.print(" mGivenVisibleInsets=");
7236 mGivenVisibleInsets.printShortString(pw);
7237 pw.println();
7238 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7239 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7240 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7241 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007242 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007243 pw.print(prefix); pw.print("mShownFrame=");
7244 mShownFrame.printShortString(pw);
7245 pw.print(" last="); mLastShownFrame.printShortString(pw);
7246 pw.println();
7247 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7248 pw.print(" last="); mLastFrame.printShortString(pw);
7249 pw.println();
7250 pw.print(prefix); pw.print("mContainingFrame=");
7251 mContainingFrame.printShortString(pw);
7252 pw.print(" mDisplayFrame=");
7253 mDisplayFrame.printShortString(pw);
7254 pw.println();
7255 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7256 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7257 pw.println();
7258 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7259 pw.print(" last="); mLastContentInsets.printShortString(pw);
7260 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7261 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7262 pw.println();
7263 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7264 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7265 pw.print(" mAlpha="); pw.print(mAlpha);
7266 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7267 }
7268 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7269 || mAnimation != null) {
7270 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7271 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7272 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7273 pw.print(" mAnimation="); pw.println(mAnimation);
7274 }
7275 if (mHasTransformation || mHasLocalTransformation) {
7276 pw.print(prefix); pw.print("XForm: has=");
7277 pw.print(mHasTransformation);
7278 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7279 pw.print(" "); mTransformation.printShortString(pw);
7280 pw.println();
7281 }
7282 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7283 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7284 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7285 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7286 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7287 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7288 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7289 pw.print(" mDestroying="); pw.print(mDestroying);
7290 pw.print(" mRemoved="); pw.println(mRemoved);
7291 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007292 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007293 pw.print(prefix); pw.print("mOrientationChanging=");
7294 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007295 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7296 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007297 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007298 if (mHScale != 1 || mVScale != 1) {
7299 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7300 pw.print(" mVScale="); pw.println(mVScale);
7301 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007302 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007303 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7304 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7305 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007306 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7307 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7308 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7309 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007311
7312 String makeInputChannelName() {
7313 return Integer.toHexString(System.identityHashCode(this))
7314 + " " + mAttrs.getTitle();
7315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316
7317 @Override
7318 public String toString() {
7319 return "Window{"
7320 + Integer.toHexString(System.identityHashCode(this))
7321 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7322 }
7323 }
Romain Guy06882f82009-06-10 13:36:04 -07007324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 // -------------------------------------------------------------
7326 // Window Token State
7327 // -------------------------------------------------------------
7328
7329 class WindowToken {
7330 // The actual token.
7331 final IBinder token;
7332
7333 // The type of window this token is for, as per WindowManager.LayoutParams.
7334 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 // Set if this token was explicitly added by a client, so should
7337 // not be removed when all windows are removed.
7338 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007339
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007340 // For printing.
7341 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 // If this is an AppWindowToken, this is non-null.
7344 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 // All of the windows associated with this token.
7347 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7348
7349 // Is key dispatching paused for this token?
7350 boolean paused = false;
7351
7352 // Should this token's windows be hidden?
7353 boolean hidden;
7354
7355 // Temporary for finding which tokens no longer have visible windows.
7356 boolean hasVisible;
7357
Dianne Hackborna8f60182009-09-01 19:01:50 -07007358 // Set to true when this token is in a pending transaction where it
7359 // will be shown.
7360 boolean waitingToShow;
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 it
7363 // will be hidden.
7364 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007365
Dianne Hackborna8f60182009-09-01 19:01:50 -07007366 // Set to true when this token is in a pending transaction where its
7367 // windows will be put to the bottom of the list.
7368 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007369
Dianne Hackborna8f60182009-09-01 19:01:50 -07007370 // Set to true when this token is in a pending transaction where its
7371 // windows will be put to the top of the list.
7372 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007374 WindowToken(IBinder _token, int type, boolean _explicit) {
7375 token = _token;
7376 windowType = type;
7377 explicit = _explicit;
7378 }
7379
7380 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007381 pw.print(prefix); pw.print("token="); pw.println(token);
7382 pw.print(prefix); pw.print("windows="); pw.println(windows);
7383 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7384 pw.print(" hidden="); pw.print(hidden);
7385 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007386 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7387 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7388 pw.print(" waitingToHide="); pw.print(waitingToHide);
7389 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7390 pw.print(" sendingToTop="); pw.println(sendingToTop);
7391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 }
7393
7394 @Override
7395 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007396 if (stringName == null) {
7397 StringBuilder sb = new StringBuilder();
7398 sb.append("WindowToken{");
7399 sb.append(Integer.toHexString(System.identityHashCode(this)));
7400 sb.append(" token="); sb.append(token); sb.append('}');
7401 stringName = sb.toString();
7402 }
7403 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 }
7405 };
7406
7407 class AppWindowToken extends WindowToken {
7408 // Non-null only for application tokens.
7409 final IApplicationToken appToken;
7410
7411 // All of the windows and child windows that are included in this
7412 // application token. Note this list is NOT sorted!
7413 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7414
7415 int groupId = -1;
7416 boolean appFullscreen;
7417 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007418
7419 // The input dispatching timeout for this application token in nanoseconds.
7420 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 // These are used for determining when all windows associated with
7423 // an activity have been drawn, so they can be made visible together
7424 // at the same time.
7425 int lastTransactionSequence = mTransactionSequence-1;
7426 int numInterestingWindows;
7427 int numDrawnWindows;
7428 boolean inPendingTransaction;
7429 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007431 // Is this token going to be hidden in a little while? If so, it
7432 // won't be taken into account for setting the screen orientation.
7433 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 // Is this window's surface needed? This is almost like hidden, except
7436 // it will sometimes be true a little earlier: when the token has
7437 // been shown, but is still waiting for its app transition to execute
7438 // before making its windows shown.
7439 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 // Have we told the window clients to hide themselves?
7442 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 // Last visibility state we reported to the app token.
7445 boolean reportedVisible;
7446
7447 // Set to true when the token has been removed from the window mgr.
7448 boolean removed;
7449
7450 // Have we been asked to have this token keep the screen frozen?
7451 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 boolean animating;
7454 Animation animation;
7455 boolean hasTransformation;
7456 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007458 // Offset to the window of all layers in the token, for use by
7459 // AppWindowToken animations.
7460 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007462 // Information about an application starting window if displayed.
7463 StartingData startingData;
7464 WindowState startingWindow;
7465 View startingView;
7466 boolean startingDisplayed;
7467 boolean startingMoved;
7468 boolean firstWindowDrawn;
7469
7470 AppWindowToken(IApplicationToken _token) {
7471 super(_token.asBinder(),
7472 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7473 appWindowToken = this;
7474 appToken = _token;
7475 }
Romain Guy06882f82009-06-10 13:36:04 -07007476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007478 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007479 TAG, "Setting animation in " + this + ": " + anim);
7480 animation = anim;
7481 animating = false;
7482 anim.restrictDuration(MAX_ANIMATION_DURATION);
7483 anim.scaleCurrentDuration(mTransitionAnimationScale);
7484 int zorder = anim.getZAdjustment();
7485 int adj = 0;
7486 if (zorder == Animation.ZORDER_TOP) {
7487 adj = TYPE_LAYER_OFFSET;
7488 } else if (zorder == Animation.ZORDER_BOTTOM) {
7489 adj = -TYPE_LAYER_OFFSET;
7490 }
Romain Guy06882f82009-06-10 13:36:04 -07007491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007492 if (animLayerAdjustment != adj) {
7493 animLayerAdjustment = adj;
7494 updateLayers();
7495 }
7496 }
Romain Guy06882f82009-06-10 13:36:04 -07007497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 public void setDummyAnimation() {
7499 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007500 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 TAG, "Setting dummy animation in " + this);
7502 animation = sDummyAnimation;
7503 }
7504 }
7505
7506 public void clearAnimation() {
7507 if (animation != null) {
7508 animation = null;
7509 animating = true;
7510 }
7511 }
Romain Guy06882f82009-06-10 13:36:04 -07007512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007513 void updateLayers() {
7514 final int N = allAppWindows.size();
7515 final int adj = animLayerAdjustment;
7516 for (int i=0; i<N; i++) {
7517 WindowState w = allAppWindows.get(i);
7518 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007519 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 + w.mAnimLayer);
7521 if (w == mInputMethodTarget) {
7522 setInputMethodAnimLayerAdjustment(adj);
7523 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007524 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007525 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 }
7528 }
Romain Guy06882f82009-06-10 13:36:04 -07007529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 void sendAppVisibilityToClients() {
7531 final int N = allAppWindows.size();
7532 for (int i=0; i<N; i++) {
7533 WindowState win = allAppWindows.get(i);
7534 if (win == startingWindow && clientHidden) {
7535 // Don't hide the starting window.
7536 continue;
7537 }
7538 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007539 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 "Setting visibility of " + win + ": " + (!clientHidden));
7541 win.mClient.dispatchAppVisibility(!clientHidden);
7542 } catch (RemoteException e) {
7543 }
7544 }
7545 }
Romain Guy06882f82009-06-10 13:36:04 -07007546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 void showAllWindowsLocked() {
7548 final int NW = allAppWindows.size();
7549 for (int i=0; i<NW; i++) {
7550 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007551 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007552 "performing show on: " + w);
7553 w.performShowLocked();
7554 }
7555 }
Romain Guy06882f82009-06-10 13:36:04 -07007556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 // This must be called while inside a transaction.
7558 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007559 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007560 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 if (animation == sDummyAnimation) {
7563 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007564 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 // when it is really time to animate, this will be set to
7566 // a real animation and the next call will execute normally.
7567 return false;
7568 }
Romain Guy06882f82009-06-10 13:36:04 -07007569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007570 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7571 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007572 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 TAG, "Starting animation in " + this +
7574 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7575 + " scale=" + mTransitionAnimationScale
7576 + " allDrawn=" + allDrawn + " animating=" + animating);
7577 animation.initialize(dw, dh, dw, dh);
7578 animation.setStartTime(currentTime);
7579 animating = true;
7580 }
7581 transformation.clear();
7582 final boolean more = animation.getTransformation(
7583 currentTime, transformation);
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, "Stepped animation in " + this +
7586 ": more=" + more + ", xform=" + transformation);
7587 if (more) {
7588 // we're done!
7589 hasTransformation = true;
7590 return true;
7591 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007592 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 TAG, "Finished animation in " + this +
7594 " @ " + currentTime);
7595 animation = null;
7596 }
7597 } else if (animation != null) {
7598 // If the display is frozen, and there is a pending animation,
7599 // clear it and make sure we run the cleanup code.
7600 animating = true;
7601 animation = null;
7602 }
7603
7604 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007606 if (!animating) {
7607 return false;
7608 }
7609
7610 clearAnimation();
7611 animating = false;
7612 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7613 moveInputMethodWindowsIfNeededLocked(true);
7614 }
Romain Guy06882f82009-06-10 13:36:04 -07007615
Joe Onorato8a9b2202010-02-26 18:56:32 -08007616 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 TAG, "Animation done in " + this
7618 + ": reportedVisible=" + reportedVisible);
7619
7620 transformation.clear();
7621 if (animLayerAdjustment != 0) {
7622 animLayerAdjustment = 0;
7623 updateLayers();
7624 }
Romain Guy06882f82009-06-10 13:36:04 -07007625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 final int N = windows.size();
7627 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007628 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 }
7630 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 return false;
7633 }
7634
7635 void updateReportedVisibilityLocked() {
7636 if (appToken == null) {
7637 return;
7638 }
Romain Guy06882f82009-06-10 13:36:04 -07007639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 int numInteresting = 0;
7641 int numVisible = 0;
7642 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007643
Joe Onorato8a9b2202010-02-26 18:56:32 -08007644 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007645 final int N = allAppWindows.size();
7646 for (int i=0; i<N; i++) {
7647 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007648 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007649 || win.mViewVisibility != View.VISIBLE
7650 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 continue;
7652 }
7653 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007654 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007655 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007656 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007657 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007658 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 + " pv=" + win.mPolicyVisibility
7660 + " dp=" + win.mDrawPending
7661 + " cdp=" + win.mCommitDrawPending
7662 + " ah=" + win.mAttachedHidden
7663 + " th="
7664 + (win.mAppToken != null
7665 ? win.mAppToken.hiddenRequested : false)
7666 + " a=" + win.mAnimating);
7667 }
7668 }
7669 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007670 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007671 if (!win.isAnimating()) {
7672 numVisible++;
7673 }
7674 nowGone = false;
7675 } else if (win.isAnimating()) {
7676 nowGone = false;
7677 }
7678 }
Romain Guy06882f82009-06-10 13:36:04 -07007679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007680 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007681 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007682 + numInteresting + " visible=" + numVisible);
7683 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007684 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 TAG, "Visibility changed in " + this
7686 + ": vis=" + nowVisible);
7687 reportedVisible = nowVisible;
7688 Message m = mH.obtainMessage(
7689 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7690 nowVisible ? 1 : 0,
7691 nowGone ? 1 : 0,
7692 this);
7693 mH.sendMessage(m);
7694 }
7695 }
Romain Guy06882f82009-06-10 13:36:04 -07007696
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007697 WindowState findMainWindow() {
7698 int j = windows.size();
7699 while (j > 0) {
7700 j--;
7701 WindowState win = windows.get(j);
7702 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7703 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7704 return win;
7705 }
7706 }
7707 return null;
7708 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007710 void dump(PrintWriter pw, String prefix) {
7711 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007712 if (appToken != null) {
7713 pw.print(prefix); pw.println("app=true");
7714 }
7715 if (allAppWindows.size() > 0) {
7716 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7717 }
7718 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007719 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007720 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7721 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7722 pw.print(" clientHidden="); pw.print(clientHidden);
7723 pw.print(" willBeHidden="); pw.print(willBeHidden);
7724 pw.print(" reportedVisible="); pw.println(reportedVisible);
7725 if (paused || freezingScreen) {
7726 pw.print(prefix); pw.print("paused="); pw.print(paused);
7727 pw.print(" freezingScreen="); pw.println(freezingScreen);
7728 }
7729 if (numInterestingWindows != 0 || numDrawnWindows != 0
7730 || inPendingTransaction || allDrawn) {
7731 pw.print(prefix); pw.print("numInterestingWindows=");
7732 pw.print(numInterestingWindows);
7733 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7734 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7735 pw.print(" allDrawn="); pw.println(allDrawn);
7736 }
7737 if (animating || animation != null) {
7738 pw.print(prefix); pw.print("animating="); pw.print(animating);
7739 pw.print(" animation="); pw.println(animation);
7740 }
7741 if (animLayerAdjustment != 0) {
7742 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7743 }
7744 if (hasTransformation) {
7745 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7746 pw.print(" transformation="); transformation.printShortString(pw);
7747 pw.println();
7748 }
7749 if (startingData != null || removed || firstWindowDrawn) {
7750 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7751 pw.print(" removed="); pw.print(removed);
7752 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7753 }
7754 if (startingWindow != null || startingView != null
7755 || startingDisplayed || startingMoved) {
7756 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7757 pw.print(" startingView="); pw.print(startingView);
7758 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7759 pw.print(" startingMoved"); pw.println(startingMoved);
7760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 }
7762
7763 @Override
7764 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007765 if (stringName == null) {
7766 StringBuilder sb = new StringBuilder();
7767 sb.append("AppWindowToken{");
7768 sb.append(Integer.toHexString(System.identityHashCode(this)));
7769 sb.append(" token="); sb.append(token); sb.append('}');
7770 stringName = sb.toString();
7771 }
7772 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007773 }
7774 }
Romain Guy06882f82009-06-10 13:36:04 -07007775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 // -------------------------------------------------------------
7777 // DummyAnimation
7778 // -------------------------------------------------------------
7779
7780 // This is an animation that does nothing: it just immediately finishes
7781 // itself every time it is called. It is used as a stub animation in cases
7782 // where we want to synchronize multiple things that may be animating.
7783 static final class DummyAnimation extends Animation {
7784 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7785 return false;
7786 }
7787 }
7788 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 // -------------------------------------------------------------
7791 // Async Handler
7792 // -------------------------------------------------------------
7793
7794 static final class StartingData {
7795 final String pkg;
7796 final int theme;
7797 final CharSequence nonLocalizedLabel;
7798 final int labelRes;
7799 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007801 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7802 int _labelRes, int _icon) {
7803 pkg = _pkg;
7804 theme = _theme;
7805 nonLocalizedLabel = _nonLocalizedLabel;
7806 labelRes = _labelRes;
7807 icon = _icon;
7808 }
7809 }
7810
7811 private final class H extends Handler {
7812 public static final int REPORT_FOCUS_CHANGE = 2;
7813 public static final int REPORT_LOSING_FOCUS = 3;
7814 public static final int ANIMATE = 4;
7815 public static final int ADD_STARTING = 5;
7816 public static final int REMOVE_STARTING = 6;
7817 public static final int FINISHED_STARTING = 7;
7818 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007819 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7820 public static final int HOLD_SCREEN_CHANGED = 12;
7821 public static final int APP_TRANSITION_TIMEOUT = 13;
7822 public static final int PERSIST_ANIMATION_SCALE = 14;
7823 public static final int FORCE_GC = 15;
7824 public static final int ENABLE_SCREEN = 16;
7825 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007826 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007827 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007829 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007831 public H() {
7832 }
Romain Guy06882f82009-06-10 13:36:04 -07007833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007834 @Override
7835 public void handleMessage(Message msg) {
7836 switch (msg.what) {
7837 case REPORT_FOCUS_CHANGE: {
7838 WindowState lastFocus;
7839 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007841 synchronized(mWindowMap) {
7842 lastFocus = mLastFocus;
7843 newFocus = mCurrentFocus;
7844 if (lastFocus == newFocus) {
7845 // Focus is not changing, so nothing to do.
7846 return;
7847 }
7848 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007849 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007850 // + " to " + newFocus);
7851 if (newFocus != null && lastFocus != null
7852 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007853 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007854 mLosingFocus.add(lastFocus);
7855 lastFocus = null;
7856 }
7857 }
7858
7859 if (lastFocus != newFocus) {
7860 //System.out.println("Changing focus from " + lastFocus
7861 // + " to " + newFocus);
7862 if (newFocus != null) {
7863 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007864 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007865 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7866 } catch (RemoteException e) {
7867 // Ignore if process has died.
7868 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007869 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 }
7871
7872 if (lastFocus != null) {
7873 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007874 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007875 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7876 } catch (RemoteException e) {
7877 // Ignore if process has died.
7878 }
7879 }
7880 }
7881 } break;
7882
7883 case REPORT_LOSING_FOCUS: {
7884 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 synchronized(mWindowMap) {
7887 losers = mLosingFocus;
7888 mLosingFocus = new ArrayList<WindowState>();
7889 }
7890
7891 final int N = losers.size();
7892 for (int i=0; i<N; i++) {
7893 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007894 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7896 } catch (RemoteException e) {
7897 // Ignore if process has died.
7898 }
7899 }
7900 } break;
7901
7902 case ANIMATE: {
7903 synchronized(mWindowMap) {
7904 mAnimationPending = false;
7905 performLayoutAndPlaceSurfacesLocked();
7906 }
7907 } break;
7908
7909 case ADD_STARTING: {
7910 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7911 final StartingData sd = wtoken.startingData;
7912
7913 if (sd == null) {
7914 // Animation has been canceled... do nothing.
7915 return;
7916 }
Romain Guy06882f82009-06-10 13:36:04 -07007917
Joe Onorato8a9b2202010-02-26 18:56:32 -08007918 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007921 View view = null;
7922 try {
7923 view = mPolicy.addStartingWindow(
7924 wtoken.token, sd.pkg,
7925 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7926 sd.icon);
7927 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007928 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 }
7930
7931 if (view != null) {
7932 boolean abort = false;
7933
7934 synchronized(mWindowMap) {
7935 if (wtoken.removed || wtoken.startingData == null) {
7936 // If the window was successfully added, then
7937 // we need to remove it.
7938 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007939 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007940 "Aborted starting " + wtoken
7941 + ": removed=" + wtoken.removed
7942 + " startingData=" + wtoken.startingData);
7943 wtoken.startingWindow = null;
7944 wtoken.startingData = null;
7945 abort = true;
7946 }
7947 } else {
7948 wtoken.startingView = view;
7949 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007950 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007951 "Added starting " + wtoken
7952 + ": startingWindow="
7953 + wtoken.startingWindow + " startingView="
7954 + wtoken.startingView);
7955 }
7956
7957 if (abort) {
7958 try {
7959 mPolicy.removeStartingWindow(wtoken.token, view);
7960 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007961 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007962 }
7963 }
7964 }
7965 } break;
7966
7967 case REMOVE_STARTING: {
7968 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7969 IBinder token = null;
7970 View view = null;
7971 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007972 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 + wtoken + ": startingWindow="
7974 + wtoken.startingWindow + " startingView="
7975 + wtoken.startingView);
7976 if (wtoken.startingWindow != null) {
7977 view = wtoken.startingView;
7978 token = wtoken.token;
7979 wtoken.startingData = null;
7980 wtoken.startingView = null;
7981 wtoken.startingWindow = null;
7982 }
7983 }
7984 if (view != null) {
7985 try {
7986 mPolicy.removeStartingWindow(token, view);
7987 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007988 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007989 }
7990 }
7991 } break;
7992
7993 case FINISHED_STARTING: {
7994 IBinder token = null;
7995 View view = null;
7996 while (true) {
7997 synchronized (mWindowMap) {
7998 final int N = mFinishedStarting.size();
7999 if (N <= 0) {
8000 break;
8001 }
8002 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8003
Joe Onorato8a9b2202010-02-26 18:56:32 -08008004 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008005 "Finished starting " + wtoken
8006 + ": startingWindow=" + wtoken.startingWindow
8007 + " startingView=" + wtoken.startingView);
8008
8009 if (wtoken.startingWindow == null) {
8010 continue;
8011 }
8012
8013 view = wtoken.startingView;
8014 token = wtoken.token;
8015 wtoken.startingData = null;
8016 wtoken.startingView = null;
8017 wtoken.startingWindow = null;
8018 }
8019
8020 try {
8021 mPolicy.removeStartingWindow(token, view);
8022 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008023 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008024 }
8025 }
8026 } break;
8027
8028 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8029 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8030
8031 boolean nowVisible = msg.arg1 != 0;
8032 boolean nowGone = msg.arg2 != 0;
8033
8034 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008035 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008036 TAG, "Reporting visible in " + wtoken
8037 + " visible=" + nowVisible
8038 + " gone=" + nowGone);
8039 if (nowVisible) {
8040 wtoken.appToken.windowsVisible();
8041 } else {
8042 wtoken.appToken.windowsGone();
8043 }
8044 } catch (RemoteException ex) {
8045 }
8046 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 case WINDOW_FREEZE_TIMEOUT: {
8049 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008050 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008051 int i = mWindows.size();
8052 while (i > 0) {
8053 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008054 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008055 if (w.mOrientationChanging) {
8056 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008057 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008058 }
8059 }
8060 performLayoutAndPlaceSurfacesLocked();
8061 }
8062 break;
8063 }
Romain Guy06882f82009-06-10 13:36:04 -07008064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008065 case HOLD_SCREEN_CHANGED: {
8066 Session oldHold;
8067 Session newHold;
8068 synchronized (mWindowMap) {
8069 oldHold = mLastReportedHold;
8070 newHold = (Session)msg.obj;
8071 mLastReportedHold = newHold;
8072 }
Romain Guy06882f82009-06-10 13:36:04 -07008073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008074 if (oldHold != newHold) {
8075 try {
8076 if (oldHold != null) {
8077 mBatteryStats.noteStopWakelock(oldHold.mUid,
8078 "window",
8079 BatteryStats.WAKE_TYPE_WINDOW);
8080 }
8081 if (newHold != null) {
8082 mBatteryStats.noteStartWakelock(newHold.mUid,
8083 "window",
8084 BatteryStats.WAKE_TYPE_WINDOW);
8085 }
8086 } catch (RemoteException e) {
8087 }
8088 }
8089 break;
8090 }
Romain Guy06882f82009-06-10 13:36:04 -07008091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008092 case APP_TRANSITION_TIMEOUT: {
8093 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008094 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008095 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008096 "*** APP TRANSITION TIMEOUT");
8097 mAppTransitionReady = true;
8098 mAppTransitionTimeout = true;
8099 performLayoutAndPlaceSurfacesLocked();
8100 }
8101 }
8102 break;
8103 }
Romain Guy06882f82009-06-10 13:36:04 -07008104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008105 case PERSIST_ANIMATION_SCALE: {
8106 Settings.System.putFloat(mContext.getContentResolver(),
8107 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8108 Settings.System.putFloat(mContext.getContentResolver(),
8109 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8110 break;
8111 }
Romain Guy06882f82009-06-10 13:36:04 -07008112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008113 case FORCE_GC: {
8114 synchronized(mWindowMap) {
8115 if (mAnimationPending) {
8116 // If we are animating, don't do the gc now but
8117 // delay a bit so we don't interrupt the animation.
8118 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8119 2000);
8120 return;
8121 }
8122 // If we are currently rotating the display, it will
8123 // schedule a new message when done.
8124 if (mDisplayFrozen) {
8125 return;
8126 }
8127 mFreezeGcPending = 0;
8128 }
8129 Runtime.getRuntime().gc();
8130 break;
8131 }
Romain Guy06882f82009-06-10 13:36:04 -07008132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 case ENABLE_SCREEN: {
8134 performEnableScreen();
8135 break;
8136 }
Romain Guy06882f82009-06-10 13:36:04 -07008137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008138 case APP_FREEZE_TIMEOUT: {
8139 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008140 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008141 int i = mAppTokens.size();
8142 while (i > 0) {
8143 i--;
8144 AppWindowToken tok = mAppTokens.get(i);
8145 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008146 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008147 unsetAppFreezingScreenLocked(tok, true, true);
8148 }
8149 }
8150 }
8151 break;
8152 }
Romain Guy06882f82009-06-10 13:36:04 -07008153
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008154 case SEND_NEW_CONFIGURATION: {
8155 removeMessages(SEND_NEW_CONFIGURATION);
8156 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008157 break;
8158 }
Romain Guy06882f82009-06-10 13:36:04 -07008159
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008160 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008161 if (mWindowsChanged) {
8162 synchronized (mWindowMap) {
8163 mWindowsChanged = false;
8164 }
8165 notifyWindowsChanged();
8166 }
8167 break;
8168 }
8169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008170 }
8171 }
8172 }
8173
8174 // -------------------------------------------------------------
8175 // IWindowManager API
8176 // -------------------------------------------------------------
8177
8178 public IWindowSession openSession(IInputMethodClient client,
8179 IInputContext inputContext) {
8180 if (client == null) throw new IllegalArgumentException("null client");
8181 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008182 Session session = new Session(client, inputContext);
8183 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008184 }
8185
8186 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8187 synchronized (mWindowMap) {
8188 // The focus for the client is the window immediately below
8189 // where we would place the input method window.
8190 int idx = findDesiredInputMethodWindowIndexLocked(false);
8191 WindowState imFocus;
8192 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008193 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008194 if (imFocus != null) {
8195 if (imFocus.mSession.mClient != null &&
8196 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8197 return true;
8198 }
8199 }
8200 }
8201 }
8202 return false;
8203 }
Romain Guy06882f82009-06-10 13:36:04 -07008204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 // -------------------------------------------------------------
8206 // Internals
8207 // -------------------------------------------------------------
8208
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008209 final WindowState windowForClientLocked(Session session, IWindow client,
8210 boolean throwOnError) {
8211 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 }
Romain Guy06882f82009-06-10 13:36:04 -07008213
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008214 final WindowState windowForClientLocked(Session session, IBinder client,
8215 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008216 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008217 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008218 TAG, "Looking up client " + client + ": " + win);
8219 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008220 RuntimeException ex = new IllegalArgumentException(
8221 "Requested window " + client + " does not exist");
8222 if (throwOnError) {
8223 throw ex;
8224 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008225 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008226 return null;
8227 }
8228 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008229 RuntimeException ex = new IllegalArgumentException(
8230 "Requested window " + client + " is in session " +
8231 win.mSession + ", not " + session);
8232 if (throwOnError) {
8233 throw ex;
8234 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008235 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008236 return null;
8237 }
8238
8239 return win;
8240 }
8241
Dianne Hackborna8f60182009-09-01 19:01:50 -07008242 final void rebuildAppWindowListLocked() {
8243 int NW = mWindows.size();
8244 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008245 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008246 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008247
Dianne Hackborna8f60182009-09-01 19:01:50 -07008248 // First remove all existing app windows.
8249 i=0;
8250 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008251 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008252 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008253 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008254 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008255 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008256 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008257 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008258 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008259 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008260 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8261 && lastWallpaper == i-1) {
8262 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008263 }
8264 i++;
8265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008266
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008267 // The wallpaper window(s) typically live at the bottom of the stack,
8268 // so skip them before adding app tokens.
8269 lastWallpaper++;
8270 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008271
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008272 // First add all of the exiting app tokens... these are no longer
8273 // in the main app list, but still have windows shown. We put them
8274 // in the back because now that the animation is over we no longer
8275 // will care about them.
8276 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008277 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008278 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008280
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008281 // And add in the still active app tokens in Z order.
8282 NT = mAppTokens.size();
8283 for (int j=0; j<NT; j++) {
8284 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008285 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008286
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008287 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008288 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008289 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008290 + " windows but added " + i);
8291 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008294 private final void assignLayersLocked() {
8295 int N = mWindows.size();
8296 int curBaseLayer = 0;
8297 int curLayer = 0;
8298 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008300 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008301 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008302 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8303 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008304 curLayer += WINDOW_LAYER_MULTIPLIER;
8305 w.mLayer = curLayer;
8306 } else {
8307 curBaseLayer = curLayer = w.mBaseLayer;
8308 w.mLayer = curLayer;
8309 }
8310 if (w.mTargetAppToken != null) {
8311 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8312 } else if (w.mAppToken != null) {
8313 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8314 } else {
8315 w.mAnimLayer = w.mLayer;
8316 }
8317 if (w.mIsImWindow) {
8318 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008319 } else if (w.mIsWallpaper) {
8320 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008322 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008323 + w.mAnimLayer);
8324 //System.out.println(
8325 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8326 }
8327 }
8328
8329 private boolean mInLayout = false;
8330 private final void performLayoutAndPlaceSurfacesLocked() {
8331 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008332 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008333 throw new RuntimeException("Recursive call!");
8334 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008335 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336 return;
8337 }
8338
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008339 if (mWaitingForConfig) {
8340 // Our configuration has changed (most likely rotation), but we
8341 // don't yet have the complete configuration to report to
8342 // applications. Don't do any window layout until we have it.
8343 return;
8344 }
8345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008346 boolean recoveringMemory = false;
8347 if (mForceRemoves != null) {
8348 recoveringMemory = true;
8349 // Wait a little it for things to settle down, and off we go.
8350 for (int i=0; i<mForceRemoves.size(); i++) {
8351 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008352 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 removeWindowInnerLocked(ws.mSession, ws);
8354 }
8355 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008356 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008357 Object tmp = new Object();
8358 synchronized (tmp) {
8359 try {
8360 tmp.wait(250);
8361 } catch (InterruptedException e) {
8362 }
8363 }
8364 }
Romain Guy06882f82009-06-10 13:36:04 -07008365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008366 mInLayout = true;
8367 try {
8368 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008370 int i = mPendingRemove.size()-1;
8371 if (i >= 0) {
8372 while (i >= 0) {
8373 WindowState w = mPendingRemove.get(i);
8374 removeWindowInnerLocked(w.mSession, w);
8375 i--;
8376 }
8377 mPendingRemove.clear();
8378
8379 mInLayout = false;
8380 assignLayersLocked();
8381 mLayoutNeeded = true;
8382 performLayoutAndPlaceSurfacesLocked();
8383
8384 } else {
8385 mInLayout = false;
8386 if (mLayoutNeeded) {
8387 requestAnimationLocked(0);
8388 }
8389 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008390 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008391 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8392 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008394 } catch (RuntimeException e) {
8395 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008396 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 }
8398 }
8399
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008400 private final int performLayoutLockedInner() {
8401 if (!mLayoutNeeded) {
8402 return 0;
8403 }
8404
8405 mLayoutNeeded = false;
8406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008407 final int dw = mDisplay.getWidth();
8408 final int dh = mDisplay.getHeight();
8409
8410 final int N = mWindows.size();
8411 int i;
8412
Joe Onorato8a9b2202010-02-26 18:56:32 -08008413 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008414 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8415
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008416 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008417
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008418 int seq = mLayoutSeq+1;
8419 if (seq < 0) seq = 0;
8420 mLayoutSeq = seq;
8421
8422 // First perform layout of any root windows (not attached
8423 // to another window).
8424 int topAttached = -1;
8425 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008426 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008428 // Don't do layout of a window if it is not visible, or
8429 // soon won't be visible, to avoid wasting time and funky
8430 // changes while a window is animating away.
8431 final AppWindowToken atoken = win.mAppToken;
8432 final boolean gone = win.mViewVisibility == View.GONE
8433 || !win.mRelayoutCalled
8434 || win.mRootToken.hidden
8435 || (atoken != null && atoken.hiddenRequested)
8436 || win.mAttachedHidden
8437 || win.mExiting || win.mDestroying;
8438
8439 if (!win.mLayoutAttached) {
8440 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8441 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8442 + " mLayoutAttached=" + win.mLayoutAttached);
8443 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8444 + win.mViewVisibility + " mRelayoutCalled="
8445 + win.mRelayoutCalled + " hidden="
8446 + win.mRootToken.hidden + " hiddenRequested="
8447 + (atoken != null && atoken.hiddenRequested)
8448 + " mAttachedHidden=" + win.mAttachedHidden);
8449 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008450
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008451 // If this view is GONE, then skip it -- keep the current
8452 // frame, and let the caller know so they can ignore it
8453 // if they want. (We do the normal layout for INVISIBLE
8454 // windows, since that means "perform layout as normal,
8455 // just don't display").
8456 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008457 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008458 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8459 win.mLayoutSeq = seq;
8460 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8461 + win.mFrame + " mContainingFrame="
8462 + win.mContainingFrame + " mDisplayFrame="
8463 + win.mDisplayFrame);
8464 } else {
8465 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008466 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008468 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008469
8470 // Now perform layout of attached windows, which usually
8471 // depend on the position of the window they are attached to.
8472 // XXX does not deal with windows that are attached to windows
8473 // that are themselves attached.
8474 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008475 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008476
8477 // If this view is GONE, then skip it -- keep the current
8478 // frame, and let the caller know so they can ignore it
8479 // if they want. (We do the normal layout for INVISIBLE
8480 // windows, since that means "perform layout as normal,
8481 // just don't display").
8482 if (win.mLayoutAttached) {
8483 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8484 + " mHaveFrame=" + win.mHaveFrame
8485 + " mViewVisibility=" + win.mViewVisibility
8486 + " mRelayoutCalled=" + win.mRelayoutCalled);
8487 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8488 || !win.mHaveFrame) {
8489 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8490 win.mLayoutSeq = seq;
8491 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8492 + win.mFrame + " mContainingFrame="
8493 + win.mContainingFrame + " mDisplayFrame="
8494 + win.mDisplayFrame);
8495 }
8496 }
8497 }
Jeff Brown349703e2010-06-22 01:27:15 -07008498
8499 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008500 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008501
8502 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 }
Romain Guy06882f82009-06-10 13:36:04 -07008504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008505 private final void performLayoutAndPlaceSurfacesLockedInner(
8506 boolean recoveringMemory) {
8507 final long currentTime = SystemClock.uptimeMillis();
8508 final int dw = mDisplay.getWidth();
8509 final int dh = mDisplay.getHeight();
8510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008511 int i;
8512
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008513 if (mFocusMayChange) {
8514 mFocusMayChange = false;
8515 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8516 }
8517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 if (mFxSession == null) {
8519 mFxSession = new SurfaceSession();
8520 }
Romain Guy06882f82009-06-10 13:36:04 -07008521
Joe Onorato8a9b2202010-02-26 18:56:32 -08008522 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523
8524 // Initialize state of exiting tokens.
8525 for (i=mExitingTokens.size()-1; i>=0; i--) {
8526 mExitingTokens.get(i).hasVisible = false;
8527 }
8528
8529 // Initialize state of exiting applications.
8530 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8531 mExitingAppTokens.get(i).hasVisible = false;
8532 }
8533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 boolean orientationChangeComplete = true;
8535 Session holdScreen = null;
8536 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008537 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 boolean focusDisplayed = false;
8539 boolean animating = false;
8540
8541 Surface.openTransaction();
8542 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008543 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008544 int repeats = 0;
8545 int changes = 0;
8546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008548 repeats++;
8549 if (repeats > 6) {
8550 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8551 mLayoutNeeded = false;
8552 break;
8553 }
8554
8555 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8556 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8557 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8558 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8559 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8560 assignLayersLocked();
8561 mLayoutNeeded = true;
8562 }
8563 }
8564 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8565 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8566 if (updateOrientationFromAppTokensLocked()) {
8567 mLayoutNeeded = true;
8568 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8569 }
8570 }
8571 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8572 mLayoutNeeded = true;
8573 }
8574 }
8575
8576 // FIRST LOOP: Perform a layout, if needed.
8577 if (repeats < 4) {
8578 changes = performLayoutLockedInner();
8579 if (changes != 0) {
8580 continue;
8581 }
8582 } else {
8583 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8584 changes = 0;
8585 }
8586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 final int transactionSequence = ++mTransactionSequence;
8588
8589 // Update animations of all applications, including those
8590 // associated with exiting/removed apps
8591 boolean tokensAnimating = false;
8592 final int NAT = mAppTokens.size();
8593 for (i=0; i<NAT; i++) {
8594 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8595 tokensAnimating = true;
8596 }
8597 }
8598 final int NEAT = mExitingAppTokens.size();
8599 for (i=0; i<NEAT; i++) {
8600 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8601 tokensAnimating = true;
8602 }
8603 }
8604
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008605 // SECOND LOOP: Execute animations and update visibility of windows.
8606
Joe Onorato8a9b2202010-02-26 18:56:32 -08008607 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008608 + transactionSequence + " tokensAnimating="
8609 + tokensAnimating);
8610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008612
8613 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008614 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008615 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008616
8617 mPolicy.beginAnimationLw(dw, dh);
8618
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008619 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008621 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008622 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623
8624 final WindowManager.LayoutParams attrs = w.mAttrs;
8625
8626 if (w.mSurface != null) {
8627 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008628 if (w.commitFinishDrawingLocked(currentTime)) {
8629 if ((w.mAttrs.flags
8630 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008631 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008632 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008633 wallpaperMayChange = true;
8634 }
8635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008636
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008637 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8639 animating = true;
8640 //w.dump(" ");
8641 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008642 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8643 wallpaperMayChange = true;
8644 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008645
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008646 if (mPolicy.doesForceHide(w, attrs)) {
8647 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008648 if (DEBUG_VISIBILITY) Slog.v(TAG,
8649 "Animation done that could impact force hide: "
8650 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008651 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008652 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008653 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8654 forceHiding = true;
8655 }
8656 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8657 boolean changed;
8658 if (forceHiding) {
8659 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008660 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8661 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008662 } else {
8663 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008664 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8665 "Now policy shown: " + w);
8666 if (changed) {
8667 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008668 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008669 // Assume we will need to animate. If
8670 // we don't (because the wallpaper will
8671 // stay with the lock screen), then we will
8672 // clean up later.
8673 Animation a = mPolicy.createForceHideEnterAnimation();
8674 if (a != null) {
8675 w.setAnimation(a);
8676 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008677 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008678 if (mCurrentFocus == null ||
8679 mCurrentFocus.mLayer < w.mLayer) {
8680 // We are showing on to of the current
8681 // focus, so re-evaluate focus to make
8682 // sure it is correct.
8683 mFocusMayChange = true;
8684 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008685 }
8686 }
8687 if (changed && (attrs.flags
8688 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8689 wallpaperMayChange = true;
8690 }
8691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 mPolicy.animatingWindowLw(w, attrs);
8694 }
8695
8696 final AppWindowToken atoken = w.mAppToken;
8697 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8698 if (atoken.lastTransactionSequence != transactionSequence) {
8699 atoken.lastTransactionSequence = transactionSequence;
8700 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8701 atoken.startingDisplayed = false;
8702 }
8703 if ((w.isOnScreen() || w.mAttrs.type
8704 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8705 && !w.mExiting && !w.mDestroying) {
8706 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008707 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008708 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008709 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008710 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008711 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008712 + " pv=" + w.mPolicyVisibility
8713 + " dp=" + w.mDrawPending
8714 + " cdp=" + w.mCommitDrawPending
8715 + " ah=" + w.mAttachedHidden
8716 + " th=" + atoken.hiddenRequested
8717 + " a=" + w.mAnimating);
8718 }
8719 }
8720 if (w != atoken.startingWindow) {
8721 if (!atoken.freezingScreen || !w.mAppFreezing) {
8722 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008723 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008725 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008726 "tokenMayBeDrawn: " + atoken
8727 + " freezingScreen=" + atoken.freezingScreen
8728 + " mAppFreezing=" + w.mAppFreezing);
8729 tokenMayBeDrawn = true;
8730 }
8731 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008732 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008733 atoken.startingDisplayed = true;
8734 }
8735 }
8736 } else if (w.mReadyToShow) {
8737 w.performShowLocked();
8738 }
8739 }
8740
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008741 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008742
8743 if (tokenMayBeDrawn) {
8744 // See if any windows have been drawn, so they (and others
8745 // associated with them) can now be shown.
8746 final int NT = mTokenList.size();
8747 for (i=0; i<NT; i++) {
8748 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8749 if (wtoken == null) {
8750 continue;
8751 }
8752 if (wtoken.freezingScreen) {
8753 int numInteresting = wtoken.numInterestingWindows;
8754 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008755 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008756 "allDrawn: " + wtoken
8757 + " interesting=" + numInteresting
8758 + " drawn=" + wtoken.numDrawnWindows);
8759 wtoken.showAllWindowsLocked();
8760 unsetAppFreezingScreenLocked(wtoken, false, true);
8761 orientationChangeComplete = true;
8762 }
8763 } else if (!wtoken.allDrawn) {
8764 int numInteresting = wtoken.numInterestingWindows;
8765 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008766 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008767 "allDrawn: " + wtoken
8768 + " interesting=" + numInteresting
8769 + " drawn=" + wtoken.numDrawnWindows);
8770 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008771 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008772
8773 // We can now show all of the drawn windows!
8774 if (!mOpeningApps.contains(wtoken)) {
8775 wtoken.showAllWindowsLocked();
8776 }
8777 }
8778 }
8779 }
8780 }
8781
8782 // If we are ready to perform an app transition, check through
8783 // all of the app tokens to be shown and see if they are ready
8784 // to go.
8785 if (mAppTransitionReady) {
8786 int NN = mOpeningApps.size();
8787 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008788 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008789 "Checking " + NN + " opening apps (frozen="
8790 + mDisplayFrozen + " timeout="
8791 + mAppTransitionTimeout + ")...");
8792 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8793 // If the display isn't frozen, wait to do anything until
8794 // all of the apps are ready. Otherwise just go because
8795 // we'll unfreeze the display when everyone is ready.
8796 for (i=0; i<NN && goodToGo; i++) {
8797 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008798 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008799 "Check opening app" + wtoken + ": allDrawn="
8800 + wtoken.allDrawn + " startingDisplayed="
8801 + wtoken.startingDisplayed);
8802 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8803 && !wtoken.startingMoved) {
8804 goodToGo = false;
8805 }
8806 }
8807 }
8808 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008809 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 int transit = mNextAppTransition;
8811 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008812 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008813 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008814 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008815 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008816 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008817 mAppTransitionTimeout = false;
8818 mStartingIconInTransition = false;
8819 mSkipAppTransitionAnimation = false;
8820
8821 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8822
Dianne Hackborna8f60182009-09-01 19:01:50 -07008823 // If there are applications waiting to come to the
8824 // top of the stack, now is the time to move their windows.
8825 // (Note that we don't do apps going to the bottom
8826 // here -- we want to keep their windows in the old
8827 // Z-order until the animation completes.)
8828 if (mToTopApps.size() > 0) {
8829 NN = mAppTokens.size();
8830 for (i=0; i<NN; i++) {
8831 AppWindowToken wtoken = mAppTokens.get(i);
8832 if (wtoken.sendingToTop) {
8833 wtoken.sendingToTop = false;
8834 moveAppWindowsLocked(wtoken, NN, false);
8835 }
8836 }
8837 mToTopApps.clear();
8838 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008839
Dianne Hackborn25994b42009-09-04 14:21:19 -07008840 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008841
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008842 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008843 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008844
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008845 // The top-most window will supply the layout params,
8846 // and we will determine it below.
8847 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008848 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008849 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008850
Joe Onorato8a9b2202010-02-26 18:56:32 -08008851 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008852 "New wallpaper target=" + mWallpaperTarget
8853 + ", lower target=" + mLowerWallpaperTarget
8854 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008855 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008856 // Do a first pass through the tokens for two
8857 // things:
8858 // (1) Determine if both the closing and opening
8859 // app token sets are wallpaper targets, in which
8860 // case special animations are needed
8861 // (since the wallpaper needs to stay static
8862 // behind them).
8863 // (2) Find the layout params of the top-most
8864 // application window in the tokens, which is
8865 // what will control the animation theme.
8866 final int NC = mClosingApps.size();
8867 NN = NC + mOpeningApps.size();
8868 for (i=0; i<NN; i++) {
8869 AppWindowToken wtoken;
8870 int mode;
8871 if (i < NC) {
8872 wtoken = mClosingApps.get(i);
8873 mode = 1;
8874 } else {
8875 wtoken = mOpeningApps.get(i-NC);
8876 mode = 2;
8877 }
8878 if (mLowerWallpaperTarget != null) {
8879 if (mLowerWallpaperTarget.mAppToken == wtoken
8880 || mUpperWallpaperTarget.mAppToken == wtoken) {
8881 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008882 }
8883 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008884 if (wtoken.appFullscreen) {
8885 WindowState ws = wtoken.findMainWindow();
8886 if (ws != null) {
8887 // If this is a compatibility mode
8888 // window, we will always use its anim.
8889 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8890 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008891 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008892 bestAnimLayer = Integer.MAX_VALUE;
8893 } else if (ws.mLayer > bestAnimLayer) {
8894 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008895 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008896 bestAnimLayer = ws.mLayer;
8897 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008898 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008899 }
8900 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008901
Dianne Hackborn25994b42009-09-04 14:21:19 -07008902 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008903 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008904 "Wallpaper animation!");
8905 switch (transit) {
8906 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8907 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8908 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8909 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8910 break;
8911 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8912 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8913 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8914 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8915 break;
8916 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008917 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008918 "New transit: " + transit);
8919 } else if (oldWallpaper != null) {
8920 // We are transitioning from an activity with
8921 // a wallpaper to one without.
8922 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008923 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008924 "New transit away from wallpaper: " + transit);
8925 } else if (mWallpaperTarget != null) {
8926 // We are transitioning from an activity without
8927 // a wallpaper to now showing the wallpaper
8928 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008929 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008930 "New transit into wallpaper: " + transit);
8931 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008932
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008933 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8934 mLastEnterAnimToken = animToken;
8935 mLastEnterAnimParams = animLp;
8936 } else if (mLastEnterAnimParams != null) {
8937 animLp = mLastEnterAnimParams;
8938 mLastEnterAnimToken = null;
8939 mLastEnterAnimParams = null;
8940 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008941
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008942 // If all closing windows are obscured, then there is
8943 // no need to do an animation. This is the case, for
8944 // example, when this transition is being done behind
8945 // the lock screen.
8946 if (!mPolicy.allowAppAnimationsLw()) {
8947 animLp = null;
8948 }
8949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008950 NN = mOpeningApps.size();
8951 for (i=0; i<NN; i++) {
8952 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 "Now opening app" + wtoken);
8955 wtoken.reportedVisible = false;
8956 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008957 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008958 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008959 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008960 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008961 wtoken.showAllWindowsLocked();
8962 }
8963 NN = mClosingApps.size();
8964 for (i=0; i<NN; i++) {
8965 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008966 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 "Now closing app" + wtoken);
8968 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008969 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008970 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008971 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008972 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 // Force the allDrawn flag, because we want to start
8974 // this guy's animations regardless of whether it's
8975 // gotten drawn.
8976 wtoken.allDrawn = true;
8977 }
8978
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008979 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008981 mOpeningApps.clear();
8982 mClosingApps.clear();
8983
8984 // This has changed the visibility of windows, so perform
8985 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008986 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008988 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8989 assignLayersLocked();
8990 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008991 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008992 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008993 }
8994 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008995
Dianne Hackborn16064f92010-03-25 00:47:24 -07008996 int adjResult = 0;
8997
Dianne Hackborna8f60182009-09-01 19:01:50 -07008998 if (!animating && mAppTransitionRunning) {
8999 // We have finished the animation of an app transition. To do
9000 // this, we have delayed a lot of operations like showing and
9001 // hiding apps, moving apps in Z-order, etc. The app token list
9002 // reflects the correct Z-order, but the window list may now
9003 // be out of sync with it. So here we will just rebuild the
9004 // entire app window list. Fun!
9005 mAppTransitionRunning = false;
9006 // Clear information about apps that were moving.
9007 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009008
Dianne Hackborna8f60182009-09-01 19:01:50 -07009009 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009010 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009011 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009012 moveInputMethodWindowsIfNeededLocked(false);
9013 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009014 // Since the window list has been rebuilt, focus might
9015 // have to be recomputed since the actual order of windows
9016 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009017 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009018 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009019
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009020 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009021 // At this point, there was a window with a wallpaper that
9022 // was force hiding other windows behind it, but now it
9023 // is going away. This may be simple -- just animate
9024 // away the wallpaper and its window -- or it may be
9025 // hard -- the wallpaper now needs to be shown behind
9026 // something that was hidden.
9027 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009028 if (mLowerWallpaperTarget != null
9029 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009030 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009031 "wallpaperForceHiding changed with lower="
9032 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009033 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009034 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9035 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9036 if (mLowerWallpaperTarget.mAppToken.hidden) {
9037 // The lower target has become hidden before we
9038 // actually started the animation... let's completely
9039 // re-evaluate everything.
9040 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009041 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009042 }
9043 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009044 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009045 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009046 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009047 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009048 + " NEW: " + mWallpaperTarget
9049 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009050 if (mLowerWallpaperTarget == null) {
9051 // Whoops, we don't need a special wallpaper animation.
9052 // Clear them out.
9053 forceHiding = false;
9054 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009055 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009056 if (w.mSurface != null) {
9057 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009058 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009059 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009060 forceHiding = true;
9061 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9062 if (!w.mAnimating) {
9063 // We set the animation above so it
9064 // is not yet running.
9065 w.clearAnimation();
9066 }
9067 }
9068 }
9069 }
9070 }
9071 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009072
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009073 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009074 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009075 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009076 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009077 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009078
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009079 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009080 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009081 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009082 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009083 assignLayersLocked();
9084 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009085 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009086 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009087 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009089
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009090 if (mFocusMayChange) {
9091 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009092 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009093 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009094 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009095 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009096 }
9097
9098 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009099 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009100 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009101
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009102 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9103 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009104
Jeff Browne33348b2010-07-15 23:54:05 -07009105 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009106 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009107
9108 // THIRD LOOP: Update the surfaces of all windows.
9109
9110 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9111
9112 boolean obscured = false;
9113 boolean blurring = false;
9114 boolean dimming = false;
9115 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009116 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009117 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009119 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009121 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009122 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009123
9124 boolean displayed = false;
9125 final WindowManager.LayoutParams attrs = w.mAttrs;
9126 final int attrFlags = attrs.flags;
9127
9128 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009129 // XXX NOTE: The logic here could be improved. We have
9130 // the decision about whether to resize a window separated
9131 // from whether to hide the surface. This can cause us to
9132 // resize a surface even if we are going to hide it. You
9133 // can see this by (1) holding device in landscape mode on
9134 // home screen; (2) tapping browser icon (device will rotate
9135 // to landscape; (3) tap home. The wallpaper will be resized
9136 // in step 2 but then immediately hidden, causing us to
9137 // have to resize and then redraw it again in step 3. It
9138 // would be nice to figure out how to avoid this, but it is
9139 // difficult because we do need to resize surfaces in some
9140 // cases while they are hidden such as when first showing a
9141 // window.
9142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009144 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 TAG, "Placing surface #" + i + " " + w.mSurface
9146 + ": new=" + w.mShownFrame + ", old="
9147 + w.mLastShownFrame);
9148
9149 boolean resize;
9150 int width, height;
9151 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9152 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9153 w.mLastRequestedHeight != w.mRequestedHeight;
9154 // for a scaled surface, we just want to use
9155 // the requested size.
9156 width = w.mRequestedWidth;
9157 height = w.mRequestedHeight;
9158 w.mLastRequestedWidth = width;
9159 w.mLastRequestedHeight = height;
9160 w.mLastShownFrame.set(w.mShownFrame);
9161 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009162 if (SHOW_TRANSACTIONS) logSurface(w,
9163 "POS " + w.mShownFrame.left
9164 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009165 w.mSurfaceX = w.mShownFrame.left;
9166 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009167 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9168 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009169 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009170 if (!recoveringMemory) {
9171 reclaimSomeSurfaceMemoryLocked(w, "position");
9172 }
9173 }
9174 } else {
9175 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9176 width = w.mShownFrame.width();
9177 height = w.mShownFrame.height();
9178 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009179 }
9180
9181 if (resize) {
9182 if (width < 1) width = 1;
9183 if (height < 1) height = 1;
9184 if (w.mSurface != null) {
9185 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009186 if (SHOW_TRANSACTIONS) logSurface(w,
9187 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009188 + w.mShownFrame.top + " SIZE "
9189 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009190 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009191 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009192 w.mSurfaceW = width;
9193 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009194 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009195 w.mSurfaceX = w.mShownFrame.left;
9196 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009197 w.mSurface.setPosition(w.mShownFrame.left,
9198 w.mShownFrame.top);
9199 } catch (RuntimeException e) {
9200 // If something goes wrong with the surface (such
9201 // as running out of memory), don't take down the
9202 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009203 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009204 + "size=(" + width + "x" + height
9205 + "), pos=(" + w.mShownFrame.left
9206 + "," + w.mShownFrame.top + ")", e);
9207 if (!recoveringMemory) {
9208 reclaimSomeSurfaceMemoryLocked(w, "size");
9209 }
9210 }
9211 }
9212 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009213 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009214 w.mContentInsetsChanged =
9215 !w.mLastContentInsets.equals(w.mContentInsets);
9216 w.mVisibleInsetsChanged =
9217 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009218 boolean configChanged =
9219 w.mConfiguration != mCurConfiguration
9220 && (w.mConfiguration == null
9221 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009222 if (DEBUG_CONFIGURATION && configChanged) {
9223 Slog.v(TAG, "Win " + w + " config changed: "
9224 + mCurConfiguration);
9225 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009226 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009227 + ": configChanged=" + configChanged
9228 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009229 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009230 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009231 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009232 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009233 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009234 w.mLastFrame.set(w.mFrame);
9235 w.mLastContentInsets.set(w.mContentInsets);
9236 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009237 // If the screen is currently frozen, then keep
9238 // it frozen until this window draws at its new
9239 // orientation.
9240 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009241 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009242 "Resizing while display frozen: " + w);
9243 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009244 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009245 mWindowsFreezingScreen = true;
9246 // XXX should probably keep timeout from
9247 // when we first froze the display.
9248 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9249 mH.sendMessageDelayed(mH.obtainMessage(
9250 H.WINDOW_FREEZE_TIMEOUT), 2000);
9251 }
9252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 // If the orientation is changing, then we need to
9254 // hold off on unfreezing the display until this
9255 // window has been redrawn; to do that, we need
9256 // to go through the process of getting informed
9257 // by the application when it has finished drawing.
9258 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009259 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 "Orientation start waiting for draw in "
9261 + w + ", surface " + w.mSurface);
9262 w.mDrawPending = true;
9263 w.mCommitDrawPending = false;
9264 w.mReadyToShow = false;
9265 if (w.mAppToken != null) {
9266 w.mAppToken.allDrawn = false;
9267 }
9268 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009269 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 "Resizing window " + w + " to " + w.mFrame);
9271 mResizingWindows.add(w);
9272 } else if (w.mOrientationChanging) {
9273 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009274 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009275 "Orientation not waiting for draw in "
9276 + w + ", surface " + w.mSurface);
9277 w.mOrientationChanging = false;
9278 }
9279 }
9280 }
9281
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009282 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 if (!w.mLastHidden) {
9284 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009285 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9286 + w.mRootToken.waitingToShow + " polvis="
9287 + w.mPolicyVisibility + " atthid="
9288 + w.mAttachedHidden + " tokhid="
9289 + w.mRootToken.hidden + " vis="
9290 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009291 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009292 if (SHOW_TRANSACTIONS) logSurface(w,
9293 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009294 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009295 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009296 try {
9297 w.mSurface.hide();
9298 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009299 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009300 }
9301 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009302 }
9303 // If we are waiting for this window to handle an
9304 // orientation change, well, it is hidden, so
9305 // doesn't really matter. Note that this does
9306 // introduce a potential glitch if the window
9307 // becomes unhidden before it has drawn for the
9308 // new orientation.
9309 if (w.mOrientationChanging) {
9310 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009311 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009312 "Orientation change skips hidden " + w);
9313 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009314 } else if (w.mLastLayer != w.mAnimLayer
9315 || w.mLastAlpha != w.mShownAlpha
9316 || w.mLastDsDx != w.mDsDx
9317 || w.mLastDtDx != w.mDtDx
9318 || w.mLastDsDy != w.mDsDy
9319 || w.mLastDtDy != w.mDtDy
9320 || w.mLastHScale != w.mHScale
9321 || w.mLastVScale != w.mVScale
9322 || w.mLastHidden) {
9323 displayed = true;
9324 w.mLastAlpha = w.mShownAlpha;
9325 w.mLastLayer = w.mAnimLayer;
9326 w.mLastDsDx = w.mDsDx;
9327 w.mLastDtDx = w.mDtDx;
9328 w.mLastDsDy = w.mDsDy;
9329 w.mLastDtDy = w.mDtDy;
9330 w.mLastHScale = w.mHScale;
9331 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009332 if (SHOW_TRANSACTIONS) logSurface(w,
9333 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009334 + " matrix=[" + (w.mDsDx*w.mHScale)
9335 + "," + (w.mDtDx*w.mVScale)
9336 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009337 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009338 if (w.mSurface != null) {
9339 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009340 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009341 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009342 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009343 w.mSurface.setLayer(w.mAnimLayer);
9344 w.mSurface.setMatrix(
9345 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9346 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9347 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009348 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009349 if (!recoveringMemory) {
9350 reclaimSomeSurfaceMemoryLocked(w, "update");
9351 }
9352 }
9353 }
9354
9355 if (w.mLastHidden && !w.mDrawPending
9356 && !w.mCommitDrawPending
9357 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009358 if (SHOW_TRANSACTIONS) logSurface(w,
9359 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009360 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009361 + " during relayout");
9362 if (showSurfaceRobustlyLocked(w)) {
9363 w.mHasDrawn = true;
9364 w.mLastHidden = false;
9365 } else {
9366 w.mOrientationChanging = false;
9367 }
9368 }
9369 if (w.mSurface != null) {
9370 w.mToken.hasVisible = true;
9371 }
9372 } else {
9373 displayed = true;
9374 }
9375
9376 if (displayed) {
9377 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009378 if (attrs.width == LayoutParams.MATCH_PARENT
9379 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009380 covered = true;
9381 }
9382 }
9383 if (w.mOrientationChanging) {
9384 if (w.mDrawPending || w.mCommitDrawPending) {
9385 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009386 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009387 "Orientation continue waiting for draw in " + w);
9388 } else {
9389 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009390 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009391 "Orientation change complete in " + w);
9392 }
9393 }
9394 w.mToken.hasVisible = true;
9395 }
9396 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009397 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 "Orientation change skips hidden " + w);
9399 w.mOrientationChanging = false;
9400 }
9401
9402 final boolean canBeSeen = w.isDisplayedLw();
9403
9404 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9405 focusDisplayed = true;
9406 }
9407
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009408 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009411 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009412 if (w.mSurface != null) {
9413 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9414 holdScreen = w.mSession;
9415 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009416 if (!syswin && w.mAttrs.screenBrightness >= 0
9417 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009418 screenBrightness = w.mAttrs.screenBrightness;
9419 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009420 if (!syswin && w.mAttrs.buttonBrightness >= 0
9421 && buttonBrightness < 0) {
9422 buttonBrightness = w.mAttrs.buttonBrightness;
9423 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009424 if (canBeSeen
9425 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9426 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9427 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009428 syswin = true;
9429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009430 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009431
Dianne Hackborn25994b42009-09-04 14:21:19 -07009432 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9433 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434 // This window completely covers everything behind it,
9435 // so we want to leave all of them as unblurred (for
9436 // performance reasons).
9437 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009438 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009439 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009440 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009441 obscured = true;
9442 if (mBackgroundFillerSurface == null) {
9443 try {
9444 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009445 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009446 0, dw, dh,
9447 PixelFormat.OPAQUE,
9448 Surface.FX_SURFACE_NORMAL);
9449 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009450 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009451 }
9452 }
9453 try {
9454 mBackgroundFillerSurface.setPosition(0, 0);
9455 mBackgroundFillerSurface.setSize(dw, dh);
9456 // Using the same layer as Dim because they will never be shown at the
9457 // same time.
9458 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9459 mBackgroundFillerSurface.show();
9460 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009461 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009462 }
9463 backgroundFillerShown = true;
9464 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009465 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009466 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009467 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009468 + ": blurring=" + blurring
9469 + " obscured=" + obscured
9470 + " displayed=" + displayed);
9471 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9472 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009473 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009475 if (mDimAnimator == null) {
9476 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009477 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009478 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009479 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009481 }
9482 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9483 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009484 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009486 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009487 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009488 + mBlurSurface + ": CREATE");
9489 try {
Romain Guy06882f82009-06-10 13:36:04 -07009490 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009491 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009492 -1, 16, 16,
9493 PixelFormat.OPAQUE,
9494 Surface.FX_SURFACE_BLUR);
9495 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009496 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 }
9498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009500 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9501 + mBlurSurface + ": pos=(0,0) (" +
9502 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 mBlurSurface.setPosition(0, 0);
9504 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009505 mBlurSurface.setLayer(w.mAnimLayer-2);
9506 if (!mBlurShown) {
9507 try {
9508 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9509 + mBlurSurface + ": SHOW");
9510 mBlurSurface.show();
9511 } catch (RuntimeException e) {
9512 Slog.w(TAG, "Failure showing blur surface", e);
9513 }
9514 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009515 }
9516 }
9517 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009518 }
9519 }
9520 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009521
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009522 if (obscuredChanged && mWallpaperTarget == w) {
9523 // This is the wallpaper target and its obscured state
9524 // changed... make sure the current wallaper's visibility
9525 // has been updated accordingly.
9526 updateWallpaperVisibilityLocked();
9527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009528 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009529
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009530 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9531 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009532 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009533 try {
9534 mBackgroundFillerSurface.hide();
9535 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009536 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009537 }
9538 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009540 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009541 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9542 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009543 }
Romain Guy06882f82009-06-10 13:36:04 -07009544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009546 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009547 + ": HIDE");
9548 try {
9549 mBlurSurface.hide();
9550 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009551 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 }
9553 mBlurShown = false;
9554 }
9555
Joe Onorato8a9b2202010-02-26 18:56:32 -08009556 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009557 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009558 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009559 }
9560
Jeff Browne33348b2010-07-15 23:54:05 -07009561 mInputMonitor.updateInputWindowsLw();
9562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009563 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009564
Joe Onorato8a9b2202010-02-26 18:56:32 -08009565 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009566 "With display frozen, orientationChangeComplete="
9567 + orientationChangeComplete);
9568 if (orientationChangeComplete) {
9569 if (mWindowsFreezingScreen) {
9570 mWindowsFreezingScreen = false;
9571 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9572 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009573 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009574 }
Romain Guy06882f82009-06-10 13:36:04 -07009575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009576 i = mResizingWindows.size();
9577 if (i > 0) {
9578 do {
9579 i--;
9580 WindowState win = mResizingWindows.get(i);
9581 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009582 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9583 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009584 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009585 boolean configChanged =
9586 win.mConfiguration != mCurConfiguration
9587 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009588 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9589 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9590 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009591 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009592 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009593 + " / " + mCurConfiguration + " / 0x"
9594 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009595 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009596 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009597 win.mClient.resized(win.mFrame.width(),
9598 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009599 win.mLastVisibleInsets, win.mDrawPending,
9600 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009601 win.mContentInsetsChanged = false;
9602 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009603 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009604 } catch (RemoteException e) {
9605 win.mOrientationChanging = false;
9606 }
9607 } while (i > 0);
9608 mResizingWindows.clear();
9609 }
Romain Guy06882f82009-06-10 13:36:04 -07009610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009611 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009612 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 i = mDestroySurface.size();
9614 if (i > 0) {
9615 do {
9616 i--;
9617 WindowState win = mDestroySurface.get(i);
9618 win.mDestroying = false;
9619 if (mInputMethodWindow == win) {
9620 mInputMethodWindow = null;
9621 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009622 if (win == mWallpaperTarget) {
9623 wallpaperDestroyed = true;
9624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009625 win.destroySurfaceLocked();
9626 } while (i > 0);
9627 mDestroySurface.clear();
9628 }
9629
9630 // Time to remove any exiting tokens?
9631 for (i=mExitingTokens.size()-1; i>=0; i--) {
9632 WindowToken token = mExitingTokens.get(i);
9633 if (!token.hasVisible) {
9634 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009635 if (token.windowType == TYPE_WALLPAPER) {
9636 mWallpaperTokens.remove(token);
9637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009638 }
9639 }
9640
9641 // Time to remove any exiting applications?
9642 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9643 AppWindowToken token = mExitingAppTokens.get(i);
9644 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009645 // Make sure there is no animation running on this token,
9646 // so any windows associated with it will be removed as
9647 // soon as their animations are complete
9648 token.animation = null;
9649 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009650 mAppTokens.remove(token);
9651 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009652 if (mLastEnterAnimToken == token) {
9653 mLastEnterAnimToken = null;
9654 mLastEnterAnimParams = null;
9655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009656 }
9657 }
9658
Dianne Hackborna8f60182009-09-01 19:01:50 -07009659 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009660
Dianne Hackborna8f60182009-09-01 19:01:50 -07009661 if (!animating && mAppTransitionRunning) {
9662 // We have finished the animation of an app transition. To do
9663 // this, we have delayed a lot of operations like showing and
9664 // hiding apps, moving apps in Z-order, etc. The app token list
9665 // reflects the correct Z-order, but the window list may now
9666 // be out of sync with it. So here we will just rebuild the
9667 // entire app window list. Fun!
9668 mAppTransitionRunning = false;
9669 needRelayout = true;
9670 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009671 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009672 // Clear information about apps that were moving.
9673 mToBottomApps.clear();
9674 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009676 if (focusDisplayed) {
9677 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9678 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009679 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009680 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009681 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009682 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009683 requestAnimationLocked(0);
9684 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9686 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009687
Jeff Browne33348b2010-07-15 23:54:05 -07009688 mInputMonitor.updateInputWindowsLw();
9689
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009690 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9691 + " holdScreen=" + holdScreen);
9692 if (!mDisplayFrozen) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009693 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009694 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9695 mPowerManager.setScreenBrightnessOverride(-1);
9696 } else {
9697 mPowerManager.setScreenBrightnessOverride((int)
9698 (screenBrightness * Power.BRIGHTNESS_ON));
9699 }
9700 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9701 mPowerManager.setButtonBrightnessOverride(-1);
9702 } else {
9703 mPowerManager.setButtonBrightnessOverride((int)
9704 (buttonBrightness * Power.BRIGHTNESS_ON));
9705 }
9706 if (holdScreen != mHoldingScreenOn) {
9707 mHoldingScreenOn = holdScreen;
9708 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9709 mH.sendMessage(m);
9710 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009711 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009712
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009713 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009714 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009715 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9716 LocalPowerManager.BUTTON_EVENT, true);
9717 mTurnOnScreen = false;
9718 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009719
9720 // Check to see if we are now in a state where the screen should
9721 // be enabled, because the window obscured flags have changed.
9722 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009723 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009724
9725 /**
9726 * Must be called with the main window manager lock held.
9727 */
9728 void setHoldScreenLocked(boolean holding) {
9729 boolean state = mHoldingScreenWakeLock.isHeld();
9730 if (holding != state) {
9731 if (holding) {
9732 mHoldingScreenWakeLock.acquire();
9733 } else {
9734 mPolicy.screenOnStoppedLw();
9735 mHoldingScreenWakeLock.release();
9736 }
9737 }
9738 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739
9740 void requestAnimationLocked(long delay) {
9741 if (!mAnimationPending) {
9742 mAnimationPending = true;
9743 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9744 }
9745 }
Romain Guy06882f82009-06-10 13:36:04 -07009746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009747 /**
9748 * Have the surface flinger show a surface, robustly dealing with
9749 * error conditions. In particular, if there is not enough memory
9750 * to show the surface, then we will try to get rid of other surfaces
9751 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009752 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753 * @return Returns true if the surface was successfully shown.
9754 */
9755 boolean showSurfaceRobustlyLocked(WindowState win) {
9756 try {
9757 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009758 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009759 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009760 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009761 if (DEBUG_VISIBILITY) Slog.v(TAG,
9762 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009763 win.mTurnOnScreen = false;
9764 mTurnOnScreen = true;
9765 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009766 }
9767 return true;
9768 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009769 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009770 }
Romain Guy06882f82009-06-10 13:36:04 -07009771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009774 return false;
9775 }
Romain Guy06882f82009-06-10 13:36:04 -07009776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009777 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9778 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009779
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009780 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009781 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009783 if (mForceRemoves == null) {
9784 mForceRemoves = new ArrayList<WindowState>();
9785 }
Romain Guy06882f82009-06-10 13:36:04 -07009786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787 long callingIdentity = Binder.clearCallingIdentity();
9788 try {
9789 // There was some problem... first, do a sanity check of the
9790 // window list to make sure we haven't left any dangling surfaces
9791 // around.
9792 int N = mWindows.size();
9793 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009794 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009796 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009797 if (ws.mSurface != null) {
9798 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009799 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 + ws + " surface=" + ws.mSurface
9801 + " token=" + win.mToken
9802 + " pid=" + ws.mSession.mPid
9803 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009804 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009805 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806 ws.mSurface = null;
9807 mForceRemoves.add(ws);
9808 i--;
9809 N--;
9810 leakedSurface = true;
9811 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009812 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 + ws + " surface=" + ws.mSurface
9814 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009815 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009816 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009817 ws.mSurface = null;
9818 leakedSurface = true;
9819 }
9820 }
9821 }
Romain Guy06882f82009-06-10 13:36:04 -07009822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009823 boolean killedApps = false;
9824 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009825 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 SparseIntArray pidCandidates = new SparseIntArray();
9827 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009828 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 if (ws.mSurface != null) {
9830 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9831 }
9832 }
9833 if (pidCandidates.size() > 0) {
9834 int[] pids = new int[pidCandidates.size()];
9835 for (int i=0; i<pids.length; i++) {
9836 pids[i] = pidCandidates.keyAt(i);
9837 }
9838 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009839 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009840 killedApps = true;
9841 }
9842 } catch (RemoteException e) {
9843 }
9844 }
9845 }
Romain Guy06882f82009-06-10 13:36:04 -07009846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009847 if (leakedSurface || killedApps) {
9848 // We managed to reclaim some memory, so get rid of the trouble
9849 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009850 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009852 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009853 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009854 win.mSurface = null;
9855 }
Romain Guy06882f82009-06-10 13:36:04 -07009856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009857 try {
9858 win.mClient.dispatchGetNewSurface();
9859 } catch (RemoteException e) {
9860 }
9861 }
9862 } finally {
9863 Binder.restoreCallingIdentity(callingIdentity);
9864 }
9865 }
Romain Guy06882f82009-06-10 13:36:04 -07009866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867 private boolean updateFocusedWindowLocked(int mode) {
9868 WindowState newFocus = computeFocusedWindowLocked();
9869 if (mCurrentFocus != newFocus) {
9870 // This check makes sure that we don't already have the focus
9871 // change message pending.
9872 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9873 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009874 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009875 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9876 final WindowState oldFocus = mCurrentFocus;
9877 mCurrentFocus = newFocus;
9878 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009880 final WindowState imWindow = mInputMethodWindow;
9881 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009882 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009884 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9885 mLayoutNeeded = true;
9886 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9888 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009889 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9890 // Client will do the layout, but we need to assign layers
9891 // for handleNewWindowLocked() below.
9892 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893 }
9894 }
Jeff Brown349703e2010-06-22 01:27:15 -07009895
9896 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9897 // If we defer assigning layers, then the caller is responsible for
9898 // doing this part.
9899 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009901 return true;
9902 }
9903 return false;
9904 }
Jeff Brown349703e2010-06-22 01:27:15 -07009905
9906 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009907 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909
9910 private WindowState computeFocusedWindowLocked() {
9911 WindowState result = null;
9912 WindowState win;
9913
9914 int i = mWindows.size() - 1;
9915 int nextAppIndex = mAppTokens.size()-1;
9916 WindowToken nextApp = nextAppIndex >= 0
9917 ? mAppTokens.get(nextAppIndex) : null;
9918
9919 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009920 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009921
Joe Onorato8a9b2202010-02-26 18:56:32 -08009922 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009923 TAG, "Looking for focus: " + i
9924 + " = " + win
9925 + ", flags=" + win.mAttrs.flags
9926 + ", canReceive=" + win.canReceiveKeys());
9927
9928 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009930 // If this window's application has been removed, just skip it.
9931 if (thisApp != null && thisApp.removed) {
9932 i--;
9933 continue;
9934 }
Romain Guy06882f82009-06-10 13:36:04 -07009935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009936 // If there is a focused app, don't allow focus to go to any
9937 // windows below it. If this is an application window, step
9938 // through the app tokens until we find its app.
9939 if (thisApp != null && nextApp != null && thisApp != nextApp
9940 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9941 int origAppIndex = nextAppIndex;
9942 while (nextAppIndex > 0) {
9943 if (nextApp == mFocusedApp) {
9944 // Whoops, we are below the focused app... no focus
9945 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009946 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009947 TAG, "Reached focused app: " + mFocusedApp);
9948 return null;
9949 }
9950 nextAppIndex--;
9951 nextApp = mAppTokens.get(nextAppIndex);
9952 if (nextApp == thisApp) {
9953 break;
9954 }
9955 }
9956 if (thisApp != nextApp) {
9957 // Uh oh, the app token doesn't exist! This shouldn't
9958 // happen, but if it does we can get totally hosed...
9959 // so restart at the original app.
9960 nextAppIndex = origAppIndex;
9961 nextApp = mAppTokens.get(nextAppIndex);
9962 }
9963 }
9964
9965 // Dispatch to this window if it is wants key events.
9966 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009967 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009968 TAG, "Found focus @ " + i + " = " + win);
9969 result = win;
9970 break;
9971 }
9972
9973 i--;
9974 }
9975
9976 return result;
9977 }
9978
9979 private void startFreezingDisplayLocked() {
9980 if (mDisplayFrozen) {
9981 return;
9982 }
Romain Guy06882f82009-06-10 13:36:04 -07009983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009984 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009987 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009988 if (mFreezeGcPending != 0) {
9989 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009990 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009991 mH.removeMessages(H.FORCE_GC);
9992 Runtime.getRuntime().gc();
9993 mFreezeGcPending = now;
9994 }
9995 } else {
9996 mFreezeGcPending = now;
9997 }
Romain Guy06882f82009-06-10 13:36:04 -07009998
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009999 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
10000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010001 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010002
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010003 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010004
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010005 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10006 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010007 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010008 mAppTransitionReady = true;
10009 }
Romain Guy06882f82009-06-10 13:36:04 -070010010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010011 if (PROFILE_ORIENTATION) {
10012 File file = new File("/data/system/frozen");
10013 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10014 }
10015 Surface.freezeDisplay(0);
10016 }
Romain Guy06882f82009-06-10 13:36:04 -070010017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 private void stopFreezingDisplayLocked() {
10019 if (!mDisplayFrozen) {
10020 return;
10021 }
Romain Guy06882f82009-06-10 13:36:04 -070010022
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010023 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10024 return;
10025 }
10026
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010027 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
10028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010029 mDisplayFrozen = false;
10030 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10031 if (PROFILE_ORIENTATION) {
10032 Debug.stopMethodTracing();
10033 }
10034 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010035
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010036 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010037
Christopher Tateb696aee2010-04-02 19:08:30 -070010038 // While the display is frozen we don't re-compute the orientation
10039 // to avoid inconsistent states. However, something interesting
10040 // could have actually changed during that time so re-evaluate it
10041 // now to catch that.
10042 if (updateOrientationFromAppTokensLocked()) {
10043 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10044 }
10045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 // A little kludge: a lot could have happened while the
10047 // display was frozen, so now that we are coming back we
10048 // do a gc so that any remote references the system
10049 // processes holds on others can be released if they are
10050 // no longer needed.
10051 mH.removeMessages(H.FORCE_GC);
10052 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10053 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055 mScreenFrozenLock.release();
10056 }
Romain Guy06882f82009-06-10 13:36:04 -070010057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058 @Override
10059 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10060 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10061 != PackageManager.PERMISSION_GRANTED) {
10062 pw.println("Permission Denial: can't dump WindowManager from from pid="
10063 + Binder.getCallingPid()
10064 + ", uid=" + Binder.getCallingUid());
10065 return;
10066 }
Romain Guy06882f82009-06-10 13:36:04 -070010067
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010068 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010069 pw.println(" ");
10070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 synchronized(mWindowMap) {
10072 pw.println("Current Window Manager state:");
10073 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010074 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010075 pw.print(" Window #"); pw.print(i); pw.print(' ');
10076 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 w.dump(pw, " ");
10078 }
10079 if (mInputMethodDialogs.size() > 0) {
10080 pw.println(" ");
10081 pw.println(" Input method dialogs:");
10082 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10083 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010084 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010085 }
10086 }
10087 if (mPendingRemove.size() > 0) {
10088 pw.println(" ");
10089 pw.println(" Remove pending for:");
10090 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10091 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010092 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10093 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010094 w.dump(pw, " ");
10095 }
10096 }
10097 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10098 pw.println(" ");
10099 pw.println(" Windows force removing:");
10100 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10101 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010102 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10103 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010104 w.dump(pw, " ");
10105 }
10106 }
10107 if (mDestroySurface.size() > 0) {
10108 pw.println(" ");
10109 pw.println(" Windows waiting to destroy their surface:");
10110 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10111 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010112 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10113 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010114 w.dump(pw, " ");
10115 }
10116 }
10117 if (mLosingFocus.size() > 0) {
10118 pw.println(" ");
10119 pw.println(" Windows losing focus:");
10120 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10121 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010122 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10123 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010124 w.dump(pw, " ");
10125 }
10126 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010127 if (mResizingWindows.size() > 0) {
10128 pw.println(" ");
10129 pw.println(" Windows waiting to resize:");
10130 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10131 WindowState w = mResizingWindows.get(i);
10132 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10133 pw.print(w); pw.println(":");
10134 w.dump(pw, " ");
10135 }
10136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010137 if (mSessions.size() > 0) {
10138 pw.println(" ");
10139 pw.println(" All active sessions:");
10140 Iterator<Session> it = mSessions.iterator();
10141 while (it.hasNext()) {
10142 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010143 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144 s.dump(pw, " ");
10145 }
10146 }
10147 if (mTokenMap.size() > 0) {
10148 pw.println(" ");
10149 pw.println(" All tokens:");
10150 Iterator<WindowToken> it = mTokenMap.values().iterator();
10151 while (it.hasNext()) {
10152 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010153 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010154 token.dump(pw, " ");
10155 }
10156 }
10157 if (mTokenList.size() > 0) {
10158 pw.println(" ");
10159 pw.println(" Window token list:");
10160 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010161 pw.print(" #"); pw.print(i); pw.print(": ");
10162 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010163 }
10164 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010165 if (mWallpaperTokens.size() > 0) {
10166 pw.println(" ");
10167 pw.println(" Wallpaper tokens:");
10168 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10169 WindowToken token = mWallpaperTokens.get(i);
10170 pw.print(" Wallpaper #"); pw.print(i);
10171 pw.print(' '); pw.print(token); pw.println(':');
10172 token.dump(pw, " ");
10173 }
10174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010175 if (mAppTokens.size() > 0) {
10176 pw.println(" ");
10177 pw.println(" Application tokens in Z order:");
10178 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010179 pw.print(" App #"); pw.print(i); pw.print(": ");
10180 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010181 }
10182 }
10183 if (mFinishedStarting.size() > 0) {
10184 pw.println(" ");
10185 pw.println(" Finishing start of application tokens:");
10186 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10187 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010188 pw.print(" Finished Starting #"); pw.print(i);
10189 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010190 token.dump(pw, " ");
10191 }
10192 }
10193 if (mExitingTokens.size() > 0) {
10194 pw.println(" ");
10195 pw.println(" Exiting tokens:");
10196 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10197 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010198 pw.print(" Exiting #"); pw.print(i);
10199 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010200 token.dump(pw, " ");
10201 }
10202 }
10203 if (mExitingAppTokens.size() > 0) {
10204 pw.println(" ");
10205 pw.println(" Exiting application tokens:");
10206 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10207 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010208 pw.print(" Exiting App #"); pw.print(i);
10209 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010210 token.dump(pw, " ");
10211 }
10212 }
10213 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010214 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10215 pw.print(" mLastFocus="); pw.println(mLastFocus);
10216 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10217 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10218 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010219 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010220 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10221 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10222 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10223 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010224 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10225 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10226 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010227 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10228 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10229 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10230 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010231 if (mDimAnimator != null) {
10232 mDimAnimator.printTo(pw);
10233 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010234 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010235 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010236 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010237 pw.print(mInputMethodAnimLayerAdjustment);
10238 pw.print(" mWallpaperAnimLayerAdjustment=");
10239 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010240 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10241 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010242 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10243 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010244 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10245 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010246 pw.print(" mRotation="); pw.print(mRotation);
10247 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10248 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10249 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10250 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10251 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10252 pw.print(" mNextAppTransition=0x");
10253 pw.print(Integer.toHexString(mNextAppTransition));
10254 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010255 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010256 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010257 if (mNextAppTransitionPackage != null) {
10258 pw.print(" mNextAppTransitionPackage=");
10259 pw.print(mNextAppTransitionPackage);
10260 pw.print(", mNextAppTransitionEnter=0x");
10261 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10262 pw.print(", mNextAppTransitionExit=0x");
10263 pw.print(Integer.toHexString(mNextAppTransitionExit));
10264 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010265 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10266 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010267 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10268 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10269 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10270 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010271 if (mOpeningApps.size() > 0) {
10272 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10273 }
10274 if (mClosingApps.size() > 0) {
10275 pw.print(" mClosingApps="); pw.println(mClosingApps);
10276 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010277 if (mToTopApps.size() > 0) {
10278 pw.print(" mToTopApps="); pw.println(mToTopApps);
10279 }
10280 if (mToBottomApps.size() > 0) {
10281 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10282 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010283 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10284 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010285 }
10286 }
10287
Jeff Brown349703e2010-06-22 01:27:15 -070010288 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 public void monitor() {
10290 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010291 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010293
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010294 /**
10295 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010296 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010297 */
10298 private static class DimAnimator {
10299 Surface mDimSurface;
10300 boolean mDimShown = false;
10301 float mDimCurrentAlpha;
10302 float mDimTargetAlpha;
10303 float mDimDeltaPerMs;
10304 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010305
10306 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010307
10308 DimAnimator (SurfaceSession session) {
10309 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010310 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010311 + mDimSurface + ": CREATE");
10312 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010313 mDimSurface = new Surface(session, 0,
10314 "DimSurface",
10315 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010316 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010317 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010318 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010319 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010320 }
10321 }
10322 }
10323
10324 /**
10325 * Show the dim surface.
10326 */
10327 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010328 if (!mDimShown) {
10329 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10330 dw + "x" + dh + ")");
10331 mDimShown = true;
10332 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010333 mLastDimWidth = dw;
10334 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010335 mDimSurface.setPosition(0, 0);
10336 mDimSurface.setSize(dw, dh);
10337 mDimSurface.show();
10338 } catch (RuntimeException e) {
10339 Slog.w(TAG, "Failure showing dim surface", e);
10340 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010341 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10342 mLastDimWidth = dw;
10343 mLastDimHeight = dh;
10344 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010345 }
10346 }
10347
10348 /**
10349 * Set's the dim surface's layer and update dim parameters that will be used in
10350 * {@link updateSurface} after all windows are examined.
10351 */
10352 void updateParameters(WindowState w, long currentTime) {
10353 mDimSurface.setLayer(w.mAnimLayer-1);
10354
10355 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010356 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010357 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010358 if (mDimTargetAlpha != target) {
10359 // If the desired dim level has changed, then
10360 // start an animation to it.
10361 mLastDimAnimTime = currentTime;
10362 long duration = (w.mAnimating && w.mAnimation != null)
10363 ? w.mAnimation.computeDurationHint()
10364 : DEFAULT_DIM_DURATION;
10365 if (target > mDimTargetAlpha) {
10366 // This is happening behind the activity UI,
10367 // so we can make it run a little longer to
10368 // give a stronger impression without disrupting
10369 // the user.
10370 duration *= DIM_DURATION_MULTIPLIER;
10371 }
10372 if (duration < 1) {
10373 // Don't divide by zero
10374 duration = 1;
10375 }
10376 mDimTargetAlpha = target;
10377 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10378 }
10379 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010380
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010381 /**
10382 * Updating the surface's alpha. Returns true if the animation continues, or returns
10383 * false when the animation is finished and the dim surface is hidden.
10384 */
10385 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10386 if (!dimming) {
10387 if (mDimTargetAlpha != 0) {
10388 mLastDimAnimTime = currentTime;
10389 mDimTargetAlpha = 0;
10390 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10391 }
10392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010393
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010394 boolean animating = false;
10395 if (mLastDimAnimTime != 0) {
10396 mDimCurrentAlpha += mDimDeltaPerMs
10397 * (currentTime-mLastDimAnimTime);
10398 boolean more = true;
10399 if (displayFrozen) {
10400 // If the display is frozen, there is no reason to animate.
10401 more = false;
10402 } else if (mDimDeltaPerMs > 0) {
10403 if (mDimCurrentAlpha > mDimTargetAlpha) {
10404 more = false;
10405 }
10406 } else if (mDimDeltaPerMs < 0) {
10407 if (mDimCurrentAlpha < mDimTargetAlpha) {
10408 more = false;
10409 }
10410 } else {
10411 more = false;
10412 }
10413
10414 // Do we need to continue animating?
10415 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010416 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010417 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10418 mLastDimAnimTime = currentTime;
10419 mDimSurface.setAlpha(mDimCurrentAlpha);
10420 animating = true;
10421 } else {
10422 mDimCurrentAlpha = mDimTargetAlpha;
10423 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010424 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010425 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10426 mDimSurface.setAlpha(mDimCurrentAlpha);
10427 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010428 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010429 + ": HIDE");
10430 try {
10431 mDimSurface.hide();
10432 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010433 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010434 }
10435 mDimShown = false;
10436 }
10437 }
10438 }
10439 return animating;
10440 }
10441
10442 public void printTo(PrintWriter pw) {
10443 pw.print(" mDimShown="); pw.print(mDimShown);
10444 pw.print(" current="); pw.print(mDimCurrentAlpha);
10445 pw.print(" target="); pw.print(mDimTargetAlpha);
10446 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10447 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10448 }
10449 }
10450
10451 /**
10452 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10453 * This is used for opening/closing transition for apps in compatible mode.
10454 */
10455 private static class FadeInOutAnimation extends Animation {
10456 int mWidth;
10457 boolean mFadeIn;
10458
10459 public FadeInOutAnimation(boolean fadeIn) {
10460 setInterpolator(new AccelerateInterpolator());
10461 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10462 mFadeIn = fadeIn;
10463 }
10464
10465 @Override
10466 protected void applyTransformation(float interpolatedTime, Transformation t) {
10467 float x = interpolatedTime;
10468 if (!mFadeIn) {
10469 x = 1.0f - x; // reverse the interpolation for fade out
10470 }
10471 if (x < 0.5) {
10472 // move the window out of the screen.
10473 t.getMatrix().setTranslate(mWidth, 0);
10474 } else {
10475 t.getMatrix().setTranslate(0, 0);// show
10476 t.setAlpha((x - 0.5f) * 2);
10477 }
10478 }
10479
10480 @Override
10481 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10482 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10483 mWidth = width;
10484 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010485
10486 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010487 public int getZAdjustment() {
10488 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010489 }
10490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491}