blob: 1c92da9e59c07d0404530b5eb30140469ab3e213 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070043import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import com.android.internal.view.IInputContext;
45import com.android.internal.view.IInputMethodClient;
46import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080047import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import com.android.server.am.BatteryStatsService;
49
50import android.Manifest;
51import android.app.ActivityManagerNative;
52import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070055import android.content.ClipData;
56import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070058import android.content.Intent;
59import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.pm.ActivityInfo;
61import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070068import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.graphics.Rect;
70import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070071import android.graphics.Typeface;
72import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.BatteryStats;
74import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070075import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.Debug;
77import android.os.Handler;
78import android.os.IBinder;
79import android.os.LocalPowerManager;
80import android.os.Looper;
81import android.os.Message;
82import android.os.Parcel;
83import android.os.ParcelFileDescriptor;
84import android.os.Power;
85import android.os.PowerManager;
86import android.os.Process;
87import android.os.RemoteException;
88import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070089import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.os.SystemClock;
91import android.os.SystemProperties;
92import android.os.TokenWatcher;
93import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070094import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070096import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080097import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070099import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700101import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700103import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104import android.view.IApplicationToken;
105import android.view.IOnKeyguardExitResult;
106import android.view.IRotationWatcher;
107import android.view.IWindow;
108import android.view.IWindowManager;
109import android.view.IWindowSession;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700110import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700111import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700112import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700113import android.view.InputHandler;
114import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.KeyEvent;
116import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117import android.view.Surface;
118import android.view.SurfaceSession;
119import android.view.View;
120import android.view.ViewTreeObserver;
121import android.view.WindowManager;
122import android.view.WindowManagerImpl;
123import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700124import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700126import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127import android.view.animation.Animation;
128import android.view.animation.AnimationUtils;
129import android.view.animation.Transformation;
130
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134import java.io.File;
135import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700136import java.io.FileInputStream;
137import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138import java.io.IOException;
139import java.io.OutputStream;
140import java.io.OutputStreamWriter;
141import java.io.PrintWriter;
142import java.io.StringWriter;
143import java.net.Socket;
144import java.util.ArrayList;
145import java.util.HashMap;
146import java.util.HashSet;
147import java.util.Iterator;
148import java.util.List;
149
150/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700151public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700152 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final String TAG = "WindowManager";
154 static final boolean DEBUG = false;
155 static final boolean DEBUG_FOCUS = false;
156 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800157 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800158 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 static final boolean DEBUG_LAYERS = false;
160 static final boolean DEBUG_INPUT = false;
161 static final boolean DEBUG_INPUT_METHOD = false;
162 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700163 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700165 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 static final boolean DEBUG_APP_TRANSITIONS = false;
167 static final boolean DEBUG_STARTING_WINDOW = false;
168 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700169 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700170 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700172 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 static final boolean PROFILE_ORIENTATION = false;
175 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700176 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to multiply the policy's type layer, to reserve room
179 * for multiple windows of the same type and Z-ordering adjustment
180 * with TYPE_LAYER_OFFSET. */
181 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
184 * or below others in the same layer. */
185 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 /** How much to increment the layer for each window, to reserve room
188 * for effect surfaces between them.
189 */
190 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 /** The maximum length we will accept for a loaded animation duration:
193 * this is 10 seconds.
194 */
195 static final int MAX_ANIMATION_DURATION = 10*1000;
196
197 /** Amount of time (in milliseconds) to animate the dim surface from one
198 * value to another, when no window animation is driving it.
199 */
200 static final int DEFAULT_DIM_DURATION = 200;
201
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700202 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
203 * compatible windows.
204 */
205 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 /** Adjustment to time to perform a dim, to make it more dramatic.
208 */
209 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700210
211 // Maximum number of milliseconds to wait for input event injection.
212 // FIXME is this value reasonable?
213 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700214
215 // Default input dispatching timeout in nanoseconds.
216 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 static final int UPDATE_FOCUS_NORMAL = 0;
219 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
220 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
221 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700224 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225
226 /**
227 * Condition waited on by {@link #reenableKeyguard} to know the call to
228 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 * This is set to true only if mKeyguardTokenWatcher.acquired() has
230 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500232 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233
Jim Miller284b62e2010-06-08 14:27:42 -0700234 private static final int ALLOW_DISABLE_YES = 1;
235 private static final int ALLOW_DISABLE_NO = 0;
236 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
237 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
238
Mike Lockwood983ee092009-11-22 01:42:24 -0500239 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
240 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700242 if (shouldAllowDisableKeyguard()) {
243 mPolicy.enableKeyguard(false);
244 mKeyguardDisabled = true;
245 } else {
246 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 }
249 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700250 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500251 synchronized (mKeyguardTokenWatcher) {
252 mKeyguardDisabled = false;
253 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
255 }
256 };
257
Jim Miller284b62e2010-06-08 14:27:42 -0700258 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
259 @Override
260 public void onReceive(Context context, Intent intent) {
261 mPolicy.enableKeyguard(true);
262 synchronized(mKeyguardTokenWatcher) {
263 // lazily evaluate this next time we're asked to disable keyguard
264 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
265 mKeyguardDisabled = false;
266 }
267 }
268 };
269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final Context mContext;
271
272 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
277
278 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 /**
283 * All currently active sessions with clients.
284 */
285 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 /**
288 * Mapping from an IWindow IBinder to the server's Window object.
289 * This is also used as the lock for all of our state.
290 */
291 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
292
293 /**
294 * Mapping from a token IBinder to a WindowToken object.
295 */
296 final HashMap<IBinder, WindowToken> mTokenMap =
297 new HashMap<IBinder, WindowToken>();
298
299 /**
300 * The same tokens as mTokenMap, stored in a list for efficient iteration
301 * over them.
302 */
303 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 /**
306 * Window tokens that are in the process of exiting, but still
307 * on screen for animations.
308 */
309 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
310
311 /**
312 * Z-ordered (bottom-most first) list of all application tokens, for
313 * controlling the ordering of windows in different applications. This
314 * contains WindowToken objects.
315 */
316 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
317
318 /**
319 * Application tokens that are in the process of exiting, but still
320 * on screen for animations.
321 */
322 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
323
324 /**
325 * List of window tokens that have finished starting their application,
326 * and now need to have the policy remove their windows.
327 */
328 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
329
330 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700331 * This was the app token that was used to retrieve the last enter
332 * animation. It will be used for the next exit animation.
333 */
334 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800335
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700336 /**
337 * These were the layout params used to retrieve the last enter animation.
338 * They will be used for the next exit animation.
339 */
340 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800341
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700342 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 * Z-ordered (bottom-most first) list of all Window objects.
344 */
Jeff Browne33348b2010-07-15 23:54:05 -0700345 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346
347 /**
348 * Windows that are being resized. Used so we can tell the client about
349 * the resize after closing the transaction in which we resized the
350 * underlying surface.
351 */
352 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
353
354 /**
355 * Windows whose animations have ended and now must be removed.
356 */
357 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
358
359 /**
360 * Windows whose surface should be destroyed.
361 */
362 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
363
364 /**
365 * Windows that have lost input focus and are waiting for the new
366 * focus window to be displayed before they are told about this.
367 */
368 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
369
370 /**
371 * This is set when we have run out of memory, and will either be an empty
372 * list or contain windows that need to be force removed.
373 */
374 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700379 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 Surface mBlurSurface;
381 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700382 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 final float[] mTmpFloats = new float[9];
387
388 boolean mSafeMode;
389 boolean mDisplayEnabled = false;
390 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700391 int mInitialDisplayWidth = 0;
392 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 int mRotation = 0;
394 int mRequestedRotation = 0;
395 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700396 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 ArrayList<IRotationWatcher> mRotationWatchers
398 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 boolean mLayoutNeeded = true;
401 boolean mAnimationPending = false;
402 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800403 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 boolean mWindowsFreezingScreen = false;
405 long mFreezeGcPending = 0;
406 int mAppsFreezingScreen = 0;
407
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800408 int mLayoutSeq = 0;
409
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800410 // State while inside of layoutAndPlaceSurfacesLocked().
411 boolean mFocusMayChange;
412
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800413 Configuration mCurConfiguration = new Configuration();
414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 // This is held as long as we have the screen frozen, to give us time to
416 // perform a rotation animation when turning off shows the lock screen which
417 // changes the orientation.
418 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 // State management of app transitions. When we are preparing for a
421 // transition, mNextAppTransition will be the kind of transition to
422 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
423 // mOpeningApps and mClosingApps are the lists of tokens that will be
424 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700425 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700426 String mNextAppTransitionPackage;
427 int mNextAppTransitionEnter;
428 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700430 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionTimeout = false;
432 boolean mStartingIconInTransition = false;
433 boolean mSkipAppTransitionAnimation = false;
434 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700436 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 H mH = new H();
442
443 WindowState mCurrentFocus = null;
444 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 // This just indicates the window the input method is on top of, not
447 // necessarily the window its input is going to.
448 WindowState mInputMethodTarget = null;
449 WindowState mUpcomingInputMethodTarget = null;
450 boolean mInputMethodTargetWaitingAnim;
451 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 WindowState mInputMethodWindow = null;
454 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
455
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700456 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800457
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700458 // If non-null, this is the currently visible window that is associated
459 // with the wallpaper.
460 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700461 // If non-null, we are in the middle of animating from one wallpaper target
462 // to another, and this is the lower one in Z-order.
463 WindowState mLowerWallpaperTarget = null;
464 // If non-null, we are in the middle of animating from one wallpaper target
465 // to another, and this is the higher one in Z-order.
466 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700467 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700468 float mLastWallpaperX = -1;
469 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800470 float mLastWallpaperXStep = -1;
471 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700472 // This is set when we are waiting for a wallpaper to tell us it is done
473 // changing its scroll position.
474 WindowState mWaitingOnWallpaper;
475 // The last time we had a timeout when waiting for a wallpaper.
476 long mLastWallpaperTimeoutTime;
477 // We give a wallpaper up to 150ms to finish scrolling.
478 static final long WALLPAPER_TIMEOUT = 150;
479 // Time we wait after a timeout before trying to wait again.
480 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 AppWindowToken mFocusedApp = null;
483
484 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 float mWindowAnimationScale = 1.0f;
487 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700488
Jeff Brown46b9ac02010-04-22 18:58:52 -0700489 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490
491 // Who is holding the screen on.
492 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700493 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700494
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700495 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700498 * Drag/drop state
499 */
500 class DragState {
501 IBinder mToken;
502 Surface mSurface;
503 boolean mLocalOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700504 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700505 ClipData mData;
506 ClipDescription mDataDescription;
Chris Tated4533f12010-10-19 15:15:08 -0700507 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700508 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 float mThumbOffsetX, mThumbOffsetY;
510 InputChannel mServerChannel, mClientChannel;
511 WindowState mTargetWindow;
512 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700513 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700514
515 private final Rect tmpRect = new Rect();
516
Chris Tate7b362e42010-11-04 16:02:52 -0700517 DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700518 mToken = token;
519 mSurface = surface;
520 mLocalOnly = localOnly;
Chris Tate7b362e42010-11-04 16:02:52 -0700521 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700522 mNotifiedWindows = new ArrayList<WindowState>();
523 }
524
525 void reset() {
526 if (mSurface != null) {
527 mSurface.destroy();
528 }
529 mSurface = null;
530 mLocalOnly = false;
Chris Tate7b362e42010-11-04 16:02:52 -0700531 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700532 mToken = null;
533 mData = null;
534 mThumbOffsetX = mThumbOffsetY = 0;
535 mNotifiedWindows = null;
536 }
537
538 void register() {
539 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
540 if (mClientChannel != null) {
541 Slog.e(TAG, "Duplicate register of drag input channel");
542 } else {
543 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
544 mServerChannel = channels[0];
545 mClientChannel = channels[1];
546 mInputManager.registerInputChannel(mServerChannel);
547 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
548 mH.getLooper().getQueue());
549 }
550 }
551
552 void unregister() {
553 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
554 if (mClientChannel == null) {
555 Slog.e(TAG, "Unregister of nonexistent drag input channel");
556 } else {
557 mInputManager.unregisterInputChannel(mServerChannel);
558 InputQueue.unregisterInputChannel(mClientChannel);
559 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700560 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700561 mClientChannel = null;
562 mServerChannel = null;
563 }
564 }
565
Chris Tatea32dcf72010-10-14 12:13:50 -0700566 int getDragLayerLw() {
567 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
568 * TYPE_LAYER_MULTIPLIER
569 + TYPE_LAYER_OFFSET;
570 }
571
Christopher Tatea53146c2010-09-07 11:57:52 -0700572 /* call out to each visible window/session informing it about the drag
573 */
Chris Tateb8203e92010-10-12 14:23:21 -0700574 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700575 // Cache a base-class instance of the clip metadata so that parceling
576 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700577 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700579 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700580
581 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700582 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 }
584
Christopher Tate2c095f32010-10-04 14:13:40 -0700585 final int N = mWindows.size();
586 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700587 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
590
591 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
592 * designated window is potentially a drop recipient. There are race situations
593 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
594 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700595 *
596 * This method clones the 'event' parameter if it's being delivered to the same
597 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 */
Chris Tateb478f462010-10-15 16:02:26 -0700599 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
600 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700601 // Don't actually send the event if the drag is supposed to be pinned
602 // to the originating window but 'newWin' is not that window.
603 if (mLocalOnly) {
604 final IBinder winBinder = newWin.mClient.asBinder();
605 if (winBinder != mLocalWin) {
606 if (DEBUG_DRAG) {
607 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
608 }
609 return;
610 }
611 }
612
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700613 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700614 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
615 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700616 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700617 try {
618 newWin.mClient.dispatchDragEvent(event);
619 // track each window that we've notified that the drag is starting
620 mNotifiedWindows.add(newWin);
621 } catch (RemoteException e) {
622 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700623 } finally {
624 // if the callee was local, the dispatch has already recycled the event
625 if (Process.myPid() != newWin.mSession.mPid) {
626 event.recycle();
627 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700628 }
629 }
630 }
631
632 /* helper - construct and send a DRAG_STARTED event only if the window has not
633 * previously been notified, i.e. it became visible after the drag operation
634 * was begun. This is a rare case.
635 */
636 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700637 if (mDragInProgress) {
638 // If we have sent the drag-started, we needn't do so again
639 for (WindowState ws : mNotifiedWindows) {
640 if (ws == newWin) {
641 return;
642 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700643 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700644 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700645 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700646 }
Chris Tateb478f462010-10-15 16:02:26 -0700647 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700648 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
650
Chris Tated4533f12010-10-19 15:15:08 -0700651 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700652 if (DEBUG_DRAG) {
653 Slog.d(TAG, "broadcasting DRAG_ENDED");
654 }
Chris Tated4533f12010-10-19 15:15:08 -0700655 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
656 0, 0, null, null, mDragResult);
657 for (WindowState ws: mNotifiedWindows) {
658 try {
659 ws.mClient.dispatchDragEvent(evt);
660 } catch (RemoteException e) {
661 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700662 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 }
Chris Tated4533f12010-10-19 15:15:08 -0700664 mNotifiedWindows.clear();
665 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700666 evt.recycle();
667 }
668
Chris Tated4533f12010-10-19 15:15:08 -0700669 void endDragLw() {
670 mDragState.broadcastDragEndedLw();
671
672 // stop intercepting input
673 mDragState.unregister();
674 mInputMonitor.updateInputWindowsLw();
675
676 // free our resources and drop all the object references
677 mDragState.reset();
678 mDragState = null;
679 }
680
Christopher Tatea53146c2010-09-07 11:57:52 -0700681 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700682 final int myPid = Process.myPid();
683
684 // Move the surface to the given touch
685 mSurface.openTransaction();
686 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
687 mSurface.closeTransaction();
688
689 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700690 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tate7b362e42010-11-04 16:02:52 -0700691 if (mLocalOnly) {
692 final IBinder touchedBinder = touchedWin.mClient.asBinder();
693 if (touchedBinder != mLocalWin) {
694 // This drag is pinned only to the originating window, but the drag
695 // point is outside that window. Pretend it's over empty space.
696 touchedWin = null;
697 }
698 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700699 try {
700 // have we dragged over a new window?
701 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
702 if (DEBUG_DRAG) {
703 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
704 }
705 // force DRAG_EXITED_EVENT if appropriate
706 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700707 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700708 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700709 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700710 if (myPid != mTargetWindow.mSession.mPid) {
711 evt.recycle();
712 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700713 }
714 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700715 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700716 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
717 }
718 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700719 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f12010-10-19 15:15:08 -0700720 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700721 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700722 if (myPid != touchedWin.mSession.mPid) {
723 evt.recycle();
724 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700725 }
726 } catch (RemoteException e) {
727 Slog.w(TAG, "can't send drag notification to windows");
728 }
729 mTargetWindow = touchedWin;
730 }
731
Chris Tated4533f12010-10-19 15:15:08 -0700732 // Tell the drop target about the data. Returns 'true' if we can immediately
733 // dispatch the global drag-ended message, 'false' if we need to wait for a
734 // result from the recipient.
735 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700736 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f12010-10-19 15:15:08 -0700737 if (touchedWin == null) {
738 // "drop" outside a valid window -- no recipient to apply a
739 // timeout to, and we can send the drag-ended message immediately.
740 mDragResult = false;
741 return true;
742 }
743
744 if (DEBUG_DRAG) {
745 Slog.d(TAG, "sending DROP to " + touchedWin);
746 }
747 final int myPid = Process.myPid();
748 final IBinder token = touchedWin.mClient.asBinder();
749 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
750 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
751 null, mData, false);
752 try {
753 touchedWin.mClient.dispatchDragEvent(evt);
754
755 // 5 second timeout for this window to respond to the drop
756 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
757 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
758 mH.sendMessageDelayed(msg, 5000);
759 } catch (RemoteException e) {
760 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
761 return true;
762 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700763 if (myPid != touchedWin.mSession.mPid) {
764 evt.recycle();
765 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700766 }
Chris Tated4533f12010-10-19 15:15:08 -0700767 mToken = token;
768 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700769 }
770
771 // Find the visible, touch-deliverable window under the given point
772 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
773 WindowState touchedWin = null;
774 final int x = (int) xf;
775 final int y = (int) yf;
776 final ArrayList<WindowState> windows = mWindows;
777 final int N = windows.size();
778 for (int i = N - 1; i >= 0; i--) {
779 WindowState child = windows.get(i);
780 final int flags = child.mAttrs.flags;
781 if (!child.isVisibleLw()) {
782 // not visible == don't tell about drags
783 continue;
784 }
785 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
786 // not touchable == don't tell about drags
787 continue;
788 }
789 // account for the window's decor etc
790 tmpRect.set(child.mFrame);
791 if (child.mTouchableInsets == ViewTreeObserver
792 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
793 // The point is inside of the window if it is
794 // inside the frame, AND the content part of that
795 // frame that was given by the application.
796 tmpRect.left += child.mGivenContentInsets.left;
797 tmpRect.top += child.mGivenContentInsets.top;
798 tmpRect.right -= child.mGivenContentInsets.right;
799 tmpRect.bottom -= child.mGivenContentInsets.bottom;
800 } else if (child.mTouchableInsets == ViewTreeObserver
801 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
802 // The point is inside of the window if it is
803 // inside the frame, AND the visible part of that
804 // frame that was given by the application.
805 tmpRect.left += child.mGivenVisibleInsets.left;
806 tmpRect.top += child.mGivenVisibleInsets.top;
807 tmpRect.right -= child.mGivenVisibleInsets.right;
808 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
809 }
810 final int touchFlags = flags &
811 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
812 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
813 if (tmpRect.contains(x, y) || touchFlags == 0) {
814 // Found it
815 touchedWin = child;
816 break;
817 }
818 }
819
820 return touchedWin;
821 }
822 }
823
824 DragState mDragState = null;
825 private final InputHandler mDragInputHandler = new BaseInputHandler() {
826 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700827 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
828 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700829 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700830 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
831 && mDragState != null) {
832 boolean endDrag = false;
833 final float newX = event.getRawX();
834 final float newY = event.getRawY();
835
Christopher Tatea53146c2010-09-07 11:57:52 -0700836 switch (event.getAction()) {
837 case MotionEvent.ACTION_DOWN: {
838 if (DEBUG_DRAG) {
839 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
840 }
841 } break;
842
843 case MotionEvent.ACTION_MOVE: {
844 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700845 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700846 mDragState.notifyMoveLw(newX, newY);
847 }
848 } break;
849
850 case MotionEvent.ACTION_UP: {
851 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
852 + newX + "," + newY);
853 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700854 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700855 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700856 } break;
857
858 case MotionEvent.ACTION_CANCEL: {
859 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
860 endDrag = true;
861 } break;
862 }
863
864 if (endDrag) {
865 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
866 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700867 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700868 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700869 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700870 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700871
872 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700873 }
874 } catch (Exception e) {
875 Slog.e(TAG, "Exception caught by drag handleMotion", e);
876 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700877 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700878 }
879 }
880 };
881
882 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 * Whether the UI is currently running in touch mode (not showing
884 * navigational focus because the user is directly pressing the screen).
885 */
886 boolean mInTouchMode = false;
887
888 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700889 private ArrayList<WindowChangeListener> mWindowChangeListeners =
890 new ArrayList<WindowChangeListener>();
891 private boolean mWindowsChanged = false;
892
893 public interface WindowChangeListener {
894 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700895 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700896 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897
Dianne Hackbornc485a602009-03-24 22:39:49 -0700898 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700899 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700900
901 // The frame use to limit the size of the app running in compatibility mode.
902 Rect mCompatibleScreenFrame = new Rect();
903 // The surface used to fill the outer rim of the app running in compatibility mode.
904 Surface mBackgroundFillerSurface = null;
905 boolean mBackgroundFillerShown = false;
906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 public static WindowManagerService main(Context context,
908 PowerManagerService pm, boolean haveInputMethods) {
909 WMThread thr = new WMThread(context, pm, haveInputMethods);
910 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 synchronized (thr) {
913 while (thr.mService == null) {
914 try {
915 thr.wait();
916 } catch (InterruptedException e) {
917 }
918 }
919 }
Romain Guy06882f82009-06-10 13:36:04 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 return thr.mService;
922 }
Romain Guy06882f82009-06-10 13:36:04 -0700923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 static class WMThread extends Thread {
925 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 private final Context mContext;
928 private final PowerManagerService mPM;
929 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 public WMThread(Context context, PowerManagerService pm,
932 boolean haveInputMethods) {
933 super("WindowManager");
934 mContext = context;
935 mPM = pm;
936 mHaveInputMethods = haveInputMethods;
937 }
Romain Guy06882f82009-06-10 13:36:04 -0700938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 public void run() {
940 Looper.prepare();
941 WindowManagerService s = new WindowManagerService(mContext, mPM,
942 mHaveInputMethods);
943 android.os.Process.setThreadPriority(
944 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700945 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 synchronized (this) {
948 mService = s;
949 notifyAll();
950 }
Romain Guy06882f82009-06-10 13:36:04 -0700951
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700952 // For debug builds, log event loop stalls to dropbox for analysis.
953 if (StrictMode.conditionallyEnableDebugLogging()) {
954 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
955 }
956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 Looper.loop();
958 }
959 }
960
961 static class PolicyThread extends Thread {
962 private final WindowManagerPolicy mPolicy;
963 private final WindowManagerService mService;
964 private final Context mContext;
965 private final PowerManagerService mPM;
966 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 public PolicyThread(WindowManagerPolicy policy,
969 WindowManagerService service, Context context,
970 PowerManagerService pm) {
971 super("WindowManagerPolicy");
972 mPolicy = policy;
973 mService = service;
974 mContext = context;
975 mPM = pm;
976 }
Romain Guy06882f82009-06-10 13:36:04 -0700977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 public void run() {
979 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800980 WindowManagerPolicyThread.set(this, Looper.myLooper());
981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800983 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 android.os.Process.setThreadPriority(
985 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700986 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 synchronized (this) {
990 mRunning = true;
991 notifyAll();
992 }
Romain Guy06882f82009-06-10 13:36:04 -0700993
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700994 // For debug builds, log event loop stalls to dropbox for analysis.
995 if (StrictMode.conditionallyEnableDebugLogging()) {
996 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
997 }
998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 Looper.loop();
1000 }
1001 }
1002
1003 private WindowManagerService(Context context, PowerManagerService pm,
1004 boolean haveInputMethods) {
1005 mContext = context;
1006 mHaveInputMethods = haveInputMethods;
1007 mLimitedAlphaCompositing = context.getResources().getBoolean(
1008 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 mPowerManager = pm;
1011 mPowerManager.setPolicy(mPolicy);
1012 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1013 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1014 "SCREEN_FROZEN");
1015 mScreenFrozenLock.setReferenceCounted(false);
1016
1017 mActivityManager = ActivityManagerNative.getDefault();
1018 mBatteryStats = BatteryStatsService.getService();
1019
1020 // Get persisted window scale setting
1021 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1022 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1023 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1024 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001025
Jim Miller284b62e2010-06-08 14:27:42 -07001026 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1027 IntentFilter filter = new IntentFilter();
1028 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1029 mContext.registerReceiver(mBroadcastReceiver, filter);
1030
Jeff Brown46b9ac02010-04-22 18:58:52 -07001031 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1032 "KEEP_SCREEN_ON_FLAG");
1033 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034
Jeff Browne33348b2010-07-15 23:54:05 -07001035 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1038 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 synchronized (thr) {
1041 while (!thr.mRunning) {
1042 try {
1043 thr.wait();
1044 } catch (InterruptedException e) {
1045 }
1046 }
1047 }
Romain Guy06882f82009-06-10 13:36:04 -07001048
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001049 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 // Add ourself to the Watchdog monitors.
1052 Watchdog.getInstance().addMonitor(this);
1053 }
1054
1055 @Override
1056 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1057 throws RemoteException {
1058 try {
1059 return super.onTransact(code, data, reply, flags);
1060 } catch (RuntimeException e) {
1061 // The window manager only throws security exceptions, so let's
1062 // log all others.
1063 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001064 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 }
1066 throw e;
1067 }
1068 }
1069
Jeff Browne33348b2010-07-15 23:54:05 -07001070 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001072 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 TAG, "Adding window " + window + " at "
1074 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1075 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001076 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 }
1078
Jeff Browne33348b2010-07-15 23:54:05 -07001079 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001081 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 TAG, "Adding window " + window + " at "
1083 + i + " of " + mWindows.size() + " (before " + pos + ")");
1084 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001085 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 }
1087
1088 //This method finds out the index of a window that has the same app token as
1089 //win. used for z ordering the windows in mWindows
1090 private int findIdxBasedOnAppTokens(WindowState win) {
1091 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001092 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 int jmax = localmWindows.size();
1094 if(jmax == 0) {
1095 return -1;
1096 }
1097 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001098 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 if(wentry.mAppToken == win.mAppToken) {
1100 return j;
1101 }
1102 }
1103 return -1;
1104 }
Romain Guy06882f82009-06-10 13:36:04 -07001105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1107 final IWindow client = win.mClient;
1108 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001109 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 final int N = localmWindows.size();
1112 final WindowState attached = win.mAttachedWindow;
1113 int i;
1114 if (attached == null) {
1115 int tokenWindowsPos = token.windows.size();
1116 if (token.appWindowToken != null) {
1117 int index = tokenWindowsPos-1;
1118 if (index >= 0) {
1119 // If this application has existing windows, we
1120 // simply place the new window on top of them... but
1121 // keep the starting window on top.
1122 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1123 // Base windows go behind everything else.
1124 placeWindowBefore(token.windows.get(0), win);
1125 tokenWindowsPos = 0;
1126 } else {
1127 AppWindowToken atoken = win.mAppToken;
1128 if (atoken != null &&
1129 token.windows.get(index) == atoken.startingWindow) {
1130 placeWindowBefore(token.windows.get(index), win);
1131 tokenWindowsPos--;
1132 } else {
1133 int newIdx = findIdxBasedOnAppTokens(win);
1134 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001135 //there is a window above this one associated with the same
1136 //apptoken note that the window could be a floating window
1137 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001139 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001140 TAG, "Adding window " + win + " at "
1141 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001143 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 }
1146 }
1147 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001148 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 TAG, "Figuring out where to add app window "
1150 + client.asBinder() + " (token=" + token + ")");
1151 // Figure out where the window should go, based on the
1152 // order of applications.
1153 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001154 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 for (i=NA-1; i>=0; i--) {
1156 AppWindowToken t = mAppTokens.get(i);
1157 if (t == token) {
1158 i--;
1159 break;
1160 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001161
Dianne Hackborna8f60182009-09-01 19:01:50 -07001162 // We haven't reached the token yet; if this token
1163 // is not going to the bottom and has windows, we can
1164 // use it as an anchor for when we do reach the token.
1165 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 pos = t.windows.get(0);
1167 }
1168 }
1169 // We now know the index into the apps. If we found
1170 // an app window above, that gives us the position; else
1171 // we need to look some more.
1172 if (pos != null) {
1173 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001174 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 if (atoken != null) {
1176 final int NC = atoken.windows.size();
1177 if (NC > 0) {
1178 WindowState bottom = atoken.windows.get(0);
1179 if (bottom.mSubLayer < 0) {
1180 pos = bottom;
1181 }
1182 }
1183 }
1184 placeWindowBefore(pos, win);
1185 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001186 // Continue looking down until we find the first
1187 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 while (i >= 0) {
1189 AppWindowToken t = mAppTokens.get(i);
1190 final int NW = t.windows.size();
1191 if (NW > 0) {
1192 pos = t.windows.get(NW-1);
1193 break;
1194 }
1195 i--;
1196 }
1197 if (pos != null) {
1198 // Move in front of any windows attached to this
1199 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001200 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 if (atoken != null) {
1202 final int NC = atoken.windows.size();
1203 if (NC > 0) {
1204 WindowState top = atoken.windows.get(NC-1);
1205 if (top.mSubLayer >= 0) {
1206 pos = top;
1207 }
1208 }
1209 }
1210 placeWindowAfter(pos, win);
1211 } else {
1212 // Just search for the start of this layer.
1213 final int myLayer = win.mBaseLayer;
1214 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001215 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 if (w.mBaseLayer > myLayer) {
1217 break;
1218 }
1219 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001220 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001221 TAG, "Adding window " + win + " at "
1222 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001224 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 }
1226 }
1227 }
1228 } else {
1229 // Figure out where window should go, based on layer.
1230 final int myLayer = win.mBaseLayer;
1231 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001232 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 i++;
1234 break;
1235 }
1236 }
1237 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001238 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001239 TAG, "Adding window " + win + " at "
1240 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001242 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 }
1244 if (addToToken) {
1245 token.windows.add(tokenWindowsPos, win);
1246 }
1247
1248 } else {
1249 // Figure out this window's ordering relative to the window
1250 // it is attached to.
1251 final int NA = token.windows.size();
1252 final int sublayer = win.mSubLayer;
1253 int largestSublayer = Integer.MIN_VALUE;
1254 WindowState windowWithLargestSublayer = null;
1255 for (i=0; i<NA; i++) {
1256 WindowState w = token.windows.get(i);
1257 final int wSublayer = w.mSubLayer;
1258 if (wSublayer >= largestSublayer) {
1259 largestSublayer = wSublayer;
1260 windowWithLargestSublayer = w;
1261 }
1262 if (sublayer < 0) {
1263 // For negative sublayers, we go below all windows
1264 // in the same sublayer.
1265 if (wSublayer >= sublayer) {
1266 if (addToToken) {
1267 token.windows.add(i, win);
1268 }
1269 placeWindowBefore(
1270 wSublayer >= 0 ? attached : w, win);
1271 break;
1272 }
1273 } else {
1274 // For positive sublayers, we go above all windows
1275 // in the same sublayer.
1276 if (wSublayer > sublayer) {
1277 if (addToToken) {
1278 token.windows.add(i, win);
1279 }
1280 placeWindowBefore(w, win);
1281 break;
1282 }
1283 }
1284 }
1285 if (i >= NA) {
1286 if (addToToken) {
1287 token.windows.add(win);
1288 }
1289 if (sublayer < 0) {
1290 placeWindowBefore(attached, win);
1291 } else {
1292 placeWindowAfter(largestSublayer >= 0
1293 ? windowWithLargestSublayer
1294 : attached,
1295 win);
1296 }
1297 }
1298 }
Romain Guy06882f82009-06-10 13:36:04 -07001299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 if (win.mAppToken != null && addToToken) {
1301 win.mAppToken.allAppWindows.add(win);
1302 }
1303 }
Romain Guy06882f82009-06-10 13:36:04 -07001304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 static boolean canBeImeTarget(WindowState w) {
1306 final int fl = w.mAttrs.flags
1307 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1308 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1309 return w.isVisibleOrAdding();
1310 }
1311 return false;
1312 }
Romain Guy06882f82009-06-10 13:36:04 -07001313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001315 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 final int N = localmWindows.size();
1317 WindowState w = null;
1318 int i = N;
1319 while (i > 0) {
1320 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001321 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001322
Joe Onorato8a9b2202010-02-26 18:56:32 -08001323 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 // + Integer.toHexString(w.mAttrs.flags));
1325 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001326 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 // Yet more tricksyness! If this window is a "starting"
1329 // window, we do actually want to be on top of it, but
1330 // it is not -really- where input will go. So if the caller
1331 // is not actually looking to move the IME, look down below
1332 // for a real window to target...
1333 if (!willMove
1334 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1335 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001336 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1338 i--;
1339 w = wb;
1340 }
1341 }
1342 break;
1343 }
1344 }
Romain Guy06882f82009-06-10 13:36:04 -07001345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001347
Joe Onorato8a9b2202010-02-26 18:56:32 -08001348 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 if (willMove && w != null) {
1352 final WindowState curTarget = mInputMethodTarget;
1353 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001355 // Now some fun for dealing with window animations that
1356 // modify the Z order. We need to look at all windows below
1357 // the current target that are in this app, finding the highest
1358 // visible one in layering.
1359 AppWindowToken token = curTarget.mAppToken;
1360 WindowState highestTarget = null;
1361 int highestPos = 0;
1362 if (token.animating || token.animation != null) {
1363 int pos = 0;
1364 pos = localmWindows.indexOf(curTarget);
1365 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001366 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 if (win.mAppToken != token) {
1368 break;
1369 }
1370 if (!win.mRemoved) {
1371 if (highestTarget == null || win.mAnimLayer >
1372 highestTarget.mAnimLayer) {
1373 highestTarget = win;
1374 highestPos = pos;
1375 }
1376 }
1377 pos--;
1378 }
1379 }
Romain Guy06882f82009-06-10 13:36:04 -07001380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001381 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001382 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 + mNextAppTransition + " " + highestTarget
1384 + " animating=" + highestTarget.isAnimating()
1385 + " layer=" + highestTarget.mAnimLayer
1386 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001387
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001388 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 // If we are currently setting up for an animation,
1390 // hold everything until we can find out what will happen.
1391 mInputMethodTargetWaitingAnim = true;
1392 mInputMethodTarget = highestTarget;
1393 return highestPos + 1;
1394 } else if (highestTarget.isAnimating() &&
1395 highestTarget.mAnimLayer > w.mAnimLayer) {
1396 // If the window we are currently targeting is involved
1397 // with an animation, and it is on top of the next target
1398 // we will be over, then hold off on moving until
1399 // that is done.
1400 mInputMethodTarget = highestTarget;
1401 return highestPos + 1;
1402 }
1403 }
1404 }
1405 }
Romain Guy06882f82009-06-10 13:36:04 -07001406
Joe Onorato8a9b2202010-02-26 18:56:32 -08001407 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 if (w != null) {
1409 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001410 if (DEBUG_INPUT_METHOD) {
1411 RuntimeException e = null;
1412 if (!HIDE_STACK_CRAWLS) {
1413 e = new RuntimeException();
1414 e.fillInStackTrace();
1415 }
1416 Slog.w(TAG, "Moving IM target from "
1417 + mInputMethodTarget + " to " + w, e);
1418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 mInputMethodTarget = w;
1420 if (w.mAppToken != null) {
1421 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1422 } else {
1423 setInputMethodAnimLayerAdjustment(0);
1424 }
1425 }
1426 return i+1;
1427 }
1428 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001429 if (DEBUG_INPUT_METHOD) {
1430 RuntimeException e = null;
1431 if (!HIDE_STACK_CRAWLS) {
1432 e = new RuntimeException();
1433 e.fillInStackTrace();
1434 }
1435 Slog.w(TAG, "Moving IM target from "
1436 + mInputMethodTarget + " to null", e);
1437 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 mInputMethodTarget = null;
1439 setInputMethodAnimLayerAdjustment(0);
1440 }
1441 return -1;
1442 }
Romain Guy06882f82009-06-10 13:36:04 -07001443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 void addInputMethodWindowToListLocked(WindowState win) {
1445 int pos = findDesiredInputMethodWindowIndexLocked(true);
1446 if (pos >= 0) {
1447 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001448 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001449 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001451 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 moveInputMethodDialogsLocked(pos+1);
1453 return;
1454 }
1455 win.mTargetAppToken = null;
1456 addWindowToListInOrderLocked(win, true);
1457 moveInputMethodDialogsLocked(pos);
1458 }
Romain Guy06882f82009-06-10 13:36:04 -07001459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001461 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 mInputMethodAnimLayerAdjustment = adj;
1463 WindowState imw = mInputMethodWindow;
1464 if (imw != null) {
1465 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001466 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 + " anim layer: " + imw.mAnimLayer);
1468 int wi = imw.mChildWindows.size();
1469 while (wi > 0) {
1470 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001471 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001473 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 + " anim layer: " + cw.mAnimLayer);
1475 }
1476 }
1477 int di = mInputMethodDialogs.size();
1478 while (di > 0) {
1479 di --;
1480 imw = mInputMethodDialogs.get(di);
1481 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001482 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 + " anim layer: " + imw.mAnimLayer);
1484 }
1485 }
Romain Guy06882f82009-06-10 13:36:04 -07001486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1488 int wpos = mWindows.indexOf(win);
1489 if (wpos >= 0) {
1490 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001491 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001493 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 int NC = win.mChildWindows.size();
1495 while (NC > 0) {
1496 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001497 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 int cpos = mWindows.indexOf(cw);
1499 if (cpos >= 0) {
1500 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001501 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001502 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 mWindows.remove(cpos);
1504 }
1505 }
1506 }
1507 return interestingPos;
1508 }
Romain Guy06882f82009-06-10 13:36:04 -07001509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 private void reAddWindowToListInOrderLocked(WindowState win) {
1511 addWindowToListInOrderLocked(win, false);
1512 // This is a hack to get all of the child windows added as well
1513 // at the right position. Child windows should be rare and
1514 // this case should be rare, so it shouldn't be that big a deal.
1515 int wpos = mWindows.indexOf(win);
1516 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001517 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001518 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001520 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 reAddWindowLocked(wpos, win);
1522 }
1523 }
Romain Guy06882f82009-06-10 13:36:04 -07001524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 void logWindowList(String prefix) {
1526 int N = mWindows.size();
1527 while (N > 0) {
1528 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001529 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530 }
1531 }
Romain Guy06882f82009-06-10 13:36:04 -07001532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 void moveInputMethodDialogsLocked(int pos) {
1534 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001537 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 for (int i=0; i<N; i++) {
1539 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1540 }
1541 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001542 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 logWindowList(" ");
1544 }
Romain Guy06882f82009-06-10 13:36:04 -07001545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 if (pos >= 0) {
1547 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1548 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001549 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 if (wp == mInputMethodWindow) {
1551 pos++;
1552 }
1553 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001554 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 for (int i=0; i<N; i++) {
1556 WindowState win = dialogs.get(i);
1557 win.mTargetAppToken = targetAppToken;
1558 pos = reAddWindowLocked(pos, win);
1559 }
1560 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001561 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 logWindowList(" ");
1563 }
1564 return;
1565 }
1566 for (int i=0; i<N; i++) {
1567 WindowState win = dialogs.get(i);
1568 win.mTargetAppToken = null;
1569 reAddWindowToListInOrderLocked(win);
1570 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001571 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 logWindowList(" ");
1573 }
1574 }
1575 }
Romain Guy06882f82009-06-10 13:36:04 -07001576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1578 final WindowState imWin = mInputMethodWindow;
1579 final int DN = mInputMethodDialogs.size();
1580 if (imWin == null && DN == 0) {
1581 return false;
1582 }
Romain Guy06882f82009-06-10 13:36:04 -07001583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1585 if (imPos >= 0) {
1586 // In this case, the input method windows are to be placed
1587 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 // First check to see if the input method windows are already
1590 // located here, and contiguous.
1591 final int N = mWindows.size();
1592 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001593 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 // Figure out the actual input method window that should be
1596 // at the bottom of their stack.
1597 WindowState baseImWin = imWin != null
1598 ? imWin : mInputMethodDialogs.get(0);
1599 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001600 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 if (cw.mSubLayer < 0) baseImWin = cw;
1602 }
Romain Guy06882f82009-06-10 13:36:04 -07001603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 if (firstImWin == baseImWin) {
1605 // The windows haven't moved... but are they still contiguous?
1606 // First find the top IM window.
1607 int pos = imPos+1;
1608 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001609 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 break;
1611 }
1612 pos++;
1613 }
1614 pos++;
1615 // Now there should be no more input method windows above.
1616 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001617 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 break;
1619 }
1620 pos++;
1621 }
1622 if (pos >= N) {
1623 // All is good!
1624 return false;
1625 }
1626 }
Romain Guy06882f82009-06-10 13:36:04 -07001627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 if (imWin != null) {
1629 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001630 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001631 logWindowList(" ");
1632 }
1633 imPos = tmpRemoveWindowLocked(imPos, imWin);
1634 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001635 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 logWindowList(" ");
1637 }
1638 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1639 reAddWindowLocked(imPos, imWin);
1640 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001641 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 logWindowList(" ");
1643 }
1644 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1645 } else {
1646 moveInputMethodDialogsLocked(imPos);
1647 }
Romain Guy06882f82009-06-10 13:36:04 -07001648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 } else {
1650 // In this case, the input method windows go in a fixed layer,
1651 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 tmpRemoveWindowLocked(0, imWin);
1656 imWin.mTargetAppToken = null;
1657 reAddWindowToListInOrderLocked(imWin);
1658 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001659 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 logWindowList(" ");
1661 }
1662 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1663 } else {
1664 moveInputMethodDialogsLocked(-1);;
1665 }
Romain Guy06882f82009-06-10 13:36:04 -07001666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 }
Romain Guy06882f82009-06-10 13:36:04 -07001668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 if (needAssignLayers) {
1670 assignLayersLocked();
1671 }
Romain Guy06882f82009-06-10 13:36:04 -07001672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 return true;
1674 }
Romain Guy06882f82009-06-10 13:36:04 -07001675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676 void adjustInputMethodDialogsLocked() {
1677 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1678 }
Romain Guy06882f82009-06-10 13:36:04 -07001679
Dianne Hackborn25994b42009-09-04 14:21:19 -07001680 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001681 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001682 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1683 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1684 ? wallpaperTarget.mAppToken.animation : null)
1685 + " upper=" + mUpperWallpaperTarget
1686 + " lower=" + mLowerWallpaperTarget);
1687 return (wallpaperTarget != null
1688 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1689 && wallpaperTarget.mAppToken.animation != null)))
1690 || mUpperWallpaperTarget != null
1691 || mLowerWallpaperTarget != null;
1692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001693
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001694 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1695 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001696
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001697 int adjustWallpaperWindowsLocked() {
1698 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001699
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001700 final int dw = mDisplay.getWidth();
1701 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001702
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001703 // First find top-most window that has asked to be on top of the
1704 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001705 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001706 int N = localmWindows.size();
1707 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001708 WindowState foundW = null;
1709 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001710 WindowState topCurW = null;
1711 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001712 int i = N;
1713 while (i > 0) {
1714 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001715 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001716 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1717 if (topCurW == null) {
1718 topCurW = w;
1719 topCurI = i;
1720 }
1721 continue;
1722 }
1723 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001724 if (w.mAppToken != null) {
1725 // If this window's app token is hidden and not animating,
1726 // it is of no interest to us.
1727 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001728 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001729 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001730 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001731 continue;
1732 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001733 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001734 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001735 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1736 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001737 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001738 && (mWallpaperTarget == w
1739 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001740 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001742 foundW = w;
1743 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001744 if (w == mWallpaperTarget && ((w.mAppToken != null
1745 && w.mAppToken.animation != null)
1746 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001747 // The current wallpaper target is animating, so we'll
1748 // look behind it for another possible target and figure
1749 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001750 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001751 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001752 continue;
1753 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001754 break;
1755 }
1756 }
1757
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001758 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001759 // If we are currently waiting for an app transition, and either
1760 // the current target or the next target are involved with it,
1761 // then hold off on doing anything with the wallpaper.
1762 // Note that we are checking here for just whether the target
1763 // is part of an app token... which is potentially overly aggressive
1764 // (the app token may not be involved in the transition), but good
1765 // enough (we'll just wait until whatever transition is pending
1766 // executes).
1767 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001768 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001769 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001770 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001771 }
1772 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001773 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001774 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001775 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001776 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001778
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001779 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001780 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001781 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001782 + " oldTarget: " + mWallpaperTarget);
1783 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001784
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001785 mLowerWallpaperTarget = null;
1786 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001787
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001788 WindowState oldW = mWallpaperTarget;
1789 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001790
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001791 // Now what is happening... if the current and new targets are
1792 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001793 if (foundW != null && oldW != null) {
1794 boolean oldAnim = oldW.mAnimation != null
1795 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1796 boolean foundAnim = foundW.mAnimation != null
1797 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001798 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001799 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001800 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001802 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001803 int oldI = localmWindows.indexOf(oldW);
1804 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001805 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 }
1807 if (oldI >= 0) {
1808 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001810 + "=" + oldW + "; new#" + foundI
1811 + "=" + foundW);
1812 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001813
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001815 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001816 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001817 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 }
1819 mWallpaperTarget = oldW;
1820 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001821
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001822 // Now set the upper and lower wallpaper targets
1823 // correctly, and make sure that we are positioning
1824 // the wallpaper below the lower.
1825 if (foundI > oldI) {
1826 // The new target is on top of the old one.
1827 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001828 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001829 }
1830 mUpperWallpaperTarget = foundW;
1831 mLowerWallpaperTarget = oldW;
1832 foundW = oldW;
1833 foundI = oldI;
1834 } else {
1835 // The new target is below the old one.
1836 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001837 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001838 }
1839 mUpperWallpaperTarget = oldW;
1840 mLowerWallpaperTarget = foundW;
1841 }
1842 }
1843 }
1844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001845
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001846 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001847 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001848 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1849 || (mLowerWallpaperTarget.mAppToken != null
1850 && mLowerWallpaperTarget.mAppToken.animation != null);
1851 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1852 || (mUpperWallpaperTarget.mAppToken != null
1853 && mUpperWallpaperTarget.mAppToken.animation != null);
1854 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001855 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001856 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001857 }
1858 mLowerWallpaperTarget = null;
1859 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001860 }
1861 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001862
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001863 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001864 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001865 // The window is visible to the compositor... but is it visible
1866 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001867 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001869
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001870 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001871 // its layer adjustment. Only do this if we are not transfering
1872 // between two wallpaper targets.
1873 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001874 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001875 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001876
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001877 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1878 * TYPE_LAYER_MULTIPLIER
1879 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001880
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001881 // Now w is the window we are supposed to be behind... but we
1882 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001883 // AND any starting window associated with it, AND below the
1884 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001885 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001886 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001887 if (wb.mBaseLayer < maxLayer &&
1888 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001889 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001890 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001891 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001892 // This window is not related to the previous one in any
1893 // interesting way, so stop here.
1894 break;
1895 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001896 foundW = wb;
1897 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001898 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001899 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001900 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001901 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001902
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001903 if (foundW == null && topCurW != null) {
1904 // There is no wallpaper target, so it goes at the bottom.
1905 // We will assume it is the same place as last time, if known.
1906 foundW = topCurW;
1907 foundI = topCurI+1;
1908 } else {
1909 // Okay i is the position immediately above the wallpaper. Look at
1910 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001911 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001912 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001913
Dianne Hackborn284ac932009-08-28 10:34:25 -07001914 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001915 if (mWallpaperTarget.mWallpaperX >= 0) {
1916 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001917 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001918 }
1919 if (mWallpaperTarget.mWallpaperY >= 0) {
1920 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001921 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001922 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001923 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001924
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001925 // Start stepping backwards from here, ensuring that our wallpaper windows
1926 // are correctly placed.
1927 int curTokenIndex = mWallpaperTokens.size();
1928 while (curTokenIndex > 0) {
1929 curTokenIndex--;
1930 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001931 if (token.hidden == visible) {
1932 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1933 token.hidden = !visible;
1934 // Need to do a layout to ensure the wallpaper now has the
1935 // correct size.
1936 mLayoutNeeded = true;
1937 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001938
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001939 int curWallpaperIndex = token.windows.size();
1940 while (curWallpaperIndex > 0) {
1941 curWallpaperIndex--;
1942 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001943
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001944 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001945 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001946 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001947
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001948 // First, make sure the client has the current visibility
1949 // state.
1950 if (wallpaper.mWallpaperVisible != visible) {
1951 wallpaper.mWallpaperVisible = visible;
1952 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001953 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001954 "Setting visibility of wallpaper " + wallpaper
1955 + ": " + visible);
1956 wallpaper.mClient.dispatchAppVisibility(visible);
1957 } catch (RemoteException e) {
1958 }
1959 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001960
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001961 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001962 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001963 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001964
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001965 // First, if this window is at the current index, then all
1966 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001967 if (wallpaper == foundW) {
1968 foundI--;
1969 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001970 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001971 continue;
1972 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001973
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001974 // The window didn't match... the current wallpaper window,
1975 // wherever it is, is in the wrong place, so make sure it is
1976 // not in the list.
1977 int oldIndex = localmWindows.indexOf(wallpaper);
1978 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001979 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001980 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001982 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001983 if (oldIndex < foundI) {
1984 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001985 }
1986 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001987
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001988 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001989 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001990 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001991 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001992
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001993 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001994 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001995 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001996 }
1997 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001998
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001999 return changed;
2000 }
2001
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002002 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002003 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002004 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002005 mWallpaperAnimLayerAdjustment = adj;
2006 int curTokenIndex = mWallpaperTokens.size();
2007 while (curTokenIndex > 0) {
2008 curTokenIndex--;
2009 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2010 int curWallpaperIndex = token.windows.size();
2011 while (curWallpaperIndex > 0) {
2012 curWallpaperIndex--;
2013 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2014 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002015 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002016 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002017 }
2018 }
2019 }
2020
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002021 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2022 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002023 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002024 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002025 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002026 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002027 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2028 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2029 changed = wallpaperWin.mXOffset != offset;
2030 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002031 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002032 + wallpaperWin + " x: " + offset);
2033 wallpaperWin.mXOffset = offset;
2034 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002035 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002036 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002037 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002038 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002039 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002040
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002041 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002042 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002043 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2044 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2045 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002046 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002047 + wallpaperWin + " y: " + offset);
2048 changed = true;
2049 wallpaperWin.mYOffset = offset;
2050 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002051 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002052 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002053 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002054 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002055 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002056
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002057 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002058 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002059 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002060 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2061 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002062 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002063 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002064 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002065 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002066 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2067 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002068 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002069 if (mWaitingOnWallpaper != null) {
2070 long start = SystemClock.uptimeMillis();
2071 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2072 < start) {
2073 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002074 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002075 "Waiting for offset complete...");
2076 mWindowMap.wait(WALLPAPER_TIMEOUT);
2077 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002078 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002079 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002080 if ((start+WALLPAPER_TIMEOUT)
2081 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002082 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002083 + wallpaperWin);
2084 mLastWallpaperTimeoutTime = start;
2085 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002086 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002087 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002088 }
2089 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002090 } catch (RemoteException e) {
2091 }
2092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002093
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002094 return changed;
2095 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002096
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002097 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002098 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002099 if (mWaitingOnWallpaper != null &&
2100 mWaitingOnWallpaper.mClient.asBinder() == window) {
2101 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002102 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002103 }
2104 }
2105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002106
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002107 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002108 final int dw = mDisplay.getWidth();
2109 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002110
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002111 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002112
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002113 WindowState target = mWallpaperTarget;
2114 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002115 if (target.mWallpaperX >= 0) {
2116 mLastWallpaperX = target.mWallpaperX;
2117 } else if (changingTarget.mWallpaperX >= 0) {
2118 mLastWallpaperX = changingTarget.mWallpaperX;
2119 }
2120 if (target.mWallpaperY >= 0) {
2121 mLastWallpaperY = target.mWallpaperY;
2122 } else if (changingTarget.mWallpaperY >= 0) {
2123 mLastWallpaperY = changingTarget.mWallpaperY;
2124 }
2125 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002126
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002127 int curTokenIndex = mWallpaperTokens.size();
2128 while (curTokenIndex > 0) {
2129 curTokenIndex--;
2130 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2131 int curWallpaperIndex = token.windows.size();
2132 while (curWallpaperIndex > 0) {
2133 curWallpaperIndex--;
2134 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2135 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2136 wallpaper.computeShownFrameLocked();
2137 changed = true;
2138 // We only want to be synchronous with one wallpaper.
2139 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002140 }
2141 }
2142 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002143
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002144 return changed;
2145 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002146
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002147 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002148 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002149 final int dw = mDisplay.getWidth();
2150 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002151
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002152 int curTokenIndex = mWallpaperTokens.size();
2153 while (curTokenIndex > 0) {
2154 curTokenIndex--;
2155 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002156 if (token.hidden == visible) {
2157 token.hidden = !visible;
2158 // Need to do a layout to ensure the wallpaper now has the
2159 // correct size.
2160 mLayoutNeeded = true;
2161 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002162
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002163 int curWallpaperIndex = token.windows.size();
2164 while (curWallpaperIndex > 0) {
2165 curWallpaperIndex--;
2166 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2167 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002168 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002169 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002170
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002171 if (wallpaper.mWallpaperVisible != visible) {
2172 wallpaper.mWallpaperVisible = visible;
2173 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002174 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002175 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002176 + ": " + visible);
2177 wallpaper.mClient.dispatchAppVisibility(visible);
2178 } catch (RemoteException e) {
2179 }
2180 }
2181 }
2182 }
2183 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 public int addWindow(Session session, IWindow client,
2186 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07002187 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 int res = mPolicy.checkAddPermission(attrs);
2189 if (res != WindowManagerImpl.ADD_OKAY) {
2190 return res;
2191 }
Romain Guy06882f82009-06-10 13:36:04 -07002192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002193 boolean reportNewConfig = false;
2194 WindowState attachedWindow = null;
2195 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002196 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002200 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 }
Romain Guy06882f82009-06-10 13:36:04 -07002202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002204 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2206 }
2207
2208 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002209 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002211 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 + attrs.token + ". Aborting.");
2213 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2214 }
2215 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2216 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002217 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 + attrs.token + ". Aborting.");
2219 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2220 }
2221 }
2222
2223 boolean addToken = false;
2224 WindowToken token = mTokenMap.get(attrs.token);
2225 if (token == null) {
2226 if (attrs.type >= FIRST_APPLICATION_WINDOW
2227 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002228 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002229 + attrs.token + ". Aborting.");
2230 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2231 }
2232 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002233 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002234 + attrs.token + ". Aborting.");
2235 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2236 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002237 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002238 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002239 + attrs.token + ". Aborting.");
2240 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 token = new WindowToken(attrs.token, -1, false);
2243 addToken = true;
2244 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2245 && attrs.type <= LAST_APPLICATION_WINDOW) {
2246 AppWindowToken atoken = token.appWindowToken;
2247 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002248 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 + token + ". Aborting.");
2250 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2251 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002252 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 + token + ". Aborting.");
2254 return WindowManagerImpl.ADD_APP_EXITING;
2255 }
2256 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2257 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002258 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2260 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2261 }
2262 } else if (attrs.type == TYPE_INPUT_METHOD) {
2263 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002264 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 + attrs.token + ". Aborting.");
2266 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2267 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002268 } else if (attrs.type == TYPE_WALLPAPER) {
2269 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002270 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002271 + attrs.token + ". Aborting.");
2272 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002274 }
2275
2276 win = new WindowState(session, client, token,
2277 attachedWindow, attrs, viewVisibility);
2278 if (win.mDeathRecipient == null) {
2279 // Client has apparently died, so there is no reason to
2280 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002281 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 + " that is dead, aborting.");
2283 return WindowManagerImpl.ADD_APP_EXITING;
2284 }
2285
2286 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 res = mPolicy.prepareAddWindowLw(win, attrs);
2289 if (res != WindowManagerImpl.ADD_OKAY) {
2290 return res;
2291 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002292
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002293 if (outInputChannel != null) {
2294 String name = win.makeInputChannelName();
2295 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2296 win.mInputChannel = inputChannels[0];
2297 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2298
2299 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301
2302 // From now on, no exceptions or errors allowed!
2303
2304 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002305
Dianne Hackborn5132b372010-07-29 12:51:35 -07002306 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 if (addToken) {
2309 mTokenMap.put(attrs.token, token);
2310 mTokenList.add(token);
2311 }
2312 win.attach();
2313 mWindowMap.put(client.asBinder(), win);
2314
2315 if (attrs.type == TYPE_APPLICATION_STARTING &&
2316 token.appWindowToken != null) {
2317 token.appWindowToken.startingWindow = win;
2318 }
2319
2320 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 if (attrs.type == TYPE_INPUT_METHOD) {
2323 mInputMethodWindow = win;
2324 addInputMethodWindowToListLocked(win);
2325 imMayMove = false;
2326 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2327 mInputMethodDialogs.add(win);
2328 addWindowToListInOrderLocked(win, true);
2329 adjustInputMethodDialogsLocked();
2330 imMayMove = false;
2331 } else {
2332 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002333 if (attrs.type == TYPE_WALLPAPER) {
2334 mLastWallpaperTimeoutTime = 0;
2335 adjustWallpaperWindowsLocked();
2336 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002337 adjustWallpaperWindowsLocked();
2338 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 }
Romain Guy06882f82009-06-10 13:36:04 -07002340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 if (mInTouchMode) {
2346 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2347 }
2348 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2349 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2350 }
Romain Guy06882f82009-06-10 13:36:04 -07002351
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002352 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002354 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2355 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 imMayMove = false;
2357 }
2358 }
Romain Guy06882f82009-06-10 13:36:04 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002361 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 }
Romain Guy06882f82009-06-10 13:36:04 -07002363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 assignLayersLocked();
2365 // Don't do layout here, the window must call
2366 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 //dump();
2369
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002370 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002371 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002372 }
Jeff Brown349703e2010-06-22 01:27:15 -07002373
Joe Onorato8a9b2202010-02-26 18:56:32 -08002374 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 TAG, "New client " + client.asBinder()
2376 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002377
2378 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2379 reportNewConfig = true;
2380 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 }
2382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 if (reportNewConfig) {
2384 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 return res;
2390 }
Romain Guy06882f82009-06-10 13:36:04 -07002391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 public void removeWindow(Session session, IWindow client) {
2393 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002394 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 if (win == null) {
2396 return;
2397 }
2398 removeWindowLocked(session, win);
2399 }
2400 }
Romain Guy06882f82009-06-10 13:36:04 -07002401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 public void removeWindowLocked(Session session, WindowState win) {
2403
Joe Onorato8a9b2202010-02-26 18:56:32 -08002404 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 TAG, "Remove " + win + " client="
2406 + Integer.toHexString(System.identityHashCode(
2407 win.mClient.asBinder()))
2408 + ", surface=" + win.mSurface);
2409
2410 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002411
2412 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002413
Joe Onorato8a9b2202010-02-26 18:56:32 -08002414 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2416 + " mExiting=" + win.mExiting
2417 + " isAnimating=" + win.isAnimating()
2418 + " app-animation="
2419 + (win.mAppToken != null ? win.mAppToken.animation : null)
2420 + " inPendingTransaction="
2421 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2422 + " mDisplayFrozen=" + mDisplayFrozen);
2423 // Visibility of the removed window. Will be used later to update orientation later on.
2424 boolean wasVisible = false;
2425 // First, see if we need to run an animation. If we do, we have
2426 // to hold off on removing the window until the animation is done.
2427 // If the display is frozen, just remove immediately, since the
2428 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002429 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 // If we are not currently running the exit animation, we
2431 // need to see about starting one.
2432 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002434 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2435 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2436 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2437 }
2438 // Try starting an animation.
2439 if (applyAnimationLocked(win, transit, false)) {
2440 win.mExiting = true;
2441 }
2442 }
2443 if (win.mExiting || win.isAnimating()) {
2444 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002445 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 win.mExiting = true;
2447 win.mRemoveOnExit = true;
2448 mLayoutNeeded = true;
2449 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2450 performLayoutAndPlaceSurfacesLocked();
2451 if (win.mAppToken != null) {
2452 win.mAppToken.updateReportedVisibilityLocked();
2453 }
2454 //dump();
2455 Binder.restoreCallingIdentity(origId);
2456 return;
2457 }
2458 }
2459
2460 removeWindowInnerLocked(session, win);
2461 // Removing a visible window will effect the computed orientation
2462 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002463 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002464 != mForcedAppOrientation
2465 && updateOrientationFromAppTokensLocked()) {
2466 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 }
2468 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2469 Binder.restoreCallingIdentity(origId);
2470 }
Romain Guy06882f82009-06-10 13:36:04 -07002471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002472 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 if (mInputMethodTarget == win) {
2476 moveInputMethodWindowsIfNeededLocked(false);
2477 }
Romain Guy06882f82009-06-10 13:36:04 -07002478
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002479 if (false) {
2480 RuntimeException e = new RuntimeException("here");
2481 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002482 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002483 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 mPolicy.removeWindowLw(win);
2486 win.removeLocked();
2487
2488 mWindowMap.remove(win.mClient.asBinder());
2489 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002490 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002491 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492
2493 if (mInputMethodWindow == win) {
2494 mInputMethodWindow = null;
2495 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2496 mInputMethodDialogs.remove(win);
2497 }
Romain Guy06882f82009-06-10 13:36:04 -07002498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 final WindowToken token = win.mToken;
2500 final AppWindowToken atoken = win.mAppToken;
2501 token.windows.remove(win);
2502 if (atoken != null) {
2503 atoken.allAppWindows.remove(win);
2504 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002505 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 TAG, "**** Removing window " + win + ": count="
2507 + token.windows.size());
2508 if (token.windows.size() == 0) {
2509 if (!token.explicit) {
2510 mTokenMap.remove(token.token);
2511 mTokenList.remove(token);
2512 } else if (atoken != null) {
2513 atoken.firstWindowDrawn = false;
2514 }
2515 }
2516
2517 if (atoken != null) {
2518 if (atoken.startingWindow == win) {
2519 atoken.startingWindow = null;
2520 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2521 // If this is the last window and we had requested a starting
2522 // transition window, well there is no point now.
2523 atoken.startingData = null;
2524 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2525 // If this is the last window except for a starting transition
2526 // window, we need to get rid of the starting transition.
2527 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002528 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 + ": no more real windows");
2530 }
2531 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2532 mH.sendMessage(m);
2533 }
2534 }
Romain Guy06882f82009-06-10 13:36:04 -07002535
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002536 if (win.mAttrs.type == TYPE_WALLPAPER) {
2537 mLastWallpaperTimeoutTime = 0;
2538 adjustWallpaperWindowsLocked();
2539 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002540 adjustWallpaperWindowsLocked();
2541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 if (!mInLayout) {
2544 assignLayersLocked();
2545 mLayoutNeeded = true;
2546 performLayoutAndPlaceSurfacesLocked();
2547 if (win.mAppToken != null) {
2548 win.mAppToken.updateReportedVisibilityLocked();
2549 }
2550 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002551
2552 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 }
2554
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002555 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2556 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2557 + ": " + msg + " / " + w.mAttrs.getTitle();
2558 if (where != null) {
2559 Slog.i(TAG, str, where);
2560 } else {
2561 Slog.i(TAG, str);
2562 }
2563 }
2564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2566 long origId = Binder.clearCallingIdentity();
2567 try {
2568 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002569 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002571 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 Surface.openTransaction();
2573 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002574 if (SHOW_TRANSACTIONS) logSurface(w,
2575 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 w.mSurface.setTransparentRegionHint(region);
2577 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002578 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 Surface.closeTransaction();
2580 }
2581 }
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(origId);
2585 }
2586 }
2587
2588 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002589 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 Rect visibleInsets) {
2591 long origId = Binder.clearCallingIdentity();
2592 try {
2593 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002594 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 if (w != null) {
2596 w.mGivenInsetsPending = false;
2597 w.mGivenContentInsets.set(contentInsets);
2598 w.mGivenVisibleInsets.set(visibleInsets);
2599 w.mTouchableInsets = touchableInsets;
2600 mLayoutNeeded = true;
2601 performLayoutAndPlaceSurfacesLocked();
2602 }
2603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(origId);
2606 }
2607 }
Romain Guy06882f82009-06-10 13:36:04 -07002608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 public void getWindowDisplayFrame(Session session, IWindow client,
2610 Rect outDisplayFrame) {
2611 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002612 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 if (win == null) {
2614 outDisplayFrame.setEmpty();
2615 return;
2616 }
2617 outDisplayFrame.set(win.mDisplayFrame);
2618 }
2619 }
2620
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002621 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2622 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002623 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2624 window.mWallpaperX = x;
2625 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002626 window.mWallpaperXStep = xStep;
2627 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002628 if (updateWallpaperOffsetLocked(window, true)) {
2629 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002630 }
2631 }
2632 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002633
Dianne Hackborn75804932009-10-20 20:15:20 -07002634 void wallpaperCommandComplete(IBinder window, Bundle result) {
2635 synchronized (mWindowMap) {
2636 if (mWaitingOnWallpaper != null &&
2637 mWaitingOnWallpaper.mClient.asBinder() == window) {
2638 mWaitingOnWallpaper = null;
2639 mWindowMap.notifyAll();
2640 }
2641 }
2642 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002643
Dianne Hackborn75804932009-10-20 20:15:20 -07002644 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2645 String action, int x, int y, int z, Bundle extras, boolean sync) {
2646 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2647 || window == mUpperWallpaperTarget) {
2648 boolean doWait = sync;
2649 int curTokenIndex = mWallpaperTokens.size();
2650 while (curTokenIndex > 0) {
2651 curTokenIndex--;
2652 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2653 int curWallpaperIndex = token.windows.size();
2654 while (curWallpaperIndex > 0) {
2655 curWallpaperIndex--;
2656 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2657 try {
2658 wallpaper.mClient.dispatchWallpaperCommand(action,
2659 x, y, z, extras, sync);
2660 // We only want to be synchronous with one wallpaper.
2661 sync = false;
2662 } catch (RemoteException e) {
2663 }
2664 }
2665 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002666
Dianne Hackborn75804932009-10-20 20:15:20 -07002667 if (doWait) {
2668 // XXX Need to wait for result.
2669 }
2670 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002671
Dianne Hackborn75804932009-10-20 20:15:20 -07002672 return null;
2673 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675 public int relayoutWindow(Session session, IWindow client,
2676 WindowManager.LayoutParams attrs, int requestedWidth,
2677 int requestedHeight, int viewVisibility, boolean insetsPending,
2678 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002679 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002680 boolean displayed = false;
2681 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002682 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002686 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 if (win == null) {
2688 return 0;
2689 }
2690 win.mRequestedWidth = requestedWidth;
2691 win.mRequestedHeight = requestedHeight;
2692
2693 if (attrs != null) {
2694 mPolicy.adjustWindowParamsLw(attrs);
2695 }
Romain Guy06882f82009-06-10 13:36:04 -07002696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 int attrChanges = 0;
2698 int flagChanges = 0;
2699 if (attrs != null) {
2700 flagChanges = win.mAttrs.flags ^= attrs.flags;
2701 attrChanges = win.mAttrs.copyFrom(attrs);
2702 }
2703
Joe Onorato8a9b2202010-02-26 18:56:32 -08002704 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705
2706 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2707 win.mAlpha = attrs.alpha;
2708 }
2709
2710 final boolean scaledWindow =
2711 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2712
2713 if (scaledWindow) {
2714 // requested{Width|Height} Surface's physical size
2715 // attrs.{width|height} Size on screen
2716 win.mHScale = (attrs.width != requestedWidth) ?
2717 (attrs.width / (float)requestedWidth) : 1.0f;
2718 win.mVScale = (attrs.height != requestedHeight) ?
2719 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002720 } else {
2721 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 }
2723
2724 boolean imMayMove = (flagChanges&(
2725 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2726 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 boolean focusMayChange = win.mViewVisibility != viewVisibility
2729 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2730 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002731
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002732 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2733 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735 win.mRelayoutCalled = true;
2736 final int oldVisibility = win.mViewVisibility;
2737 win.mViewVisibility = viewVisibility;
2738 if (viewVisibility == View.VISIBLE &&
2739 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2740 displayed = !win.isVisibleLw();
2741 if (win.mExiting) {
2742 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002743 if (win.mAnimation != null) {
2744 win.mAnimation.cancel();
2745 win.mAnimation = null;
2746 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 }
2748 if (win.mDestroying) {
2749 win.mDestroying = false;
2750 mDestroySurface.remove(win);
2751 }
2752 if (oldVisibility == View.GONE) {
2753 win.mEnterAnimationPending = true;
2754 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002755 if (displayed) {
2756 if (win.mSurface != null && !win.mDrawPending
2757 && !win.mCommitDrawPending && !mDisplayFrozen
2758 && mPolicy.isScreenOn()) {
2759 applyEnterAnimationLocked(win);
2760 }
2761 if ((win.mAttrs.flags
2762 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2763 if (DEBUG_VISIBILITY) Slog.v(TAG,
2764 "Relayout window turning screen on: " + win);
2765 win.mTurnOnScreen = true;
2766 }
2767 int diff = 0;
2768 if (win.mConfiguration != mCurConfiguration
2769 && (win.mConfiguration == null
2770 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2771 win.mConfiguration = mCurConfiguration;
2772 if (DEBUG_CONFIGURATION) {
2773 Slog.i(TAG, "Window " + win + " visible with new config: "
2774 + win.mConfiguration + " / 0x"
2775 + Integer.toHexString(diff));
2776 }
2777 outConfig.setTo(mCurConfiguration);
2778 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002779 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2781 // To change the format, we need to re-build the surface.
2782 win.destroySurfaceLocked();
2783 displayed = true;
2784 }
2785 try {
2786 Surface surface = win.createSurfaceLocked();
2787 if (surface != null) {
2788 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002789 win.mReportDestroySurface = false;
2790 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002791 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002792 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002793 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002794 // For some reason there isn't a surface. Clear the
2795 // caller's object so they see the same state.
2796 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 }
2798 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002799 mInputMonitor.updateInputWindowsLw();
2800
Joe Onorato8a9b2202010-02-26 18:56:32 -08002801 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002802 + client + " (" + win.mAttrs.getTitle() + ")",
2803 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 Binder.restoreCallingIdentity(origId);
2805 return 0;
2806 }
2807 if (displayed) {
2808 focusMayChange = true;
2809 }
2810 if (win.mAttrs.type == TYPE_INPUT_METHOD
2811 && mInputMethodWindow == null) {
2812 mInputMethodWindow = win;
2813 imMayMove = true;
2814 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002815 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2816 && win.mAppToken != null
2817 && win.mAppToken.startingWindow != null) {
2818 // Special handling of starting window over the base
2819 // window of the app: propagate lock screen flags to it,
2820 // to provide the correct semantics while starting.
2821 final int mask =
2822 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002823 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2824 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002825 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2826 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 } else {
2829 win.mEnterAnimationPending = false;
2830 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002831 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002832 + ": mExiting=" + win.mExiting
2833 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834 // If we are not currently running the exit animation, we
2835 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002836 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 // Try starting an animation; if there isn't one, we
2838 // can destroy the surface right away.
2839 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2840 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2841 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2842 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002843 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002845 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 } else if (win.isAnimating()) {
2848 // Currently in a hide animation... turn this into
2849 // an exit.
2850 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002851 } else if (win == mWallpaperTarget) {
2852 // If the wallpaper is currently behind this
2853 // window, we need to change both of them inside
2854 // of a transaction to avoid artifacts.
2855 win.mExiting = true;
2856 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 } else {
2858 if (mInputMethodWindow == win) {
2859 mInputMethodWindow = null;
2860 }
2861 win.destroySurfaceLocked();
2862 }
2863 }
2864 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002865
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002866 if (win.mSurface == null || (win.getAttrs().flags
2867 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2868 || win.mSurfacePendingDestroy) {
2869 // We are being called from a local process, which
2870 // means outSurface holds its current surface. Ensure the
2871 // surface object is cleared, but we don't want it actually
2872 // destroyed at this point.
2873 win.mSurfacePendingDestroy = false;
2874 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002875 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002876 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002877 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002878 "Keeping surface, will report destroy: " + win);
2879 win.mReportDestroySurface = true;
2880 outSurface.copyFrom(win.mSurface);
2881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 }
2883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 if (focusMayChange) {
2885 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2886 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 imMayMove = false;
2888 }
2889 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2890 }
Romain Guy06882f82009-06-10 13:36:04 -07002891
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002892 // updateFocusedWindowLocked() already assigned layers so we only need to
2893 // reassign them at this point if the IM window state gets shuffled
2894 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002897 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2898 // Little hack here -- we -should- be able to rely on the
2899 // function to return true if the IME has moved and needs
2900 // its layer recomputed. However, if the IME was hidden
2901 // and isn't actually moved in the list, its layer may be
2902 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 assignLayers = true;
2904 }
2905 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002906 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002907 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002908 assignLayers = true;
2909 }
2910 }
Romain Guy06882f82009-06-10 13:36:04 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 mLayoutNeeded = true;
2913 win.mGivenInsetsPending = insetsPending;
2914 if (assignLayers) {
2915 assignLayersLocked();
2916 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002917 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002919 if (displayed && win.mIsWallpaper) {
2920 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002921 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002922 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 if (win.mAppToken != null) {
2924 win.mAppToken.updateReportedVisibilityLocked();
2925 }
2926 outFrame.set(win.mFrame);
2927 outContentInsets.set(win.mContentInsets);
2928 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002929 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002931 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 + ", requestedHeight=" + requestedHeight
2933 + ", viewVisibility=" + viewVisibility
2934 + "\nRelayout returning frame=" + outFrame
2935 + ", surface=" + outSurface);
2936
Joe Onorato8a9b2202010-02-26 18:56:32 -08002937 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2939
2940 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002941
2942 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 }
2944
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002945 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 sendNewConfiguration();
2947 }
Romain Guy06882f82009-06-10 13:36:04 -07002948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2952 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2953 }
2954
2955 public void finishDrawingWindow(Session session, IWindow client) {
2956 final long origId = Binder.clearCallingIdentity();
2957 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002958 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002960 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2961 adjustWallpaperWindowsLocked();
2962 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 mLayoutNeeded = true;
2964 performLayoutAndPlaceSurfacesLocked();
2965 }
2966 }
2967 Binder.restoreCallingIdentity(origId);
2968 }
2969
2970 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 + (lp != null ? lp.packageName : null)
2973 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2974 if (lp != null && lp.windowAnimations != 0) {
2975 // If this is a system resource, don't try to load it from the
2976 // application resources. It is nice to avoid loading application
2977 // resources if we can.
2978 String packageName = lp.packageName != null ? lp.packageName : "android";
2979 int resId = lp.windowAnimations;
2980 if ((resId&0xFF000000) == 0x01000000) {
2981 packageName = "android";
2982 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002983 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 + packageName);
2985 return AttributeCache.instance().get(packageName, resId,
2986 com.android.internal.R.styleable.WindowAnimation);
2987 }
2988 return null;
2989 }
Romain Guy06882f82009-06-10 13:36:04 -07002990
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002991 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002992 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002993 + packageName + " resId=0x" + Integer.toHexString(resId));
2994 if (packageName != null) {
2995 if ((resId&0xFF000000) == 0x01000000) {
2996 packageName = "android";
2997 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002998 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002999 + packageName);
3000 return AttributeCache.instance().get(packageName, resId,
3001 com.android.internal.R.styleable.WindowAnimation);
3002 }
3003 return null;
3004 }
3005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 private void applyEnterAnimationLocked(WindowState win) {
3007 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3008 if (win.mEnterAnimationPending) {
3009 win.mEnterAnimationPending = false;
3010 transit = WindowManagerPolicy.TRANSIT_ENTER;
3011 }
3012
3013 applyAnimationLocked(win, transit, true);
3014 }
3015
3016 private boolean applyAnimationLocked(WindowState win,
3017 int transit, boolean isEntrance) {
3018 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3019 // If we are trying to apply an animation, but already running
3020 // an animation of the same type, then just leave that one alone.
3021 return true;
3022 }
Romain Guy06882f82009-06-10 13:36:04 -07003023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 // Only apply an animation if the display isn't frozen. If it is
3025 // frozen, there is no reason to animate and it can cause strange
3026 // artifacts when we unfreeze the display if some different animation
3027 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003028 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003029 int anim = mPolicy.selectAnimationLw(win, transit);
3030 int attr = -1;
3031 Animation a = null;
3032 if (anim != 0) {
3033 a = AnimationUtils.loadAnimation(mContext, anim);
3034 } else {
3035 switch (transit) {
3036 case WindowManagerPolicy.TRANSIT_ENTER:
3037 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3038 break;
3039 case WindowManagerPolicy.TRANSIT_EXIT:
3040 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3041 break;
3042 case WindowManagerPolicy.TRANSIT_SHOW:
3043 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3044 break;
3045 case WindowManagerPolicy.TRANSIT_HIDE:
3046 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3047 break;
3048 }
3049 if (attr >= 0) {
3050 a = loadAnimation(win.mAttrs, attr);
3051 }
3052 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003053 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003054 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3055 + " mAnimation=" + win.mAnimation
3056 + " isEntrance=" + isEntrance);
3057 if (a != null) {
3058 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003059 RuntimeException e = null;
3060 if (!HIDE_STACK_CRAWLS) {
3061 e = new RuntimeException();
3062 e.fillInStackTrace();
3063 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003064 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003065 }
3066 win.setAnimation(a);
3067 win.mAnimationIsEntrance = isEntrance;
3068 }
3069 } else {
3070 win.clearAnimation();
3071 }
3072
3073 return win.mAnimation != null;
3074 }
3075
3076 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3077 int anim = 0;
3078 Context context = mContext;
3079 if (animAttr >= 0) {
3080 AttributeCache.Entry ent = getCachedAnimations(lp);
3081 if (ent != null) {
3082 context = ent.context;
3083 anim = ent.array.getResourceId(animAttr, 0);
3084 }
3085 }
3086 if (anim != 0) {
3087 return AnimationUtils.loadAnimation(context, anim);
3088 }
3089 return null;
3090 }
Romain Guy06882f82009-06-10 13:36:04 -07003091
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003092 private Animation loadAnimation(String packageName, int resId) {
3093 int anim = 0;
3094 Context context = mContext;
3095 if (resId >= 0) {
3096 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3097 if (ent != null) {
3098 context = ent.context;
3099 anim = resId;
3100 }
3101 }
3102 if (anim != 0) {
3103 return AnimationUtils.loadAnimation(context, anim);
3104 }
3105 return null;
3106 }
3107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003108 private boolean applyAnimationLocked(AppWindowToken wtoken,
3109 WindowManager.LayoutParams lp, int transit, boolean enter) {
3110 // Only apply an animation if the display isn't frozen. If it is
3111 // frozen, there is no reason to animate and it can cause strange
3112 // artifacts when we unfreeze the display if some different animation
3113 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003114 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003115 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003116 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003117 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003118 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003119 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003120 } else if (mNextAppTransitionPackage != null) {
3121 a = loadAnimation(mNextAppTransitionPackage, enter ?
3122 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003123 } else {
3124 int animAttr = 0;
3125 switch (transit) {
3126 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3127 animAttr = enter
3128 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3129 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3130 break;
3131 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3132 animAttr = enter
3133 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3134 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3135 break;
3136 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3137 animAttr = enter
3138 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3139 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3140 break;
3141 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3142 animAttr = enter
3143 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3144 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3145 break;
3146 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3147 animAttr = enter
3148 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3149 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3150 break;
3151 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3152 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003153 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003154 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3155 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003156 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003157 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003158 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3159 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003160 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003161 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003162 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003163 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3164 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3165 break;
3166 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3167 animAttr = enter
3168 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3169 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3170 break;
3171 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3172 animAttr = enter
3173 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3174 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003175 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003176 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003177 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003178 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003179 + " anim=" + a
3180 + " animAttr=0x" + Integer.toHexString(animAttr)
3181 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003182 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 if (a != null) {
3184 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003185 RuntimeException e = null;
3186 if (!HIDE_STACK_CRAWLS) {
3187 e = new RuntimeException();
3188 e.fillInStackTrace();
3189 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003190 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 }
3192 wtoken.setAnimation(a);
3193 }
3194 } else {
3195 wtoken.clearAnimation();
3196 }
3197
3198 return wtoken.animation != null;
3199 }
3200
3201 // -------------------------------------------------------------
3202 // Application Window Tokens
3203 // -------------------------------------------------------------
3204
3205 public void validateAppTokens(List tokens) {
3206 int v = tokens.size()-1;
3207 int m = mAppTokens.size()-1;
3208 while (v >= 0 && m >= 0) {
3209 AppWindowToken wtoken = mAppTokens.get(m);
3210 if (wtoken.removed) {
3211 m--;
3212 continue;
3213 }
3214 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003215 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003216 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3217 }
3218 v--;
3219 m--;
3220 }
3221 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003222 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 v--;
3224 }
3225 while (m >= 0) {
3226 AppWindowToken wtoken = mAppTokens.get(m);
3227 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003228 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 }
3230 m--;
3231 }
3232 }
3233
3234 boolean checkCallingPermission(String permission, String func) {
3235 // Quick check: if the calling permission is me, it's all okay.
3236 if (Binder.getCallingPid() == Process.myPid()) {
3237 return true;
3238 }
Romain Guy06882f82009-06-10 13:36:04 -07003239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003240 if (mContext.checkCallingPermission(permission)
3241 == PackageManager.PERMISSION_GRANTED) {
3242 return true;
3243 }
3244 String msg = "Permission Denial: " + func + " from pid="
3245 + Binder.getCallingPid()
3246 + ", uid=" + Binder.getCallingUid()
3247 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003248 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003249 return false;
3250 }
Romain Guy06882f82009-06-10 13:36:04 -07003251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 AppWindowToken findAppWindowToken(IBinder token) {
3253 WindowToken wtoken = mTokenMap.get(token);
3254 if (wtoken == null) {
3255 return null;
3256 }
3257 return wtoken.appWindowToken;
3258 }
Romain Guy06882f82009-06-10 13:36:04 -07003259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 public void addWindowToken(IBinder token, int type) {
3261 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3262 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003263 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 }
Romain Guy06882f82009-06-10 13:36:04 -07003265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 synchronized(mWindowMap) {
3267 WindowToken wtoken = mTokenMap.get(token);
3268 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003269 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 return;
3271 }
3272 wtoken = new WindowToken(token, type, true);
3273 mTokenMap.put(token, wtoken);
3274 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003275 if (type == TYPE_WALLPAPER) {
3276 mWallpaperTokens.add(wtoken);
3277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 }
3279 }
Romain Guy06882f82009-06-10 13:36:04 -07003280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 public void removeWindowToken(IBinder token) {
3282 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3283 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003284 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 }
3286
3287 final long origId = Binder.clearCallingIdentity();
3288 synchronized(mWindowMap) {
3289 WindowToken wtoken = mTokenMap.remove(token);
3290 mTokenList.remove(wtoken);
3291 if (wtoken != null) {
3292 boolean delayed = false;
3293 if (!wtoken.hidden) {
3294 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 final int N = wtoken.windows.size();
3297 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 for (int i=0; i<N; i++) {
3300 WindowState win = wtoken.windows.get(i);
3301
3302 if (win.isAnimating()) {
3303 delayed = true;
3304 }
Romain Guy06882f82009-06-10 13:36:04 -07003305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 if (win.isVisibleNow()) {
3307 applyAnimationLocked(win,
3308 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 changed = true;
3310 }
3311 }
3312
3313 if (changed) {
3314 mLayoutNeeded = true;
3315 performLayoutAndPlaceSurfacesLocked();
3316 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3317 }
Romain Guy06882f82009-06-10 13:36:04 -07003318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 if (delayed) {
3320 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003321 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3322 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 }
3324 }
Romain Guy06882f82009-06-10 13:36:04 -07003325
Jeff Brownc5ed5912010-07-14 18:48:53 -07003326 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003328 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 }
3330 }
3331 Binder.restoreCallingIdentity(origId);
3332 }
3333
3334 public void addAppToken(int addPos, IApplicationToken token,
3335 int groupId, int requestedOrientation, boolean fullscreen) {
3336 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3337 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003338 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 }
Jeff Brown349703e2010-06-22 01:27:15 -07003340
3341 // Get the dispatching timeout here while we are not holding any locks so that it
3342 // can be cached by the AppWindowToken. The timeout value is used later by the
3343 // input dispatcher in code that does hold locks. If we did not cache the value
3344 // here we would run the chance of introducing a deadlock between the window manager
3345 // (which holds locks while updating the input dispatcher state) and the activity manager
3346 // (which holds locks while querying the application token).
3347 long inputDispatchingTimeoutNanos;
3348 try {
3349 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3350 } catch (RemoteException ex) {
3351 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3352 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3353 }
Romain Guy06882f82009-06-10 13:36:04 -07003354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 synchronized(mWindowMap) {
3356 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3357 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003358 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 return;
3360 }
3361 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003362 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 wtoken.groupId = groupId;
3364 wtoken.appFullscreen = fullscreen;
3365 wtoken.requestedOrientation = requestedOrientation;
3366 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003367 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 mTokenMap.put(token.asBinder(), wtoken);
3369 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 // Application tokens start out hidden.
3372 wtoken.hidden = true;
3373 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 //dump();
3376 }
3377 }
Romain Guy06882f82009-06-10 13:36:04 -07003378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 public void setAppGroupId(IBinder token, int groupId) {
3380 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3381 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003382 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 }
3384
3385 synchronized(mWindowMap) {
3386 AppWindowToken wtoken = findAppWindowToken(token);
3387 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003388 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 return;
3390 }
3391 wtoken.groupId = groupId;
3392 }
3393 }
Romain Guy06882f82009-06-10 13:36:04 -07003394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 public int getOrientationFromWindowsLocked() {
3396 int pos = mWindows.size() - 1;
3397 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003398 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 pos--;
3400 if (wtoken.mAppToken != null) {
3401 // We hit an application window. so the orientation will be determined by the
3402 // app window. No point in continuing further.
3403 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3404 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003405 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 continue;
3407 }
3408 int req = wtoken.mAttrs.screenOrientation;
3409 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3410 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3411 continue;
3412 } else {
3413 return req;
3414 }
3415 }
3416 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3417 }
Romain Guy06882f82009-06-10 13:36:04 -07003418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003420 int pos = mAppTokens.size() - 1;
3421 int curGroup = 0;
3422 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3423 boolean findingBehind = false;
3424 boolean haveGroup = false;
3425 boolean lastFullscreen = false;
3426 while (pos >= 0) {
3427 AppWindowToken wtoken = mAppTokens.get(pos);
3428 pos--;
3429 // if we're about to tear down this window and not seek for
3430 // the behind activity, don't use it for orientation
3431 if (!findingBehind
3432 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3433 continue;
3434 }
3435
3436 if (!haveGroup) {
3437 // We ignore any hidden applications on the top.
3438 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003439 continue;
3440 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003441 haveGroup = true;
3442 curGroup = wtoken.groupId;
3443 lastOrientation = wtoken.requestedOrientation;
3444 } else if (curGroup != wtoken.groupId) {
3445 // If we have hit a new application group, and the bottom
3446 // of the previous group didn't explicitly say to use
3447 // the orientation behind it, and the last app was
3448 // full screen, then we'll stick with the
3449 // user's orientation.
3450 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3451 && lastFullscreen) {
3452 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003455 int or = wtoken.requestedOrientation;
3456 // If this application is fullscreen, and didn't explicitly say
3457 // to use the orientation behind it, then just take whatever
3458 // orientation it has and ignores whatever is under it.
3459 lastFullscreen = wtoken.appFullscreen;
3460 if (lastFullscreen
3461 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3462 return or;
3463 }
3464 // If this application has requested an explicit orientation,
3465 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003466 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3467 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003468 return or;
3469 }
3470 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3471 }
3472 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 }
Romain Guy06882f82009-06-10 13:36:04 -07003474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003475 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003476 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003477 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3478 "updateOrientationFromAppTokens()")) {
3479 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3480 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003481
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003482 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003484
3485 synchronized(mWindowMap) {
3486 if (updateOrientationFromAppTokensLocked()) {
3487 if (freezeThisOneIfNeeded != null) {
3488 AppWindowToken wtoken = findAppWindowToken(
3489 freezeThisOneIfNeeded);
3490 if (wtoken != null) {
3491 startAppFreezingScreenLocked(wtoken,
3492 ActivityInfo.CONFIG_ORIENTATION);
3493 }
3494 }
3495 config = computeNewConfigurationLocked();
3496
3497 } else if (currentConfig != null) {
3498 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003499 // state mismatches the activity manager's, update it,
3500 // disregarding font scale, which should remain set to
3501 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003502 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003503 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003504 if (computeNewConfigurationLocked(mTempConfiguration)) {
3505 if (currentConfig.diff(mTempConfiguration) != 0) {
3506 mWaitingForConfig = true;
3507 mLayoutNeeded = true;
3508 startFreezingDisplayLocked();
3509 config = new Configuration(mTempConfiguration);
3510 }
3511 }
3512 }
3513 }
3514
Dianne Hackborncfaef692009-06-15 14:24:44 -07003515 Binder.restoreCallingIdentity(ident);
3516 return config;
3517 }
3518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003520 * Determine the new desired orientation of the display, returning
3521 * a non-null new Configuration if it has changed from the current
3522 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3523 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3524 * SCREEN. This will typically be done for you if you call
3525 * sendNewConfiguration().
3526 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 * The orientation is computed from non-application windows first. If none of
3528 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003529 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3531 * android.os.IBinder)
3532 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003533 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003534 if (mDisplayFrozen) {
3535 // If the display is frozen, some activities may be in the middle
3536 // of restarting, and thus have removed their old window. If the
3537 // window has the flag to hide the lock screen, then the lock screen
3538 // can re-appear and inflict its own orientation on us. Keep the
3539 // orientation stable until this all settles down.
3540 return false;
3541 }
3542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 long ident = Binder.clearCallingIdentity();
3545 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003546 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003549 mForcedAppOrientation = req;
3550 //send a message to Policy indicating orientation change to take
3551 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003552 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003553 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3554 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3555 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 }
3557 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003558
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003559 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 } finally {
3561 Binder.restoreCallingIdentity(ident);
3562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 }
Romain Guy06882f82009-06-10 13:36:04 -07003564
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003565 int computeForcedAppOrientationLocked() {
3566 int req = getOrientationFromWindowsLocked();
3567 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3568 req = getOrientationFromAppTokensLocked();
3569 }
3570 return req;
3571 }
Romain Guy06882f82009-06-10 13:36:04 -07003572
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003573 public void setNewConfiguration(Configuration config) {
3574 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3575 "setNewConfiguration()")) {
3576 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3577 }
3578
3579 synchronized(mWindowMap) {
3580 mCurConfiguration = new Configuration(config);
3581 mWaitingForConfig = false;
3582 performLayoutAndPlaceSurfacesLocked();
3583 }
3584 }
3585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3587 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3588 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003589 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 }
Romain Guy06882f82009-06-10 13:36:04 -07003591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 synchronized(mWindowMap) {
3593 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3594 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003595 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 return;
3597 }
Romain Guy06882f82009-06-10 13:36:04 -07003598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 wtoken.requestedOrientation = requestedOrientation;
3600 }
3601 }
Romain Guy06882f82009-06-10 13:36:04 -07003602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 public int getAppOrientation(IApplicationToken token) {
3604 synchronized(mWindowMap) {
3605 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3606 if (wtoken == null) {
3607 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3608 }
Romain Guy06882f82009-06-10 13:36:04 -07003609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 return wtoken.requestedOrientation;
3611 }
3612 }
Romain Guy06882f82009-06-10 13:36:04 -07003613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3615 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3616 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003617 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 }
3619
3620 synchronized(mWindowMap) {
3621 boolean changed = false;
3622 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003623 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 changed = mFocusedApp != null;
3625 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003626 if (changed) {
3627 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 } else {
3630 AppWindowToken newFocus = findAppWindowToken(token);
3631 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003632 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 return;
3634 }
3635 changed = mFocusedApp != newFocus;
3636 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003637 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003638 if (changed) {
3639 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 }
3642
3643 if (moveFocusNow && changed) {
3644 final long origId = Binder.clearCallingIdentity();
3645 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3646 Binder.restoreCallingIdentity(origId);
3647 }
3648 }
3649 }
3650
3651 public void prepareAppTransition(int transit) {
3652 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3653 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003654 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 }
Romain Guy06882f82009-06-10 13:36:04 -07003656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003658 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659 TAG, "Prepare app transition: transit=" + transit
3660 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003661 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003662 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3663 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003665 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3666 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3667 // Opening a new task always supersedes a close for the anim.
3668 mNextAppTransition = transit;
3669 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3670 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3671 // Opening a new activity always supersedes a close for the anim.
3672 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 }
3674 mAppTransitionReady = false;
3675 mAppTransitionTimeout = false;
3676 mStartingIconInTransition = false;
3677 mSkipAppTransitionAnimation = false;
3678 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3679 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3680 5000);
3681 }
3682 }
3683 }
3684
3685 public int getPendingAppTransition() {
3686 return mNextAppTransition;
3687 }
Romain Guy06882f82009-06-10 13:36:04 -07003688
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003689 public void overridePendingAppTransition(String packageName,
3690 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003691 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003692 mNextAppTransitionPackage = packageName;
3693 mNextAppTransitionEnter = enterAnim;
3694 mNextAppTransitionExit = exitAnim;
3695 }
3696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 public void executeAppTransition() {
3699 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3700 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003701 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 }
Romain Guy06882f82009-06-10 13:36:04 -07003703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003705 if (DEBUG_APP_TRANSITIONS) {
3706 RuntimeException e = new RuntimeException("here");
3707 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003708 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003709 + mNextAppTransition, e);
3710 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003711 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 mAppTransitionReady = true;
3713 final long origId = Binder.clearCallingIdentity();
3714 performLayoutAndPlaceSurfacesLocked();
3715 Binder.restoreCallingIdentity(origId);
3716 }
3717 }
3718 }
3719
3720 public void setAppStartingWindow(IBinder token, String pkg,
3721 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3722 IBinder transferFrom, boolean createIfNeeded) {
3723 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3724 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003725 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 }
3727
3728 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003729 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3731 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 AppWindowToken wtoken = findAppWindowToken(token);
3734 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003735 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 return;
3737 }
3738
3739 // If the display is frozen, we won't do anything until the
3740 // actual window is displayed so there is no reason to put in
3741 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003742 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 return;
3744 }
Romain Guy06882f82009-06-10 13:36:04 -07003745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 if (wtoken.startingData != null) {
3747 return;
3748 }
Romain Guy06882f82009-06-10 13:36:04 -07003749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 if (transferFrom != null) {
3751 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3752 if (ttoken != null) {
3753 WindowState startingWindow = ttoken.startingWindow;
3754 if (startingWindow != null) {
3755 if (mStartingIconInTransition) {
3756 // In this case, the starting icon has already
3757 // been displayed, so start letting windows get
3758 // shown immediately without any more transitions.
3759 mSkipAppTransitionAnimation = true;
3760 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003761 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 "Moving existing starting from " + ttoken
3763 + " to " + wtoken);
3764 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 // Transfer the starting window over to the new
3767 // token.
3768 wtoken.startingData = ttoken.startingData;
3769 wtoken.startingView = ttoken.startingView;
3770 wtoken.startingWindow = startingWindow;
3771 ttoken.startingData = null;
3772 ttoken.startingView = null;
3773 ttoken.startingWindow = null;
3774 ttoken.startingMoved = true;
3775 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003776 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003778 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003779 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003781 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 ttoken.windows.remove(startingWindow);
3783 ttoken.allAppWindows.remove(startingWindow);
3784 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 // Propagate other interesting state between the
3787 // tokens. If the old token is displayed, we should
3788 // immediately force the new one to be displayed. If
3789 // it is animating, we need to move that animation to
3790 // the new one.
3791 if (ttoken.allDrawn) {
3792 wtoken.allDrawn = true;
3793 }
3794 if (ttoken.firstWindowDrawn) {
3795 wtoken.firstWindowDrawn = true;
3796 }
3797 if (!ttoken.hidden) {
3798 wtoken.hidden = false;
3799 wtoken.hiddenRequested = false;
3800 wtoken.willBeHidden = false;
3801 }
3802 if (wtoken.clientHidden != ttoken.clientHidden) {
3803 wtoken.clientHidden = ttoken.clientHidden;
3804 wtoken.sendAppVisibilityToClients();
3805 }
3806 if (ttoken.animation != null) {
3807 wtoken.animation = ttoken.animation;
3808 wtoken.animating = ttoken.animating;
3809 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3810 ttoken.animation = null;
3811 ttoken.animLayerAdjustment = 0;
3812 wtoken.updateLayers();
3813 ttoken.updateLayers();
3814 }
Romain Guy06882f82009-06-10 13:36:04 -07003815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003817 mLayoutNeeded = true;
3818 performLayoutAndPlaceSurfacesLocked();
3819 Binder.restoreCallingIdentity(origId);
3820 return;
3821 } else if (ttoken.startingData != null) {
3822 // The previous app was getting ready to show a
3823 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003824 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 "Moving pending starting from " + ttoken
3826 + " to " + wtoken);
3827 wtoken.startingData = ttoken.startingData;
3828 ttoken.startingData = null;
3829 ttoken.startingMoved = true;
3830 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3831 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3832 // want to process the message ASAP, before any other queued
3833 // messages.
3834 mH.sendMessageAtFrontOfQueue(m);
3835 return;
3836 }
3837 }
3838 }
3839
3840 // There is no existing starting window, and the caller doesn't
3841 // want us to create one, so that's it!
3842 if (!createIfNeeded) {
3843 return;
3844 }
Romain Guy06882f82009-06-10 13:36:04 -07003845
Dianne Hackborn284ac932009-08-28 10:34:25 -07003846 // If this is a translucent or wallpaper window, then don't
3847 // show a starting window -- the current effect (a full-screen
3848 // opaque starting window that fades away to the real contents
3849 // when it is ready) does not work for this.
3850 if (theme != 0) {
3851 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3852 com.android.internal.R.styleable.Window);
3853 if (ent.array.getBoolean(
3854 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3855 return;
3856 }
3857 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003858 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3859 return;
3860 }
3861 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003862 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3863 return;
3864 }
3865 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 mStartingIconInTransition = true;
3868 wtoken.startingData = new StartingData(
3869 pkg, theme, nonLocalizedLabel,
3870 labelRes, icon);
3871 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3872 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3873 // want to process the message ASAP, before any other queued
3874 // messages.
3875 mH.sendMessageAtFrontOfQueue(m);
3876 }
3877 }
3878
3879 public void setAppWillBeHidden(IBinder token) {
3880 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3881 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003882 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 }
3884
3885 AppWindowToken wtoken;
3886
3887 synchronized(mWindowMap) {
3888 wtoken = findAppWindowToken(token);
3889 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003890 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 -08003891 return;
3892 }
3893 wtoken.willBeHidden = true;
3894 }
3895 }
Romain Guy06882f82009-06-10 13:36:04 -07003896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003897 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3898 boolean visible, int transit, boolean performLayout) {
3899 boolean delayed = false;
3900
3901 if (wtoken.clientHidden == visible) {
3902 wtoken.clientHidden = !visible;
3903 wtoken.sendAppVisibilityToClients();
3904 }
Romain Guy06882f82009-06-10 13:36:04 -07003905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003906 wtoken.willBeHidden = false;
3907 if (wtoken.hidden == visible) {
3908 final int N = wtoken.allAppWindows.size();
3909 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003910 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3912 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003915
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003916 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 if (wtoken.animation == sDummyAnimation) {
3918 wtoken.animation = null;
3919 }
3920 applyAnimationLocked(wtoken, lp, transit, visible);
3921 changed = true;
3922 if (wtoken.animation != null) {
3923 delayed = runningAppAnimation = true;
3924 }
3925 }
Romain Guy06882f82009-06-10 13:36:04 -07003926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 for (int i=0; i<N; i++) {
3928 WindowState win = wtoken.allAppWindows.get(i);
3929 if (win == wtoken.startingWindow) {
3930 continue;
3931 }
3932
3933 if (win.isAnimating()) {
3934 delayed = true;
3935 }
Romain Guy06882f82009-06-10 13:36:04 -07003936
Joe Onorato8a9b2202010-02-26 18:56:32 -08003937 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938 //win.dump(" ");
3939 if (visible) {
3940 if (!win.isVisibleNow()) {
3941 if (!runningAppAnimation) {
3942 applyAnimationLocked(win,
3943 WindowManagerPolicy.TRANSIT_ENTER, true);
3944 }
3945 changed = true;
3946 }
3947 } else if (win.isVisibleNow()) {
3948 if (!runningAppAnimation) {
3949 applyAnimationLocked(win,
3950 WindowManagerPolicy.TRANSIT_EXIT, false);
3951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 changed = true;
3953 }
3954 }
3955
3956 wtoken.hidden = wtoken.hiddenRequested = !visible;
3957 if (!visible) {
3958 unsetAppFreezingScreenLocked(wtoken, true, true);
3959 } else {
3960 // If we are being set visible, and the starting window is
3961 // not yet displayed, then make sure it doesn't get displayed.
3962 WindowState swin = wtoken.startingWindow;
3963 if (swin != null && (swin.mDrawPending
3964 || swin.mCommitDrawPending)) {
3965 swin.mPolicyVisibility = false;
3966 swin.mPolicyVisibilityAfterAnim = false;
3967 }
3968 }
Romain Guy06882f82009-06-10 13:36:04 -07003969
Joe Onorato8a9b2202010-02-26 18:56:32 -08003970 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3972 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003973
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003974 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003976 if (performLayout) {
3977 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3978 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003979 } else {
3980 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003981 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 }
3983 }
3984
3985 if (wtoken.animation != null) {
3986 delayed = true;
3987 }
Romain Guy06882f82009-06-10 13:36:04 -07003988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 return delayed;
3990 }
3991
3992 public void setAppVisibility(IBinder token, boolean visible) {
3993 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3994 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003995 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 }
3997
3998 AppWindowToken wtoken;
3999
4000 synchronized(mWindowMap) {
4001 wtoken = findAppWindowToken(token);
4002 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004003 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 return;
4005 }
4006
4007 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004008 RuntimeException e = null;
4009 if (!HIDE_STACK_CRAWLS) {
4010 e = new RuntimeException();
4011 e.fillInStackTrace();
4012 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004013 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 + "): mNextAppTransition=" + mNextAppTransition
4015 + " hidden=" + wtoken.hidden
4016 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4017 }
Romain Guy06882f82009-06-10 13:36:04 -07004018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 // If we are preparing an app transition, then delay changing
4020 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004021 if (!mDisplayFrozen && mPolicy.isScreenOn()
4022 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 // Already in requested state, don't do anything more.
4024 if (wtoken.hiddenRequested != visible) {
4025 return;
4026 }
4027 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004028
Joe Onorato8a9b2202010-02-26 18:56:32 -08004029 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 TAG, "Setting dummy animation on: " + wtoken);
4031 wtoken.setDummyAnimation();
4032 mOpeningApps.remove(wtoken);
4033 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004034 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 wtoken.inPendingTransaction = true;
4036 if (visible) {
4037 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004038 wtoken.startingDisplayed = false;
4039 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004040
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004041 // If the token is currently hidden (should be the
4042 // common case), then we need to set up to wait for
4043 // its windows to be ready.
4044 if (wtoken.hidden) {
4045 wtoken.allDrawn = false;
4046 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004047
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004048 if (wtoken.clientHidden) {
4049 // In the case where we are making an app visible
4050 // but holding off for a transition, we still need
4051 // to tell the client to make its windows visible so
4052 // they get drawn. Otherwise, we will wait on
4053 // performing the transition until all windows have
4054 // been drawn, they never will be, and we are sad.
4055 wtoken.clientHidden = false;
4056 wtoken.sendAppVisibilityToClients();
4057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004058 }
4059 } else {
4060 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004061
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004062 // If the token is currently visible (should be the
4063 // common case), then set up to wait for it to be hidden.
4064 if (!wtoken.hidden) {
4065 wtoken.waitingToHide = true;
4066 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 }
4068 return;
4069 }
Romain Guy06882f82009-06-10 13:36:04 -07004070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004071 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004072 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004073 wtoken.updateReportedVisibilityLocked();
4074 Binder.restoreCallingIdentity(origId);
4075 }
4076 }
4077
4078 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4079 boolean unfreezeSurfaceNow, boolean force) {
4080 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004081 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 + " force=" + force);
4083 final int N = wtoken.allAppWindows.size();
4084 boolean unfrozeWindows = false;
4085 for (int i=0; i<N; i++) {
4086 WindowState w = wtoken.allAppWindows.get(i);
4087 if (w.mAppFreezing) {
4088 w.mAppFreezing = false;
4089 if (w.mSurface != null && !w.mOrientationChanging) {
4090 w.mOrientationChanging = true;
4091 }
4092 unfrozeWindows = true;
4093 }
4094 }
4095 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004096 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097 wtoken.freezingScreen = false;
4098 mAppsFreezingScreen--;
4099 }
4100 if (unfreezeSurfaceNow) {
4101 if (unfrozeWindows) {
4102 mLayoutNeeded = true;
4103 performLayoutAndPlaceSurfacesLocked();
4104 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004105 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004106 }
4107 }
4108 }
Romain Guy06882f82009-06-10 13:36:04 -07004109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4111 int configChanges) {
4112 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004113 RuntimeException e = null;
4114 if (!HIDE_STACK_CRAWLS) {
4115 e = new RuntimeException();
4116 e.fillInStackTrace();
4117 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004118 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 + ": hidden=" + wtoken.hidden + " freezing="
4120 + wtoken.freezingScreen, e);
4121 }
4122 if (!wtoken.hiddenRequested) {
4123 if (!wtoken.freezingScreen) {
4124 wtoken.freezingScreen = true;
4125 mAppsFreezingScreen++;
4126 if (mAppsFreezingScreen == 1) {
4127 startFreezingDisplayLocked();
4128 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4129 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4130 5000);
4131 }
4132 }
4133 final int N = wtoken.allAppWindows.size();
4134 for (int i=0; i<N; i++) {
4135 WindowState w = wtoken.allAppWindows.get(i);
4136 w.mAppFreezing = true;
4137 }
4138 }
4139 }
Romain Guy06882f82009-06-10 13:36:04 -07004140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 public void startAppFreezingScreen(IBinder token, int configChanges) {
4142 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4143 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004144 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 }
4146
4147 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004148 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004149 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004150 return;
4151 }
Romain Guy06882f82009-06-10 13:36:04 -07004152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 AppWindowToken wtoken = findAppWindowToken(token);
4154 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004155 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004156 return;
4157 }
4158 final long origId = Binder.clearCallingIdentity();
4159 startAppFreezingScreenLocked(wtoken, configChanges);
4160 Binder.restoreCallingIdentity(origId);
4161 }
4162 }
Romain Guy06882f82009-06-10 13:36:04 -07004163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 public void stopAppFreezingScreen(IBinder token, boolean force) {
4165 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4166 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004167 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 }
4169
4170 synchronized(mWindowMap) {
4171 AppWindowToken wtoken = findAppWindowToken(token);
4172 if (wtoken == null || wtoken.appToken == null) {
4173 return;
4174 }
4175 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004176 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4178 unsetAppFreezingScreenLocked(wtoken, true, force);
4179 Binder.restoreCallingIdentity(origId);
4180 }
4181 }
Romain Guy06882f82009-06-10 13:36:04 -07004182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004183 public void removeAppToken(IBinder token) {
4184 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4185 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004186 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 }
4188
4189 AppWindowToken wtoken = null;
4190 AppWindowToken startingToken = null;
4191 boolean delayed = false;
4192
4193 final long origId = Binder.clearCallingIdentity();
4194 synchronized(mWindowMap) {
4195 WindowToken basewtoken = mTokenMap.remove(token);
4196 mTokenList.remove(basewtoken);
4197 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004198 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004199 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 wtoken.inPendingTransaction = false;
4201 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004202 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004203 if (mClosingApps.contains(wtoken)) {
4204 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004205 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004206 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004207 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 delayed = true;
4209 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004210 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 TAG, "Removing app " + wtoken + " delayed=" + delayed
4212 + " animation=" + wtoken.animation
4213 + " animating=" + wtoken.animating);
4214 if (delayed) {
4215 // set the token aside because it has an active animation to be finished
4216 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004217 } else {
4218 // Make sure there is no animation running on this token,
4219 // so any windows associated with it will be removed as
4220 // soon as their animations are complete
4221 wtoken.animation = null;
4222 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 }
4224 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004225 if (mLastEnterAnimToken == wtoken) {
4226 mLastEnterAnimToken = null;
4227 mLastEnterAnimParams = null;
4228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 wtoken.removed = true;
4230 if (wtoken.startingData != null) {
4231 startingToken = wtoken;
4232 }
4233 unsetAppFreezingScreenLocked(wtoken, true, true);
4234 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004235 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004236 mFocusedApp = null;
4237 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004238 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 }
4240 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004241 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004242 }
Romain Guy06882f82009-06-10 13:36:04 -07004243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 if (!delayed && wtoken != null) {
4245 wtoken.updateReportedVisibilityLocked();
4246 }
4247 }
4248 Binder.restoreCallingIdentity(origId);
4249
4250 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004251 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 + startingToken + ": app token removed");
4253 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4254 mH.sendMessage(m);
4255 }
4256 }
4257
4258 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4259 final int NW = token.windows.size();
4260 for (int i=0; i<NW; i++) {
4261 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004262 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004263 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004264 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 int j = win.mChildWindows.size();
4266 while (j > 0) {
4267 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004268 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004269 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004270 "Tmp removing child window " + cwin);
4271 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 }
4273 }
4274 return NW > 0;
4275 }
4276
4277 void dumpAppTokensLocked() {
4278 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004279 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 }
4281 }
Romain Guy06882f82009-06-10 13:36:04 -07004282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004283 void dumpWindowsLocked() {
4284 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004285 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 }
4287 }
Romain Guy06882f82009-06-10 13:36:04 -07004288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 private int findWindowOffsetLocked(int tokenPos) {
4290 final int NW = mWindows.size();
4291
4292 if (tokenPos >= mAppTokens.size()) {
4293 int i = NW;
4294 while (i > 0) {
4295 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004296 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 if (win.getAppToken() != null) {
4298 return i+1;
4299 }
4300 }
4301 }
4302
4303 while (tokenPos > 0) {
4304 // Find the first app token below the new position that has
4305 // a window displayed.
4306 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004307 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004309 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004310 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004311 "Skipping token -- currently sending to bottom");
4312 tokenPos--;
4313 continue;
4314 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 int i = wtoken.windows.size();
4316 while (i > 0) {
4317 i--;
4318 WindowState win = wtoken.windows.get(i);
4319 int j = win.mChildWindows.size();
4320 while (j > 0) {
4321 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004322 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004323 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 for (int pos=NW-1; pos>=0; pos--) {
4325 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004326 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 "Found child win @" + (pos+1));
4328 return pos+1;
4329 }
4330 }
4331 }
4332 }
4333 for (int pos=NW-1; pos>=0; pos--) {
4334 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004335 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004336 return pos+1;
4337 }
4338 }
4339 }
4340 tokenPos--;
4341 }
4342
4343 return 0;
4344 }
4345
4346 private final int reAddWindowLocked(int index, WindowState win) {
4347 final int NCW = win.mChildWindows.size();
4348 boolean added = false;
4349 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004350 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004352 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004353 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 mWindows.add(index, win);
4355 index++;
4356 added = true;
4357 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004358 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004359 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 mWindows.add(index, cwin);
4361 index++;
4362 }
4363 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004364 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004365 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 mWindows.add(index, win);
4367 index++;
4368 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004369 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 return index;
4371 }
Romain Guy06882f82009-06-10 13:36:04 -07004372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004373 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4374 final int NW = token.windows.size();
4375 for (int i=0; i<NW; i++) {
4376 index = reAddWindowLocked(index, token.windows.get(i));
4377 }
4378 return index;
4379 }
4380
4381 public void moveAppToken(int index, IBinder token) {
4382 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4383 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004384 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 }
4386
4387 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004388 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 if (DEBUG_REORDER) dumpAppTokensLocked();
4390 final AppWindowToken wtoken = findAppWindowToken(token);
4391 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004392 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004393 + token + " (" + wtoken + ")");
4394 return;
4395 }
4396 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004397 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004400 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004401 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004402 if (DEBUG_REORDER) dumpWindowsLocked();
4403 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004404 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004405 if (DEBUG_REORDER) dumpWindowsLocked();
4406 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004407 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 if (DEBUG_REORDER) dumpWindowsLocked();
4409 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 mLayoutNeeded = true;
4411 performLayoutAndPlaceSurfacesLocked();
4412 }
4413 Binder.restoreCallingIdentity(origId);
4414 }
4415 }
4416
4417 private void removeAppTokensLocked(List<IBinder> tokens) {
4418 // XXX This should be done more efficiently!
4419 // (take advantage of the fact that both lists should be
4420 // ordered in the same way.)
4421 int N = tokens.size();
4422 for (int i=0; i<N; i++) {
4423 IBinder token = tokens.get(i);
4424 final AppWindowToken wtoken = findAppWindowToken(token);
4425 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004426 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004427 + token + " (" + wtoken + ")");
4428 i--;
4429 N--;
4430 }
4431 }
4432 }
4433
Dianne Hackborna8f60182009-09-01 19:01:50 -07004434 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4435 boolean updateFocusAndLayout) {
4436 // First remove all of the windows from the list.
4437 tmpRemoveAppWindowsLocked(wtoken);
4438
4439 // Where to start adding?
4440 int pos = findWindowOffsetLocked(tokenPos);
4441
4442 // And now add them back at the correct place.
4443 pos = reAddAppWindowsLocked(pos, wtoken);
4444
4445 if (updateFocusAndLayout) {
4446 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4447 assignLayersLocked();
4448 }
4449 mLayoutNeeded = true;
4450 performLayoutAndPlaceSurfacesLocked();
4451 }
4452 }
4453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4455 // First remove all of the windows from the list.
4456 final int N = tokens.size();
4457 int i;
4458 for (i=0; i<N; i++) {
4459 WindowToken token = mTokenMap.get(tokens.get(i));
4460 if (token != null) {
4461 tmpRemoveAppWindowsLocked(token);
4462 }
4463 }
4464
4465 // Where to start adding?
4466 int pos = findWindowOffsetLocked(tokenPos);
4467
4468 // And now add them back at the correct place.
4469 for (i=0; i<N; i++) {
4470 WindowToken token = mTokenMap.get(tokens.get(i));
4471 if (token != null) {
4472 pos = reAddAppWindowsLocked(pos, token);
4473 }
4474 }
4475
Dianne Hackborna8f60182009-09-01 19:01:50 -07004476 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4477 assignLayersLocked();
4478 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 mLayoutNeeded = true;
4480 performLayoutAndPlaceSurfacesLocked();
4481
4482 //dump();
4483 }
4484
4485 public void moveAppTokensToTop(List<IBinder> tokens) {
4486 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4487 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004488 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 }
4490
4491 final long origId = Binder.clearCallingIdentity();
4492 synchronized(mWindowMap) {
4493 removeAppTokensLocked(tokens);
4494 final int N = tokens.size();
4495 for (int i=0; i<N; i++) {
4496 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4497 if (wt != null) {
4498 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004499 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004500 mToTopApps.remove(wt);
4501 mToBottomApps.remove(wt);
4502 mToTopApps.add(wt);
4503 wt.sendingToBottom = false;
4504 wt.sendingToTop = true;
4505 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004506 }
4507 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004508
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004509 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004510 moveAppWindowsLocked(tokens, mAppTokens.size());
4511 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 }
4513 Binder.restoreCallingIdentity(origId);
4514 }
4515
4516 public void moveAppTokensToBottom(List<IBinder> tokens) {
4517 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4518 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004519 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 }
4521
4522 final long origId = Binder.clearCallingIdentity();
4523 synchronized(mWindowMap) {
4524 removeAppTokensLocked(tokens);
4525 final int N = tokens.size();
4526 int pos = 0;
4527 for (int i=0; i<N; i++) {
4528 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4529 if (wt != null) {
4530 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004531 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004532 mToTopApps.remove(wt);
4533 mToBottomApps.remove(wt);
4534 mToBottomApps.add(i, wt);
4535 wt.sendingToTop = false;
4536 wt.sendingToBottom = true;
4537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 pos++;
4539 }
4540 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004541
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004542 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004543 moveAppWindowsLocked(tokens, 0);
4544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004545 }
4546 Binder.restoreCallingIdentity(origId);
4547 }
4548
4549 // -------------------------------------------------------------
4550 // Misc IWindowSession methods
4551 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004552
Jim Miller284b62e2010-06-08 14:27:42 -07004553 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004554 {
Jim Miller284b62e2010-06-08 14:27:42 -07004555 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4556 // called before DevicePolicyManagerService has started.
4557 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4558 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4559 Context.DEVICE_POLICY_SERVICE);
4560 if (dpm != null) {
4561 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4562 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4563 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4564 }
Jim Millerd6b57052010-06-07 17:52:42 -07004565 }
Jim Miller284b62e2010-06-08 14:27:42 -07004566 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004567 }
4568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004569 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004570 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 != PackageManager.PERMISSION_GRANTED) {
4572 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4573 }
Jim Millerd6b57052010-06-07 17:52:42 -07004574
Jim Miller284b62e2010-06-08 14:27:42 -07004575 synchronized (mKeyguardTokenWatcher) {
4576 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578 }
4579
4580 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004581 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004582 != PackageManager.PERMISSION_GRANTED) {
4583 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004585
Jim Miller284b62e2010-06-08 14:27:42 -07004586 synchronized (mKeyguardTokenWatcher) {
4587 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004588
Jim Miller284b62e2010-06-08 14:27:42 -07004589 if (!mKeyguardTokenWatcher.isAcquired()) {
4590 // If we are the last one to reenable the keyguard wait until
4591 // we have actually finished reenabling until returning.
4592 // It is possible that reenableKeyguard() can be called before
4593 // the previous disableKeyguard() is handled, in which case
4594 // neither mKeyguardTokenWatcher.acquired() or released() would
4595 // be called. In that case mKeyguardDisabled will be false here
4596 // and we have nothing to wait for.
4597 while (mKeyguardDisabled) {
4598 try {
4599 mKeyguardTokenWatcher.wait();
4600 } catch (InterruptedException e) {
4601 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004602 }
4603 }
4604 }
4605 }
4606 }
4607
4608 /**
4609 * @see android.app.KeyguardManager#exitKeyguardSecurely
4610 */
4611 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004612 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 != PackageManager.PERMISSION_GRANTED) {
4614 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4615 }
4616 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4617 public void onKeyguardExitResult(boolean success) {
4618 try {
4619 callback.onKeyguardExitResult(success);
4620 } catch (RemoteException e) {
4621 // Client has died, we don't care.
4622 }
4623 }
4624 });
4625 }
4626
4627 public boolean inKeyguardRestrictedInputMode() {
4628 return mPolicy.inKeyguardRestrictedKeyInputMode();
4629 }
Romain Guy06882f82009-06-10 13:36:04 -07004630
Dianne Hackbornffa42482009-09-23 22:20:11 -07004631 public void closeSystemDialogs(String reason) {
4632 synchronized(mWindowMap) {
4633 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004634 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004635 if (w.mSurface != null) {
4636 try {
4637 w.mClient.closeSystemDialogs(reason);
4638 } catch (RemoteException e) {
4639 }
4640 }
4641 }
4642 }
4643 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 static float fixScale(float scale) {
4646 if (scale < 0) scale = 0;
4647 else if (scale > 20) scale = 20;
4648 return Math.abs(scale);
4649 }
Romain Guy06882f82009-06-10 13:36:04 -07004650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 public void setAnimationScale(int which, float scale) {
4652 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4653 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004654 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004655 }
4656
4657 if (scale < 0) scale = 0;
4658 else if (scale > 20) scale = 20;
4659 scale = Math.abs(scale);
4660 switch (which) {
4661 case 0: mWindowAnimationScale = fixScale(scale); break;
4662 case 1: mTransitionAnimationScale = fixScale(scale); break;
4663 }
Romain Guy06882f82009-06-10 13:36:04 -07004664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 // Persist setting
4666 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4667 }
Romain Guy06882f82009-06-10 13:36:04 -07004668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004669 public void setAnimationScales(float[] scales) {
4670 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4671 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004672 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004673 }
4674
4675 if (scales != null) {
4676 if (scales.length >= 1) {
4677 mWindowAnimationScale = fixScale(scales[0]);
4678 }
4679 if (scales.length >= 2) {
4680 mTransitionAnimationScale = fixScale(scales[1]);
4681 }
4682 }
Romain Guy06882f82009-06-10 13:36:04 -07004683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 // Persist setting
4685 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4686 }
Romain Guy06882f82009-06-10 13:36:04 -07004687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 public float getAnimationScale(int which) {
4689 switch (which) {
4690 case 0: return mWindowAnimationScale;
4691 case 1: return mTransitionAnimationScale;
4692 }
4693 return 0;
4694 }
Romain Guy06882f82009-06-10 13:36:04 -07004695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 public float[] getAnimationScales() {
4697 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4698 }
Romain Guy06882f82009-06-10 13:36:04 -07004699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700 public int getSwitchState(int sw) {
4701 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4702 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004703 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004704 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004705 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 }
Romain Guy06882f82009-06-10 13:36:04 -07004707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004708 public int getSwitchStateForDevice(int devid, int sw) {
4709 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4710 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004711 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004713 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 }
Romain Guy06882f82009-06-10 13:36:04 -07004715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004716 public int getScancodeState(int sw) {
4717 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4718 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004719 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004720 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004721 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004722 }
Romain Guy06882f82009-06-10 13:36:04 -07004723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 public int getScancodeStateForDevice(int devid, int sw) {
4725 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4726 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004727 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004728 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004729 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004730 }
Romain Guy06882f82009-06-10 13:36:04 -07004731
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004732 public int getTrackballScancodeState(int sw) {
4733 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4734 "getTrackballScancodeState()")) {
4735 throw new SecurityException("Requires READ_INPUT_STATE permission");
4736 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004737 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004738 }
4739
4740 public int getDPadScancodeState(int sw) {
4741 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4742 "getDPadScancodeState()")) {
4743 throw new SecurityException("Requires READ_INPUT_STATE permission");
4744 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004745 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004746 }
4747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004748 public int getKeycodeState(int sw) {
4749 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4750 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004751 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004752 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004753 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004754 }
Romain Guy06882f82009-06-10 13:36:04 -07004755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004756 public int getKeycodeStateForDevice(int devid, int sw) {
4757 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4758 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004759 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004760 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004761 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004762 }
Romain Guy06882f82009-06-10 13:36:04 -07004763
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004764 public int getTrackballKeycodeState(int sw) {
4765 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4766 "getTrackballKeycodeState()")) {
4767 throw new SecurityException("Requires READ_INPUT_STATE permission");
4768 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004769 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004770 }
4771
4772 public int getDPadKeycodeState(int sw) {
4773 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4774 "getDPadKeycodeState()")) {
4775 throw new SecurityException("Requires READ_INPUT_STATE permission");
4776 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004777 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004778 }
Jeff Browna41ca772010-08-11 14:46:32 -07004779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004780 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004781 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004782 }
Romain Guy06882f82009-06-10 13:36:04 -07004783
Jeff Browna41ca772010-08-11 14:46:32 -07004784 public InputChannel monitorInput(String inputChannelName) {
4785 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4786 "monitorInput()")) {
4787 throw new SecurityException("Requires READ_INPUT_STATE permission");
4788 }
4789 return mInputManager.monitorInput(inputChannelName);
4790 }
4791
Jeff Brown8d608662010-08-30 03:02:23 -07004792 public InputDevice getInputDevice(int deviceId) {
4793 return mInputManager.getInputDevice(deviceId);
4794 }
4795
4796 public int[] getInputDeviceIds() {
4797 return mInputManager.getInputDeviceIds();
4798 }
4799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004800 public void enableScreenAfterBoot() {
4801 synchronized(mWindowMap) {
4802 if (mSystemBooted) {
4803 return;
4804 }
4805 mSystemBooted = true;
4806 }
Romain Guy06882f82009-06-10 13:36:04 -07004807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 performEnableScreen();
4809 }
Romain Guy06882f82009-06-10 13:36:04 -07004810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 public void enableScreenIfNeededLocked() {
4812 if (mDisplayEnabled) {
4813 return;
4814 }
4815 if (!mSystemBooted) {
4816 return;
4817 }
4818 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4819 }
Romain Guy06882f82009-06-10 13:36:04 -07004820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 public void performEnableScreen() {
4822 synchronized(mWindowMap) {
4823 if (mDisplayEnabled) {
4824 return;
4825 }
4826 if (!mSystemBooted) {
4827 return;
4828 }
Romain Guy06882f82009-06-10 13:36:04 -07004829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830 // Don't enable the screen until all existing windows
4831 // have been drawn.
4832 final int N = mWindows.size();
4833 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004834 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004835 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004836 return;
4837 }
4838 }
Romain Guy06882f82009-06-10 13:36:04 -07004839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004840 mDisplayEnabled = true;
4841 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004842 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 StringWriter sw = new StringWriter();
4844 PrintWriter pw = new PrintWriter(sw);
4845 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004846 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004847 }
4848 try {
4849 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4850 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004851 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 Parcel data = Parcel.obtain();
4853 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4854 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4855 data, null, 0);
4856 data.recycle();
4857 }
4858 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004859 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004860 }
4861 }
Romain Guy06882f82009-06-10 13:36:04 -07004862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004865 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004866 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4867 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004868 }
Romain Guy06882f82009-06-10 13:36:04 -07004869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 public void setInTouchMode(boolean mode) {
4871 synchronized(mWindowMap) {
4872 mInTouchMode = mode;
4873 }
4874 }
4875
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004876 public void freezeRotation() {
4877 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4878 "setRotation()")) {
4879 throw new SecurityException("Requires SET_ORIENTATION permission");
4880 }
4881
4882 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4883 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4884 }
4885
4886 public void thawRotation() {
4887 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4888 "setRotation()")) {
4889 throw new SecurityException("Requires SET_ORIENTATION permission");
4890 }
4891
4892 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4893 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4894 }
4895
Romain Guy06882f82009-06-10 13:36:04 -07004896 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004897 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004898 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004899 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004900 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004901 }
4902
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004903 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004904 }
Romain Guy06882f82009-06-10 13:36:04 -07004905
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004906 public void setRotationUnchecked(int rotation,
4907 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004908 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004909 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 long origId = Binder.clearCallingIdentity();
4912 boolean changed;
4913 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004914 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 }
Romain Guy06882f82009-06-10 13:36:04 -07004916
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004917 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004918 sendNewConfiguration();
4919 }
Romain Guy06882f82009-06-10 13:36:04 -07004920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 Binder.restoreCallingIdentity(origId);
4922 }
Romain Guy06882f82009-06-10 13:36:04 -07004923
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004924 /**
4925 * Apply a new rotation to the screen, respecting the requests of
4926 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4927 * re-evaluate the desired rotation.
4928 *
4929 * Returns null if the rotation has been changed. In this case YOU
4930 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4931 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004932 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004933 boolean changed;
4934 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4935 rotation = mRequestedRotation;
4936 } else {
4937 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004938 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004939 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004940 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004941 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004943 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004944 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004946 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004947 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004948 "Rotation changed to " + rotation
4949 + " from " + mRotation
4950 + " (forceApp=" + mForcedAppOrientation
4951 + ", req=" + mRequestedRotation + ")");
4952 mRotation = rotation;
4953 mWindowsFreezingScreen = true;
4954 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4955 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4956 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004957 mWaitingForConfig = true;
4958 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004960 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004961 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004963 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 }
4965 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004966 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004967 if (w.mSurface != null) {
4968 w.mOrientationChanging = true;
4969 }
4970 }
4971 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4972 try {
4973 mRotationWatchers.get(i).onRotationChanged(rotation);
4974 } catch (RemoteException e) {
4975 }
4976 }
4977 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004979 return changed;
4980 }
Romain Guy06882f82009-06-10 13:36:04 -07004981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982 public int getRotation() {
4983 return mRotation;
4984 }
4985
4986 public int watchRotation(IRotationWatcher watcher) {
4987 final IBinder watcherBinder = watcher.asBinder();
4988 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4989 public void binderDied() {
4990 synchronized (mWindowMap) {
4991 for (int i=0; i<mRotationWatchers.size(); i++) {
4992 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004993 IRotationWatcher removed = mRotationWatchers.remove(i);
4994 if (removed != null) {
4995 removed.asBinder().unlinkToDeath(this, 0);
4996 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004997 i--;
4998 }
4999 }
5000 }
5001 }
5002 };
Romain Guy06882f82009-06-10 13:36:04 -07005003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005004 synchronized (mWindowMap) {
5005 try {
5006 watcher.asBinder().linkToDeath(dr, 0);
5007 mRotationWatchers.add(watcher);
5008 } catch (RemoteException e) {
5009 // Client died, no cleanup needed.
5010 }
Romain Guy06882f82009-06-10 13:36:04 -07005011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005012 return mRotation;
5013 }
5014 }
5015
5016 /**
5017 * Starts the view server on the specified port.
5018 *
5019 * @param port The port to listener to.
5020 *
5021 * @return True if the server was successfully started, false otherwise.
5022 *
5023 * @see com.android.server.ViewServer
5024 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5025 */
5026 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005027 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005028 return false;
5029 }
5030
5031 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5032 return false;
5033 }
5034
5035 if (port < 1024) {
5036 return false;
5037 }
5038
5039 if (mViewServer != null) {
5040 if (!mViewServer.isRunning()) {
5041 try {
5042 return mViewServer.start();
5043 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005044 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 }
5046 }
5047 return false;
5048 }
5049
5050 try {
5051 mViewServer = new ViewServer(this, port);
5052 return mViewServer.start();
5053 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005054 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 }
5056 return false;
5057 }
5058
Romain Guy06882f82009-06-10 13:36:04 -07005059 private boolean isSystemSecure() {
5060 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5061 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5062 }
5063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005064 /**
5065 * Stops the view server if it exists.
5066 *
5067 * @return True if the server stopped, false if it wasn't started or
5068 * couldn't be stopped.
5069 *
5070 * @see com.android.server.ViewServer
5071 */
5072 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005073 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005074 return false;
5075 }
5076
5077 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5078 return false;
5079 }
5080
5081 if (mViewServer != null) {
5082 return mViewServer.stop();
5083 }
5084 return false;
5085 }
5086
5087 /**
5088 * Indicates whether the view server is running.
5089 *
5090 * @return True if the server is running, false otherwise.
5091 *
5092 * @see com.android.server.ViewServer
5093 */
5094 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005095 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005096 return false;
5097 }
5098
5099 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5100 return false;
5101 }
5102
5103 return mViewServer != null && mViewServer.isRunning();
5104 }
5105
5106 /**
5107 * Lists all availble windows in the system. The listing is written in the
5108 * specified Socket's output stream with the following syntax:
5109 * windowHashCodeInHexadecimal windowName
5110 * Each line of the ouput represents a different window.
5111 *
5112 * @param client The remote client to send the listing to.
5113 * @return False if an error occured, true otherwise.
5114 */
5115 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005116 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005117 return false;
5118 }
5119
5120 boolean result = true;
5121
Jeff Browne33348b2010-07-15 23:54:05 -07005122 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005123 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005125 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005126 }
5127
5128 BufferedWriter out = null;
5129
5130 // Any uncaught exception will crash the system process
5131 try {
5132 OutputStream clientStream = client.getOutputStream();
5133 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5134
5135 final int count = windows.length;
5136 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005137 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005138 out.write(Integer.toHexString(System.identityHashCode(w)));
5139 out.write(' ');
5140 out.append(w.mAttrs.getTitle());
5141 out.write('\n');
5142 }
5143
5144 out.write("DONE.\n");
5145 out.flush();
5146 } catch (Exception e) {
5147 result = false;
5148 } finally {
5149 if (out != null) {
5150 try {
5151 out.close();
5152 } catch (IOException e) {
5153 result = false;
5154 }
5155 }
5156 }
5157
5158 return result;
5159 }
5160
5161 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005162 * Returns the focused window in the following format:
5163 * windowHashCodeInHexadecimal windowName
5164 *
5165 * @param client The remote client to send the listing to.
5166 * @return False if an error occurred, true otherwise.
5167 */
5168 boolean viewServerGetFocusedWindow(Socket client) {
5169 if (isSystemSecure()) {
5170 return false;
5171 }
5172
5173 boolean result = true;
5174
5175 WindowState focusedWindow = getFocusedWindow();
5176
5177 BufferedWriter out = null;
5178
5179 // Any uncaught exception will crash the system process
5180 try {
5181 OutputStream clientStream = client.getOutputStream();
5182 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5183
5184 if(focusedWindow != null) {
5185 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5186 out.write(' ');
5187 out.append(focusedWindow.mAttrs.getTitle());
5188 }
5189 out.write('\n');
5190 out.flush();
5191 } catch (Exception e) {
5192 result = false;
5193 } finally {
5194 if (out != null) {
5195 try {
5196 out.close();
5197 } catch (IOException e) {
5198 result = false;
5199 }
5200 }
5201 }
5202
5203 return result;
5204 }
5205
5206 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005207 * Sends a command to a target window. The result of the command, if any, will be
5208 * written in the output stream of the specified socket.
5209 *
5210 * The parameters must follow this syntax:
5211 * windowHashcode extra
5212 *
5213 * Where XX is the length in characeters of the windowTitle.
5214 *
5215 * The first parameter is the target window. The window with the specified hashcode
5216 * will be the target. If no target can be found, nothing happens. The extra parameters
5217 * will be delivered to the target window and as parameters to the command itself.
5218 *
5219 * @param client The remote client to sent the result, if any, to.
5220 * @param command The command to execute.
5221 * @param parameters The command parameters.
5222 *
5223 * @return True if the command was successfully delivered, false otherwise. This does
5224 * not indicate whether the command itself was successful.
5225 */
5226 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005227 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228 return false;
5229 }
5230
5231 boolean success = true;
5232 Parcel data = null;
5233 Parcel reply = null;
5234
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005235 BufferedWriter out = null;
5236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005237 // Any uncaught exception will crash the system process
5238 try {
5239 // Find the hashcode of the window
5240 int index = parameters.indexOf(' ');
5241 if (index == -1) {
5242 index = parameters.length();
5243 }
5244 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005245 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005246
5247 // Extract the command's parameter after the window description
5248 if (index < parameters.length()) {
5249 parameters = parameters.substring(index + 1);
5250 } else {
5251 parameters = "";
5252 }
5253
5254 final WindowManagerService.WindowState window = findWindow(hashCode);
5255 if (window == null) {
5256 return false;
5257 }
5258
5259 data = Parcel.obtain();
5260 data.writeInterfaceToken("android.view.IWindow");
5261 data.writeString(command);
5262 data.writeString(parameters);
5263 data.writeInt(1);
5264 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5265
5266 reply = Parcel.obtain();
5267
5268 final IBinder binder = window.mClient.asBinder();
5269 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5270 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5271
5272 reply.readException();
5273
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005274 if (!client.isOutputShutdown()) {
5275 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5276 out.write("DONE\n");
5277 out.flush();
5278 }
5279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005280 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005281 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005282 success = false;
5283 } finally {
5284 if (data != null) {
5285 data.recycle();
5286 }
5287 if (reply != null) {
5288 reply.recycle();
5289 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005290 if (out != null) {
5291 try {
5292 out.close();
5293 } catch (IOException e) {
5294
5295 }
5296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005297 }
5298
5299 return success;
5300 }
5301
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005302 public void addWindowChangeListener(WindowChangeListener listener) {
5303 synchronized(mWindowMap) {
5304 mWindowChangeListeners.add(listener);
5305 }
5306 }
5307
5308 public void removeWindowChangeListener(WindowChangeListener listener) {
5309 synchronized(mWindowMap) {
5310 mWindowChangeListeners.remove(listener);
5311 }
5312 }
5313
5314 private void notifyWindowsChanged() {
5315 WindowChangeListener[] windowChangeListeners;
5316 synchronized(mWindowMap) {
5317 if(mWindowChangeListeners.isEmpty()) {
5318 return;
5319 }
5320 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5321 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5322 }
5323 int N = windowChangeListeners.length;
5324 for(int i = 0; i < N; i++) {
5325 windowChangeListeners[i].windowsChanged();
5326 }
5327 }
5328
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005329 private void notifyFocusChanged() {
5330 WindowChangeListener[] windowChangeListeners;
5331 synchronized(mWindowMap) {
5332 if(mWindowChangeListeners.isEmpty()) {
5333 return;
5334 }
5335 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5336 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5337 }
5338 int N = windowChangeListeners.length;
5339 for(int i = 0; i < N; i++) {
5340 windowChangeListeners[i].focusChanged();
5341 }
5342 }
5343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005344 private WindowState findWindow(int hashCode) {
5345 if (hashCode == -1) {
5346 return getFocusedWindow();
5347 }
5348
5349 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005350 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351 final int count = windows.size();
5352
5353 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005354 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005355 if (System.identityHashCode(w) == hashCode) {
5356 return w;
5357 }
5358 }
5359 }
5360
5361 return null;
5362 }
5363
5364 /*
5365 * Instruct the Activity Manager to fetch the current configuration and broadcast
5366 * that to config-changed listeners if appropriate.
5367 */
5368 void sendNewConfiguration() {
5369 try {
5370 mActivityManager.updateConfiguration(null);
5371 } catch (RemoteException e) {
5372 }
5373 }
Romain Guy06882f82009-06-10 13:36:04 -07005374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005375 public Configuration computeNewConfiguration() {
5376 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005377 return computeNewConfigurationLocked();
5378 }
5379 }
Romain Guy06882f82009-06-10 13:36:04 -07005380
Dianne Hackbornc485a602009-03-24 22:39:49 -07005381 Configuration computeNewConfigurationLocked() {
5382 Configuration config = new Configuration();
5383 if (!computeNewConfigurationLocked(config)) {
5384 return null;
5385 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005386 return config;
5387 }
Romain Guy06882f82009-06-10 13:36:04 -07005388
Dianne Hackbornc485a602009-03-24 22:39:49 -07005389 boolean computeNewConfigurationLocked(Configuration config) {
5390 if (mDisplay == null) {
5391 return false;
5392 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005393
5394 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005395
5396 // Use the effective "visual" dimensions based on current rotation
5397 final boolean rotated = (mRotation == Surface.ROTATION_90
5398 || mRotation == Surface.ROTATION_270);
5399 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5400 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5401
Dianne Hackbornc485a602009-03-24 22:39:49 -07005402 int orientation = Configuration.ORIENTATION_SQUARE;
5403 if (dw < dh) {
5404 orientation = Configuration.ORIENTATION_PORTRAIT;
5405 } else if (dw > dh) {
5406 orientation = Configuration.ORIENTATION_LANDSCAPE;
5407 }
5408 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005409
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005410 DisplayMetrics dm = new DisplayMetrics();
5411 mDisplay.getMetrics(dm);
5412 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5413
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005414 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005415 // Note we only do this once because at this point we don't
5416 // expect the screen to change in this way at runtime, and want
5417 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005418 int longSize = dw;
5419 int shortSize = dh;
5420 if (longSize < shortSize) {
5421 int tmp = longSize;
5422 longSize = shortSize;
5423 shortSize = tmp;
5424 }
5425 longSize = (int)(longSize/dm.density);
5426 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005427
Dianne Hackborn723738c2009-06-25 19:48:04 -07005428 // These semi-magic numbers define our compatibility modes for
5429 // applications with different screens. Don't change unless you
5430 // make sure to test lots and lots of apps!
5431 if (longSize < 470) {
5432 // This is shorter than an HVGA normal density screen (which
5433 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005434 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5435 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005436 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005437 // What size is this screen screen?
5438 if (longSize >= 800 && shortSize >= 600) {
5439 // SVGA or larger screens at medium density are the point
5440 // at which we consider it to be an extra large screen.
5441 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005442 } else if (longSize >= 530 && shortSize >= 400) {
5443 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005444 // at which we consider it to be a large screen.
5445 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5446 } else {
5447 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005448
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005449 // If this screen is wider than normal HVGA, or taller
5450 // than FWVGA, then for old apps we want to run in size
5451 // compatibility mode.
5452 if (shortSize > 321 || longSize > 570) {
5453 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5454 }
5455 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005456
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005457 // Is this a long screen?
5458 if (((longSize*3)/5) >= (shortSize-1)) {
5459 // Anything wider than WVGA (5:3) is considering to be long.
5460 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5461 } else {
5462 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5463 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005464 }
5465 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005466 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005467
Dianne Hackbornc485a602009-03-24 22:39:49 -07005468 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5469 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5470 mPolicy.adjustConfigurationLw(config);
5471 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005472 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005473
5474 // -------------------------------------------------------------
5475 // Drag and drop
5476 // -------------------------------------------------------------
5477
5478 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5479 boolean localOnly, int width, int height, Surface outSurface) {
5480 if (DEBUG_DRAG) {
5481 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5482 + " local=" + localOnly + " win=" + window
5483 + " asbinder=" + window.asBinder());
5484 }
5485
5486 final int callerPid = Binder.getCallingPid();
5487 final long origId = Binder.clearCallingIdentity();
5488 IBinder token = null;
5489
5490 try {
5491 synchronized (mWindowMap) {
5492 try {
5493 // !!! TODO: fail if the given window does not currently have touch focus?
5494
5495 if (mDragState == null) {
5496 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5497 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5498 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005499 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005500 token = new Binder();
Chris Tate7b362e42010-11-04 16:02:52 -07005501 mDragState = new DragState(token, surface, localOnly, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005502 mDragState.mSurface = surface;
5503 mDragState.mLocalOnly = localOnly;
5504 token = mDragState.mToken = new Binder();
5505
5506 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005507 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5508 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005509 mH.sendMessageDelayed(msg, 5000);
5510 } else {
5511 Slog.w(TAG, "Drag already in progress");
5512 }
5513 } catch (Surface.OutOfResourcesException e) {
5514 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5515 if (mDragState != null) {
5516 mDragState.reset();
5517 mDragState = null;
5518 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005519 }
5520 }
5521 } finally {
5522 Binder.restoreCallingIdentity(origId);
5523 }
5524
5525 return token;
5526 }
5527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005528 // -------------------------------------------------------------
5529 // Input Events and Focus Management
5530 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005531
Jeff Brown349703e2010-06-22 01:27:15 -07005532 InputMonitor mInputMonitor = new InputMonitor();
5533
5534 /* Tracks the progress of input dispatch and ensures that input dispatch state
5535 * is kept in sync with changes in window focus, visibility, registration, and
5536 * other relevant Window Manager state transitions. */
5537 final class InputMonitor {
5538 // Current window with input focus for keys and other non-touch events. May be null.
5539 private WindowState mInputFocus;
5540
5541 // When true, prevents input dispatch from proceeding until set to false again.
5542 private boolean mInputDispatchFrozen;
5543
5544 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5545 private boolean mInputDispatchEnabled = true;
5546
5547 // Temporary list of windows information to provide to the input dispatcher.
5548 private InputWindowList mTempInputWindows = new InputWindowList();
5549
5550 // Temporary input application object to provide to the input dispatcher.
5551 private InputApplication mTempInputApplication = new InputApplication();
5552
5553 /* Notifies the window manager about a broken input channel.
5554 *
5555 * Called by the InputManager.
5556 */
5557 public void notifyInputChannelBroken(InputChannel inputChannel) {
5558 synchronized (mWindowMap) {
5559 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5560 if (windowState == null) {
5561 return; // irrelevant
5562 }
5563
5564 Slog.i(TAG, "WINDOW DIED " + windowState);
5565 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005566 }
5567 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005568
Jeff Brown519e0242010-09-15 15:18:56 -07005569 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005570 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005571 *
5572 * Called by the InputManager.
5573 */
Jeff Brown519e0242010-09-15 15:18:56 -07005574 public long notifyANR(Object token, InputChannel inputChannel) {
5575 AppWindowToken appWindowToken = null;
5576 if (inputChannel != null) {
5577 synchronized (mWindowMap) {
5578 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5579 if (windowState != null) {
5580 Slog.i(TAG, "Input event dispatching timed out sending to "
5581 + windowState.mAttrs.getTitle());
5582 appWindowToken = windowState.mAppToken;
5583 }
Jeff Brown349703e2010-06-22 01:27:15 -07005584 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005585 }
5586
Jeff Brown519e0242010-09-15 15:18:56 -07005587 if (appWindowToken == null && token != null) {
5588 appWindowToken = (AppWindowToken) token;
5589 Slog.i(TAG, "Input event dispatching timed out sending to application "
5590 + appWindowToken.stringName);
5591 }
Jeff Brown349703e2010-06-22 01:27:15 -07005592
Jeff Brown519e0242010-09-15 15:18:56 -07005593 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005594 try {
5595 // Notify the activity manager about the timeout and let it decide whether
5596 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005597 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005598 if (! abort) {
5599 // The activity manager declined to abort dispatching.
5600 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005601 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005602 }
Jeff Brown349703e2010-06-22 01:27:15 -07005603 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005604 }
5605 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005606 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005607 }
5608
Jeff Brown349703e2010-06-22 01:27:15 -07005609 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5610 synchronized (mWindowMap) {
5611 return getWindowStateForInputChannelLocked(inputChannel);
5612 }
5613 }
5614
5615 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5616 int windowCount = mWindows.size();
5617 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005618 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005619 if (windowState.mInputChannel == inputChannel) {
5620 return windowState;
5621 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005622 }
5623
Jeff Brown349703e2010-06-22 01:27:15 -07005624 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005625 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005626
Chris Tatea32dcf72010-10-14 12:13:50 -07005627 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005628 final InputWindow inputWindow = windowList.add();
5629 inputWindow.inputChannel = mDragState.mServerChannel;
5630 inputWindow.name = "drag";
5631 inputWindow.layoutParamsFlags = 0;
5632 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5633 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5634 inputWindow.visible = true;
5635 inputWindow.canReceiveKeys = false;
5636 inputWindow.hasFocus = true;
5637 inputWindow.hasWallpaper = false;
5638 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005639 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005640 inputWindow.ownerPid = Process.myPid();
5641 inputWindow.ownerUid = Process.myUid();
5642
5643 // The drag window covers the entire display
5644 inputWindow.frameLeft = 0;
5645 inputWindow.frameTop = 0;
5646 inputWindow.frameRight = mDisplay.getWidth();
5647 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005648
Christopher Tatea53146c2010-09-07 11:57:52 -07005649 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5650 inputWindow.visibleFrameTop = inputWindow.frameTop;
5651 inputWindow.visibleFrameRight = inputWindow.frameRight;
5652 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5653
5654 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5655 inputWindow.touchableAreaTop = inputWindow.frameTop;
5656 inputWindow.touchableAreaRight = inputWindow.frameRight;
5657 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5658 }
5659
Jeff Brown349703e2010-06-22 01:27:15 -07005660 /* Updates the cached window information provided to the input dispatcher. */
5661 public void updateInputWindowsLw() {
5662 // Populate the input window list with information about all of the windows that
5663 // could potentially receive input.
5664 // As an optimization, we could try to prune the list of windows but this turns
5665 // out to be difficult because only the native code knows for sure which window
5666 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005667 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005668
5669 // If there's a drag in flight, provide a pseudowindow to catch drag input
5670 final boolean inDrag = (mDragState != null);
5671 if (inDrag) {
5672 if (DEBUG_DRAG) {
5673 Log.d(TAG, "Inserting drag window");
5674 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005675 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005676 }
5677
Jeff Brown7fbdc842010-06-17 20:52:56 -07005678 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005679 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005680 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005681 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005682 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005683 continue;
5684 }
5685
Jeff Brown349703e2010-06-22 01:27:15 -07005686 final int flags = child.mAttrs.flags;
5687 final int type = child.mAttrs.type;
5688
5689 final boolean hasFocus = (child == mInputFocus);
5690 final boolean isVisible = child.isVisibleLw();
5691 final boolean hasWallpaper = (child == mWallpaperTarget)
5692 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005693
5694 // If there's a drag in progress and 'child' is a potential drop target,
5695 // make sure it's been told about the drag
5696 if (inDrag && isVisible) {
5697 mDragState.sendDragStartedIfNeededLw(child);
5698 }
5699
Jeff Brown349703e2010-06-22 01:27:15 -07005700 // Add a window to our list of input windows.
5701 final InputWindow inputWindow = mTempInputWindows.add();
5702 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005703 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005704 inputWindow.layoutParamsFlags = flags;
5705 inputWindow.layoutParamsType = type;
5706 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5707 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005708 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005709 inputWindow.hasFocus = hasFocus;
5710 inputWindow.hasWallpaper = hasWallpaper;
5711 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005712 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005713 inputWindow.ownerPid = child.mSession.mPid;
5714 inputWindow.ownerUid = child.mSession.mUid;
5715
5716 final Rect frame = child.mFrame;
5717 inputWindow.frameLeft = frame.left;
5718 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005719 inputWindow.frameRight = frame.right;
5720 inputWindow.frameBottom = frame.bottom;
5721
5722 final Rect visibleFrame = child.mVisibleFrame;
5723 inputWindow.visibleFrameLeft = visibleFrame.left;
5724 inputWindow.visibleFrameTop = visibleFrame.top;
5725 inputWindow.visibleFrameRight = visibleFrame.right;
5726 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005727
5728 switch (child.mTouchableInsets) {
5729 default:
5730 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5731 inputWindow.touchableAreaLeft = frame.left;
5732 inputWindow.touchableAreaTop = frame.top;
5733 inputWindow.touchableAreaRight = frame.right;
5734 inputWindow.touchableAreaBottom = frame.bottom;
5735 break;
5736
5737 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5738 Rect inset = child.mGivenContentInsets;
5739 inputWindow.touchableAreaLeft = frame.left + inset.left;
5740 inputWindow.touchableAreaTop = frame.top + inset.top;
5741 inputWindow.touchableAreaRight = frame.right - inset.right;
5742 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5743 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005744 }
Jeff Brown349703e2010-06-22 01:27:15 -07005745
5746 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5747 Rect inset = child.mGivenVisibleInsets;
5748 inputWindow.touchableAreaLeft = frame.left + inset.left;
5749 inputWindow.touchableAreaTop = frame.top + inset.top;
5750 inputWindow.touchableAreaRight = frame.right - inset.right;
5751 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005752 break;
5753 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005754 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005755 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005756
Jeff Brown349703e2010-06-22 01:27:15 -07005757 // Send windows to native code.
5758 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005759
Jeff Brown349703e2010-06-22 01:27:15 -07005760 // Clear the list in preparation for the next round.
5761 // Also avoids keeping InputChannel objects referenced unnecessarily.
5762 mTempInputWindows.clear();
5763 }
5764
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005765 /* Notifies that the lid switch changed state. */
5766 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5767 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5768 }
5769
Jeff Brown349703e2010-06-22 01:27:15 -07005770 /* Provides an opportunity for the window manager policy to intercept early key
5771 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005772 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5773 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5774 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5775 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005776 }
5777
5778 /* Provides an opportunity for the window manager policy to process a key before
5779 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005780 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005781 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005782 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005783 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005784 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005785 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005786 }
5787
Jeff Brown3915bb82010-11-05 15:02:16 -07005788 /* Provides an opportunity for the window manager policy to process a key that
5789 * the application did not handle. */
5790 public boolean dispatchUnhandledKey(InputChannel focus,
5791 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
5792 int policyFlags) {
5793 WindowState windowState = getWindowStateForInputChannel(focus);
5794 return mPolicy.dispatchUnhandledKey(windowState, action, flags,
5795 keyCode, scanCode, metaState, repeatCount, policyFlags);
5796 }
5797
Jeff Brown349703e2010-06-22 01:27:15 -07005798 /* Called when the current input focus changes.
5799 * Layer assignment is assumed to be complete by the time this is called.
5800 */
5801 public void setInputFocusLw(WindowState newWindow) {
5802 if (DEBUG_INPUT) {
5803 Slog.d(TAG, "Input focus has changed to " + newWindow);
5804 }
5805
5806 if (newWindow != mInputFocus) {
5807 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005808 // Displaying a window implicitly causes dispatching to be unpaused.
5809 // This is to protect against bugs if someone pauses dispatching but
5810 // forgets to resume.
5811 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005812 }
Jeff Brown349703e2010-06-22 01:27:15 -07005813
5814 mInputFocus = newWindow;
5815 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005816 }
5817 }
5818
Jeff Brown349703e2010-06-22 01:27:15 -07005819 public void setFocusedAppLw(AppWindowToken newApp) {
5820 // Focused app has changed.
5821 if (newApp == null) {
5822 mInputManager.setFocusedApplication(null);
5823 } else {
5824 mTempInputApplication.name = newApp.toString();
5825 mTempInputApplication.dispatchingTimeoutNanos =
5826 newApp.inputDispatchingTimeoutNanos;
5827 mTempInputApplication.token = newApp;
5828
5829 mInputManager.setFocusedApplication(mTempInputApplication);
5830 }
5831 }
5832
Jeff Brown349703e2010-06-22 01:27:15 -07005833 public void pauseDispatchingLw(WindowToken window) {
5834 if (! window.paused) {
5835 if (DEBUG_INPUT) {
5836 Slog.v(TAG, "Pausing WindowToken " + window);
5837 }
5838
5839 window.paused = true;
5840 updateInputWindowsLw();
5841 }
5842 }
5843
5844 public void resumeDispatchingLw(WindowToken window) {
5845 if (window.paused) {
5846 if (DEBUG_INPUT) {
5847 Slog.v(TAG, "Resuming WindowToken " + window);
5848 }
5849
5850 window.paused = false;
5851 updateInputWindowsLw();
5852 }
5853 }
5854
5855 public void freezeInputDispatchingLw() {
5856 if (! mInputDispatchFrozen) {
5857 if (DEBUG_INPUT) {
5858 Slog.v(TAG, "Freezing input dispatching");
5859 }
5860
5861 mInputDispatchFrozen = true;
5862 updateInputDispatchModeLw();
5863 }
5864 }
5865
5866 public void thawInputDispatchingLw() {
5867 if (mInputDispatchFrozen) {
5868 if (DEBUG_INPUT) {
5869 Slog.v(TAG, "Thawing input dispatching");
5870 }
5871
5872 mInputDispatchFrozen = false;
5873 updateInputDispatchModeLw();
5874 }
5875 }
5876
5877 public void setEventDispatchingLw(boolean enabled) {
5878 if (mInputDispatchEnabled != enabled) {
5879 if (DEBUG_INPUT) {
5880 Slog.v(TAG, "Setting event dispatching to " + enabled);
5881 }
5882
5883 mInputDispatchEnabled = enabled;
5884 updateInputDispatchModeLw();
5885 }
5886 }
5887
5888 private void updateInputDispatchModeLw() {
5889 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5890 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005893 public void pauseKeyDispatching(IBinder _token) {
5894 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5895 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005896 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005897 }
5898
5899 synchronized (mWindowMap) {
5900 WindowToken token = mTokenMap.get(_token);
5901 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005902 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005903 }
5904 }
5905 }
5906
5907 public void resumeKeyDispatching(IBinder _token) {
5908 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5909 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005910 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 }
5912
5913 synchronized (mWindowMap) {
5914 WindowToken token = mTokenMap.get(_token);
5915 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005916 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005917 }
5918 }
5919 }
5920
5921 public void setEventDispatching(boolean enabled) {
5922 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5923 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005924 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005925 }
5926
5927 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005928 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005929 }
5930 }
Romain Guy06882f82009-06-10 13:36:04 -07005931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005932 /**
5933 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005934 * Even when sync is false, this method may block while waiting for current
5935 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005936 *
5937 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005938 * {@link SystemClock#uptimeMillis()} as the timebase.)
5939 * @param sync If true, wait for the event to be completed before returning to the caller.
5940 * @return Returns true if event was dispatched, false if it was dropped for any reason
5941 */
5942 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5943 long downTime = ev.getDownTime();
5944 long eventTime = ev.getEventTime();
5945
5946 int action = ev.getAction();
5947 int code = ev.getKeyCode();
5948 int repeatCount = ev.getRepeatCount();
5949 int metaState = ev.getMetaState();
5950 int deviceId = ev.getDeviceId();
5951 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005952 int source = ev.getSource();
5953
5954 if (source == InputDevice.SOURCE_UNKNOWN) {
5955 source = InputDevice.SOURCE_KEYBOARD;
5956 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005957
5958 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5959 if (downTime == 0) downTime = eventTime;
5960
5961 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005962 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005964 final int pid = Binder.getCallingPid();
5965 final int uid = Binder.getCallingUid();
5966 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005967
Jeff Brownbbda99d2010-07-28 15:48:59 -07005968 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5969 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5970 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5971 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005972
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005973 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005974 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005975 }
5976
5977 /**
5978 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005979 * Even when sync is false, this method may block while waiting for current
5980 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005981 *
5982 * @param ev A motion event describing the pointer (touch) action. (As noted in
5983 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005984 * {@link SystemClock#uptimeMillis()} as the timebase.)
5985 * @param sync If true, wait for the event to be completed before returning to the caller.
5986 * @return Returns true if event was dispatched, false if it was dropped for any reason
5987 */
5988 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005989 final int pid = Binder.getCallingPid();
5990 final int uid = Binder.getCallingUid();
5991 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005992
Jeff Brownc5ed5912010-07-14 18:48:53 -07005993 MotionEvent newEvent = MotionEvent.obtain(ev);
5994 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5995 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5996 }
5997
Jeff Brownbbda99d2010-07-28 15:48:59 -07005998 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5999 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6000 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6001 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006002
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006003 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006004 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006005 }
Romain Guy06882f82009-06-10 13:36:04 -07006006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006007 /**
6008 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006009 * Even when sync is false, this method may block while waiting for current
6010 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006011 *
6012 * @param ev A motion event describing the trackball action. (As noted in
6013 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006014 * {@link SystemClock#uptimeMillis()} as the timebase.)
6015 * @param sync If true, wait for the event to be completed before returning to the caller.
6016 * @return Returns true if event was dispatched, false if it was dropped for any reason
6017 */
6018 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006019 final int pid = Binder.getCallingPid();
6020 final int uid = Binder.getCallingUid();
6021 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006022
Jeff Brownc5ed5912010-07-14 18:48:53 -07006023 MotionEvent newEvent = MotionEvent.obtain(ev);
6024 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6025 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6026 }
6027
Jeff Brownbbda99d2010-07-28 15:48:59 -07006028 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6029 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6030 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6031 INJECTION_TIMEOUT_MILLIS);
6032
6033 Binder.restoreCallingIdentity(ident);
6034 return reportInjectionResult(result);
6035 }
6036
6037 /**
6038 * Inject an input event into the UI without waiting for dispatch to commence.
6039 * This variant is useful for fire-and-forget input event injection. It does not
6040 * block any longer than it takes to enqueue the input event.
6041 *
6042 * @param ev An input event. (Be sure to set the input source correctly.)
6043 * @return Returns true if event was dispatched, false if it was dropped for any reason
6044 */
6045 public boolean injectInputEventNoWait(InputEvent ev) {
6046 final int pid = Binder.getCallingPid();
6047 final int uid = Binder.getCallingUid();
6048 final long ident = Binder.clearCallingIdentity();
6049
6050 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6051 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6052 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006053
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006054 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006055 return reportInjectionResult(result);
6056 }
6057
6058 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006059 switch (result) {
6060 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6061 Slog.w(TAG, "Input event injection permission denied.");
6062 throw new SecurityException(
6063 "Injecting to another application requires INJECT_EVENTS permission");
6064 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006065 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006066 return true;
6067 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6068 Slog.w(TAG, "Input event injection timed out.");
6069 return false;
6070 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6071 default:
6072 Slog.w(TAG, "Input event injection failed.");
6073 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006075 }
Romain Guy06882f82009-06-10 13:36:04 -07006076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006077 private WindowState getFocusedWindow() {
6078 synchronized (mWindowMap) {
6079 return getFocusedWindowLocked();
6080 }
6081 }
6082
6083 private WindowState getFocusedWindowLocked() {
6084 return mCurrentFocus;
6085 }
Romain Guy06882f82009-06-10 13:36:04 -07006086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006087 public boolean detectSafeMode() {
6088 mSafeMode = mPolicy.detectSafeMode();
6089 return mSafeMode;
6090 }
Romain Guy06882f82009-06-10 13:36:04 -07006091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006092 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006093 synchronized(mWindowMap) {
6094 if (mDisplay != null) {
6095 throw new IllegalStateException("Display already initialized");
6096 }
6097 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6098 mDisplay = wm.getDefaultDisplay();
6099 mInitialDisplayWidth = mDisplay.getWidth();
6100 mInitialDisplayHeight = mDisplay.getHeight();
6101 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6102 }
6103
6104 try {
6105 mActivityManager.updateConfiguration(null);
6106 } catch (RemoteException e) {
6107 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006108
6109 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006110 }
6111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006112 // -------------------------------------------------------------
6113 // Client Session State
6114 // -------------------------------------------------------------
6115
6116 private final class Session extends IWindowSession.Stub
6117 implements IBinder.DeathRecipient {
6118 final IInputMethodClient mClient;
6119 final IInputContext mInputContext;
6120 final int mUid;
6121 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006122 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123 SurfaceSession mSurfaceSession;
6124 int mNumWindow = 0;
6125 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006127 public Session(IInputMethodClient client, IInputContext inputContext) {
6128 mClient = client;
6129 mInputContext = inputContext;
6130 mUid = Binder.getCallingUid();
6131 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006132 StringBuilder sb = new StringBuilder();
6133 sb.append("Session{");
6134 sb.append(Integer.toHexString(System.identityHashCode(this)));
6135 sb.append(" uid ");
6136 sb.append(mUid);
6137 sb.append("}");
6138 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006140 synchronized (mWindowMap) {
6141 if (mInputMethodManager == null && mHaveInputMethods) {
6142 IBinder b = ServiceManager.getService(
6143 Context.INPUT_METHOD_SERVICE);
6144 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6145 }
6146 }
6147 long ident = Binder.clearCallingIdentity();
6148 try {
6149 // Note: it is safe to call in to the input method manager
6150 // here because we are not holding our lock.
6151 if (mInputMethodManager != null) {
6152 mInputMethodManager.addClient(client, inputContext,
6153 mUid, mPid);
6154 } else {
6155 client.setUsingInputMethod(false);
6156 }
6157 client.asBinder().linkToDeath(this, 0);
6158 } catch (RemoteException e) {
6159 // The caller has died, so we can just forget about this.
6160 try {
6161 if (mInputMethodManager != null) {
6162 mInputMethodManager.removeClient(client);
6163 }
6164 } catch (RemoteException ee) {
6165 }
6166 } finally {
6167 Binder.restoreCallingIdentity(ident);
6168 }
6169 }
Romain Guy06882f82009-06-10 13:36:04 -07006170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006171 @Override
6172 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6173 throws RemoteException {
6174 try {
6175 return super.onTransact(code, data, reply, flags);
6176 } catch (RuntimeException e) {
6177 // Log all 'real' exceptions thrown to the caller
6178 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006179 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006180 }
6181 throw e;
6182 }
6183 }
6184
6185 public void binderDied() {
6186 // Note: it is safe to call in to the input method manager
6187 // here because we are not holding our lock.
6188 try {
6189 if (mInputMethodManager != null) {
6190 mInputMethodManager.removeClient(mClient);
6191 }
6192 } catch (RemoteException e) {
6193 }
6194 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006195 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006196 mClientDead = true;
6197 killSessionLocked();
6198 }
6199 }
6200
6201 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006202 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6203 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6204 outInputChannel);
6205 }
6206
6207 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006208 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006209 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006210 }
Romain Guy06882f82009-06-10 13:36:04 -07006211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006212 public void remove(IWindow window) {
6213 removeWindow(this, window);
6214 }
Romain Guy06882f82009-06-10 13:36:04 -07006215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6217 int requestedWidth, int requestedHeight, int viewFlags,
6218 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006219 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006220 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6221 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006222 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006223 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006224 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6225 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006226 }
Romain Guy06882f82009-06-10 13:36:04 -07006227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 public void setTransparentRegion(IWindow window, Region region) {
6229 setTransparentRegionWindow(this, window, region);
6230 }
Romain Guy06882f82009-06-10 13:36:04 -07006231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006232 public void setInsets(IWindow window, int touchableInsets,
6233 Rect contentInsets, Rect visibleInsets) {
6234 setInsetsWindow(this, window, touchableInsets, contentInsets,
6235 visibleInsets);
6236 }
Romain Guy06882f82009-06-10 13:36:04 -07006237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006238 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6239 getWindowDisplayFrame(this, window, outDisplayFrame);
6240 }
Romain Guy06882f82009-06-10 13:36:04 -07006241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006242 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006243 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006244 TAG, "IWindow finishDrawing called for " + window);
6245 finishDrawingWindow(this, window);
6246 }
6247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006248 public void setInTouchMode(boolean mode) {
6249 synchronized(mWindowMap) {
6250 mInTouchMode = mode;
6251 }
6252 }
6253
6254 public boolean getInTouchMode() {
6255 synchronized(mWindowMap) {
6256 return mInTouchMode;
6257 }
6258 }
6259
6260 public boolean performHapticFeedback(IWindow window, int effectId,
6261 boolean always) {
6262 synchronized(mWindowMap) {
6263 long ident = Binder.clearCallingIdentity();
6264 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006265 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006266 windowForClientLocked(this, window, true),
6267 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 } finally {
6269 Binder.restoreCallingIdentity(ident);
6270 }
6271 }
6272 }
Romain Guy06882f82009-06-10 13:36:04 -07006273
Christopher Tatea53146c2010-09-07 11:57:52 -07006274 /* Drag/drop */
6275 public IBinder prepareDrag(IWindow window, boolean localOnly,
6276 int width, int height, Surface outSurface) {
6277 return prepareDragSurface(window, mSurfaceSession, localOnly,
6278 width, height, outSurface);
6279 }
6280
6281 public boolean performDrag(IWindow window, IBinder dragToken,
6282 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6283 ClipData data) {
6284 if (DEBUG_DRAG) {
6285 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6286 }
6287
6288 synchronized (mWindowMap) {
6289 if (mDragState == null) {
6290 Slog.w(TAG, "No drag prepared");
6291 throw new IllegalStateException("performDrag() without prepareDrag()");
6292 }
6293
6294 if (dragToken != mDragState.mToken) {
6295 Slog.w(TAG, "Performing mismatched drag");
6296 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6297 }
6298
6299 WindowState callingWin = windowForClientLocked(null, window, false);
6300 if (callingWin == null) {
6301 Slog.w(TAG, "Bad requesting window " + window);
6302 return false; // !!! TODO: throw here?
6303 }
6304
6305 // !!! TODO: if input is not still focused on the initiating window, fail
6306 // the drag initiation (e.g. an alarm window popped up just as the application
6307 // called performDrag()
6308
6309 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6310
Christopher Tate2c095f32010-10-04 14:13:40 -07006311 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6312 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006313
Chris Tateb478f462010-10-15 16:02:26 -07006314 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6315 // the actual drag event dispatch stuff in the dragstate
6316
Christopher Tatea53146c2010-09-07 11:57:52 -07006317 mDragState.register();
6318 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006319 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6320 mDragState.mServerChannel)) {
6321 Slog.e(TAG, "Unable to transfer touch focus");
6322 mDragState.unregister();
6323 mDragState = null;
6324 mInputMonitor.updateInputWindowsLw();
6325 return false;
6326 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006327
6328 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006329 mDragState.mCurrentX = touchX;
6330 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006331 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006332
6333 // remember the thumb offsets for later
6334 mDragState.mThumbOffsetX = thumbCenterX;
6335 mDragState.mThumbOffsetY = thumbCenterY;
6336
6337 // Make the surface visible at the proper location
6338 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006339 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006340 try {
6341 surface.setPosition((int)(touchX - thumbCenterX),
6342 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006343 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006344 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006345 surface.show();
6346 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006347 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006348 }
6349 }
6350
6351 return true; // success!
6352 }
6353
Chris Tated4533f12010-10-19 15:15:08 -07006354 public void reportDropResult(IWindow window, boolean consumed) {
6355 IBinder token = window.asBinder();
6356 if (DEBUG_DRAG) {
6357 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6358 }
6359
6360 synchronized (mWindowMap) {
6361 if (mDragState.mToken != token) {
6362 Slog.w(TAG, "Invalid drop-result claim by " + window);
6363 throw new IllegalStateException("reportDropResult() by non-recipient");
6364 }
6365
6366 // The right window has responded, even if it's no longer around,
6367 // so be sure to halt the timeout even if the later WindowState
6368 // lookup fails.
6369 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6370
6371 WindowState callingWin = windowForClientLocked(null, window, false);
6372 if (callingWin == null) {
6373 Slog.w(TAG, "Bad result-reporting window " + window);
6374 return; // !!! TODO: throw here?
6375 }
6376
6377 mDragState.mDragResult = consumed;
6378 mDragState.endDragLw();
6379 }
6380 }
6381
Christopher Tatea53146c2010-09-07 11:57:52 -07006382 public void dragRecipientEntered(IWindow window) {
6383 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006384 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006385 }
6386 }
6387
6388 public void dragRecipientExited(IWindow window) {
6389 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006390 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006391 }
6392 }
6393
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006394 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006395 synchronized(mWindowMap) {
6396 long ident = Binder.clearCallingIdentity();
6397 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006398 setWindowWallpaperPositionLocked(
6399 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006400 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006401 } finally {
6402 Binder.restoreCallingIdentity(ident);
6403 }
6404 }
6405 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006406
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006407 public void wallpaperOffsetsComplete(IBinder window) {
6408 WindowManagerService.this.wallpaperOffsetsComplete(window);
6409 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006410
Dianne Hackborn75804932009-10-20 20:15:20 -07006411 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6412 int z, Bundle extras, boolean sync) {
6413 synchronized(mWindowMap) {
6414 long ident = Binder.clearCallingIdentity();
6415 try {
6416 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006417 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006418 action, x, y, z, extras, sync);
6419 } finally {
6420 Binder.restoreCallingIdentity(ident);
6421 }
6422 }
6423 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006424
Dianne Hackborn75804932009-10-20 20:15:20 -07006425 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6426 WindowManagerService.this.wallpaperCommandComplete(window, result);
6427 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 void windowAddedLocked() {
6430 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006431 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 TAG, "First window added to " + this + ", creating SurfaceSession");
6433 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006434 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006435 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006436 mSessions.add(this);
6437 }
6438 mNumWindow++;
6439 }
6440
6441 void windowRemovedLocked() {
6442 mNumWindow--;
6443 killSessionLocked();
6444 }
Romain Guy06882f82009-06-10 13:36:04 -07006445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006446 void killSessionLocked() {
6447 if (mNumWindow <= 0 && mClientDead) {
6448 mSessions.remove(this);
6449 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006450 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451 TAG, "Last window removed from " + this
6452 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006453 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006454 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006455 try {
6456 mSurfaceSession.kill();
6457 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006458 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006459 + mSurfaceSession + " in session " + this
6460 + ": " + e.toString());
6461 }
6462 mSurfaceSession = null;
6463 }
6464 }
6465 }
Romain Guy06882f82009-06-10 13:36:04 -07006466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006468 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6469 pw.print(" mClientDead="); pw.print(mClientDead);
6470 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006471 }
6472
6473 @Override
6474 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006475 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 }
6477 }
6478
6479 // -------------------------------------------------------------
6480 // Client Window State
6481 // -------------------------------------------------------------
6482
6483 private final class WindowState implements WindowManagerPolicy.WindowState {
6484 final Session mSession;
6485 final IWindow mClient;
6486 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006487 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 AppWindowToken mAppToken;
6489 AppWindowToken mTargetAppToken;
6490 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6491 final DeathRecipient mDeathRecipient;
6492 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006493 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 final int mBaseLayer;
6495 final int mSubLayer;
6496 final boolean mLayoutAttached;
6497 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006498 final boolean mIsWallpaper;
6499 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006500 int mViewVisibility;
6501 boolean mPolicyVisibility = true;
6502 boolean mPolicyVisibilityAfterAnim = true;
6503 boolean mAppFreezing;
6504 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006505 boolean mReportDestroySurface;
6506 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006507 boolean mAttachedHidden; // is our parent window hidden?
6508 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006509 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 int mRequestedWidth;
6511 int mRequestedHeight;
6512 int mLastRequestedWidth;
6513 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006514 int mLayer;
6515 int mAnimLayer;
6516 int mLastLayer;
6517 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006518 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006519 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006520
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006521 int mLayoutSeq = -1;
6522
6523 Configuration mConfiguration = null;
6524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 // Actual frame shown on-screen (may be modified by animation)
6526 final Rect mShownFrame = new Rect();
6527 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006529 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006530 * Set when we have changed the size of the surface, to know that
6531 * we must tell them application to resize (and thus redraw itself).
6532 */
6533 boolean mSurfaceResized;
6534
6535 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006536 * Insets that determine the actually visible area
6537 */
6538 final Rect mVisibleInsets = new Rect();
6539 final Rect mLastVisibleInsets = new Rect();
6540 boolean mVisibleInsetsChanged;
6541
6542 /**
6543 * Insets that are covered by system windows
6544 */
6545 final Rect mContentInsets = new Rect();
6546 final Rect mLastContentInsets = new Rect();
6547 boolean mContentInsetsChanged;
6548
6549 /**
6550 * Set to true if we are waiting for this window to receive its
6551 * given internal insets before laying out other windows based on it.
6552 */
6553 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006555 /**
6556 * These are the content insets that were given during layout for
6557 * this window, to be applied to windows behind it.
6558 */
6559 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 /**
6562 * These are the visible insets that were given during layout for
6563 * this window, to be applied to windows behind it.
6564 */
6565 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 /**
6568 * Flag indicating whether the touchable region should be adjusted by
6569 * the visible insets; if false the area outside the visible insets is
6570 * NOT touchable, so we must use those to adjust the frame during hit
6571 * tests.
6572 */
6573 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006575 // Current transformation being applied.
6576 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6577 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6578 float mHScale=1, mVScale=1;
6579 float mLastHScale=1, mLastVScale=1;
6580 final Matrix mTmpMatrix = new Matrix();
6581
6582 // "Real" frame that the application sees.
6583 final Rect mFrame = new Rect();
6584 final Rect mLastFrame = new Rect();
6585
6586 final Rect mContainingFrame = new Rect();
6587 final Rect mDisplayFrame = new Rect();
6588 final Rect mContentFrame = new Rect();
6589 final Rect mVisibleFrame = new Rect();
6590
6591 float mShownAlpha = 1;
6592 float mAlpha = 1;
6593 float mLastAlpha = 1;
6594
6595 // Set to true if, when the window gets displayed, it should perform
6596 // an enter animation.
6597 boolean mEnterAnimationPending;
6598
6599 // Currently running animation.
6600 boolean mAnimating;
6601 boolean mLocalAnimating;
6602 Animation mAnimation;
6603 boolean mAnimationIsEntrance;
6604 boolean mHasTransformation;
6605 boolean mHasLocalTransformation;
6606 final Transformation mTransformation = new Transformation();
6607
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006608 // If a window showing a wallpaper: the requested offset for the
6609 // wallpaper; if a wallpaper window: the currently applied offset.
6610 float mWallpaperX = -1;
6611 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006612
6613 // If a window showing a wallpaper: what fraction of the offset
6614 // range corresponds to a full virtual screen.
6615 float mWallpaperXStep = -1;
6616 float mWallpaperYStep = -1;
6617
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006618 // Wallpaper windows: pixels offset based on above variables.
6619 int mXOffset;
6620 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006622 // This is set after IWindowSession.relayout() has been called at
6623 // least once for the window. It allows us to detect the situation
6624 // where we don't yet have a surface, but should have one soon, so
6625 // we can give the window focus before waiting for the relayout.
6626 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006628 // This is set after the Surface has been created but before the
6629 // window has been drawn. During this time the surface is hidden.
6630 boolean mDrawPending;
6631
6632 // This is set after the window has finished drawing for the first
6633 // time but before its surface is shown. The surface will be
6634 // displayed when the next layout is run.
6635 boolean mCommitDrawPending;
6636
6637 // This is set during the time after the window's drawing has been
6638 // committed, and before its surface is actually shown. It is used
6639 // to delay showing the surface until all windows in a token are ready
6640 // to be shown.
6641 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006643 // Set when the window has been shown in the screen the first time.
6644 boolean mHasDrawn;
6645
6646 // Currently running an exit animation?
6647 boolean mExiting;
6648
6649 // Currently on the mDestroySurface list?
6650 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006652 // Completely remove from window manager after exit animation?
6653 boolean mRemoveOnExit;
6654
6655 // Set when the orientation is changing and this window has not yet
6656 // been updated for the new orientation.
6657 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006659 // Is this window now (or just being) removed?
6660 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006661
Dianne Hackborn16064f92010-03-25 00:47:24 -07006662 // For debugging, this is the last information given to the surface flinger.
6663 boolean mSurfaceShown;
6664 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6665 int mSurfaceLayer;
6666 float mSurfaceAlpha;
6667
Jeff Brown46b9ac02010-04-22 18:58:52 -07006668 // Input channel
6669 InputChannel mInputChannel;
6670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 WindowState(Session s, IWindow c, WindowToken token,
6672 WindowState attachedWindow, WindowManager.LayoutParams a,
6673 int viewVisibility) {
6674 mSession = s;
6675 mClient = c;
6676 mToken = token;
6677 mAttrs.copyFrom(a);
6678 mViewVisibility = viewVisibility;
6679 DeathRecipient deathRecipient = new DeathRecipient();
6680 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006681 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006682 TAG, "Window " + this + " client=" + c.asBinder()
6683 + " token=" + token + " (" + mAttrs.token + ")");
6684 try {
6685 c.asBinder().linkToDeath(deathRecipient, 0);
6686 } catch (RemoteException e) {
6687 mDeathRecipient = null;
6688 mAttachedWindow = null;
6689 mLayoutAttached = false;
6690 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006691 mIsWallpaper = false;
6692 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006693 mBaseLayer = 0;
6694 mSubLayer = 0;
6695 return;
6696 }
6697 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6700 mAttrs.type <= LAST_SUB_WINDOW)) {
6701 // The multiplier here is to reserve space for multiple
6702 // windows in the same type layer.
6703 mBaseLayer = mPolicy.windowTypeToLayerLw(
6704 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6705 + TYPE_LAYER_OFFSET;
6706 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6707 mAttachedWindow = attachedWindow;
6708 mAttachedWindow.mChildWindows.add(this);
6709 mLayoutAttached = mAttrs.type !=
6710 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6711 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6712 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006713 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6714 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 } else {
6716 // The multiplier here is to reserve space for multiple
6717 // windows in the same type layer.
6718 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6719 * TYPE_LAYER_MULTIPLIER
6720 + TYPE_LAYER_OFFSET;
6721 mSubLayer = 0;
6722 mAttachedWindow = null;
6723 mLayoutAttached = false;
6724 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6725 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006726 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6727 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 }
6729
6730 WindowState appWin = this;
6731 while (appWin.mAttachedWindow != null) {
6732 appWin = mAttachedWindow;
6733 }
6734 WindowToken appToken = appWin.mToken;
6735 while (appToken.appWindowToken == null) {
6736 WindowToken parent = mTokenMap.get(appToken.token);
6737 if (parent == null || appToken == parent) {
6738 break;
6739 }
6740 appToken = parent;
6741 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006742 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006743 mAppToken = appToken.appWindowToken;
6744
6745 mSurface = null;
6746 mRequestedWidth = 0;
6747 mRequestedHeight = 0;
6748 mLastRequestedWidth = 0;
6749 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006750 mXOffset = 0;
6751 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 mLayer = 0;
6753 mAnimLayer = 0;
6754 mLastLayer = 0;
6755 }
6756
6757 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006758 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006759 TAG, "Attaching " + this + " token=" + mToken
6760 + ", list=" + mToken.windows);
6761 mSession.windowAddedLocked();
6762 }
6763
6764 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6765 mHaveFrame = true;
6766
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006767 final Rect container = mContainingFrame;
6768 container.set(pf);
6769
6770 final Rect display = mDisplayFrame;
6771 display.set(df);
6772
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006773 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006774 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006775 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6776 display.intersect(mCompatibleScreenFrame);
6777 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006778 }
6779
6780 final int pw = container.right - container.left;
6781 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006782
6783 int w,h;
6784 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6785 w = mAttrs.width < 0 ? pw : mAttrs.width;
6786 h = mAttrs.height< 0 ? ph : mAttrs.height;
6787 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006788 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6789 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006790 }
Romain Guy06882f82009-06-10 13:36:04 -07006791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006792 final Rect content = mContentFrame;
6793 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006795 final Rect visible = mVisibleFrame;
6796 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006799 final int fw = frame.width();
6800 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006802 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6803 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6804
6805 Gravity.apply(mAttrs.gravity, w, h, container,
6806 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6807 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6808
6809 //System.out.println("Out: " + mFrame);
6810
6811 // Now make sure the window fits in the overall display.
6812 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 // Make sure the content and visible frames are inside of the
6815 // final window frame.
6816 if (content.left < frame.left) content.left = frame.left;
6817 if (content.top < frame.top) content.top = frame.top;
6818 if (content.right > frame.right) content.right = frame.right;
6819 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6820 if (visible.left < frame.left) visible.left = frame.left;
6821 if (visible.top < frame.top) visible.top = frame.top;
6822 if (visible.right > frame.right) visible.right = frame.right;
6823 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 final Rect contentInsets = mContentInsets;
6826 contentInsets.left = content.left-frame.left;
6827 contentInsets.top = content.top-frame.top;
6828 contentInsets.right = frame.right-content.right;
6829 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831 final Rect visibleInsets = mVisibleInsets;
6832 visibleInsets.left = visible.left-frame.left;
6833 visibleInsets.top = visible.top-frame.top;
6834 visibleInsets.right = frame.right-visible.right;
6835 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006836
Dianne Hackborn284ac932009-08-28 10:34:25 -07006837 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6838 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006839 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006840 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006842 if (localLOGV) {
6843 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6844 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006845 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 + mRequestedWidth + ", mRequestedheight="
6847 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6848 + "): frame=" + mFrame.toShortString()
6849 + " ci=" + contentInsets.toShortString()
6850 + " vi=" + visibleInsets.toShortString());
6851 //}
6852 }
6853 }
Romain Guy06882f82009-06-10 13:36:04 -07006854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006855 public Rect getFrameLw() {
6856 return mFrame;
6857 }
6858
6859 public Rect getShownFrameLw() {
6860 return mShownFrame;
6861 }
6862
6863 public Rect getDisplayFrameLw() {
6864 return mDisplayFrame;
6865 }
6866
6867 public Rect getContentFrameLw() {
6868 return mContentFrame;
6869 }
6870
6871 public Rect getVisibleFrameLw() {
6872 return mVisibleFrame;
6873 }
6874
6875 public boolean getGivenInsetsPendingLw() {
6876 return mGivenInsetsPending;
6877 }
6878
6879 public Rect getGivenContentInsetsLw() {
6880 return mGivenContentInsets;
6881 }
Romain Guy06882f82009-06-10 13:36:04 -07006882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 public Rect getGivenVisibleInsetsLw() {
6884 return mGivenVisibleInsets;
6885 }
Romain Guy06882f82009-06-10 13:36:04 -07006886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 public WindowManager.LayoutParams getAttrs() {
6888 return mAttrs;
6889 }
6890
6891 public int getSurfaceLayer() {
6892 return mLayer;
6893 }
Romain Guy06882f82009-06-10 13:36:04 -07006894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006895 public IApplicationToken getAppToken() {
6896 return mAppToken != null ? mAppToken.appToken : null;
6897 }
Jeff Brown349703e2010-06-22 01:27:15 -07006898
6899 public long getInputDispatchingTimeoutNanos() {
6900 return mAppToken != null
6901 ? mAppToken.inputDispatchingTimeoutNanos
6902 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006904
6905 public boolean hasAppShownWindows() {
6906 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6907 }
6908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006909 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006910 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006911 TAG, "Setting animation in " + this + ": " + anim);
6912 mAnimating = false;
6913 mLocalAnimating = false;
6914 mAnimation = anim;
6915 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6916 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6917 }
6918
6919 public void clearAnimation() {
6920 if (mAnimation != null) {
6921 mAnimating = true;
6922 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07006923 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006924 mAnimation = null;
6925 }
6926 }
Romain Guy06882f82009-06-10 13:36:04 -07006927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006928 Surface createSurfaceLocked() {
6929 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006930 mReportDestroySurface = false;
6931 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006932 mDrawPending = true;
6933 mCommitDrawPending = false;
6934 mReadyToShow = false;
6935 if (mAppToken != null) {
6936 mAppToken.allDrawn = false;
6937 }
6938
6939 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006940 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 flags |= Surface.PUSH_BUFFERS;
6942 }
6943
6944 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6945 flags |= Surface.SECURE;
6946 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006947 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 TAG, "Creating surface in session "
6949 + mSession.mSurfaceSession + " window " + this
6950 + " w=" + mFrame.width()
6951 + " h=" + mFrame.height() + " format="
6952 + mAttrs.format + " flags=" + flags);
6953
6954 int w = mFrame.width();
6955 int h = mFrame.height();
6956 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6957 // for a scaled surface, we always want the requested
6958 // size.
6959 w = mRequestedWidth;
6960 h = mRequestedHeight;
6961 }
6962
Romain Guy9825ec62009-10-01 00:58:09 -07006963 // Something is wrong and SurfaceFlinger will not like this,
6964 // try to revert to sane values
6965 if (w <= 0) w = 1;
6966 if (h <= 0) h = 1;
6967
Dianne Hackborn16064f92010-03-25 00:47:24 -07006968 mSurfaceShown = false;
6969 mSurfaceLayer = 0;
6970 mSurfaceAlpha = 1;
6971 mSurfaceX = 0;
6972 mSurfaceY = 0;
6973 mSurfaceW = w;
6974 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006976 final boolean isHwAccelerated = (mAttrs.flags &
6977 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6978 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6979 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6980 flags |= Surface.OPAQUE;
6981 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006982 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006983 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006984 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006985 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006986 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006987 + mSurface + " IN SESSION "
6988 + mSession.mSurfaceSession
6989 + ": pid=" + mSession.mPid + " format="
6990 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006991 + Integer.toHexString(flags)
6992 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006993 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006994 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006995 reclaimSomeSurfaceMemoryLocked(this, "create");
6996 return null;
6997 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006998 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 return null;
7000 }
Romain Guy06882f82009-06-10 13:36:04 -07007001
Joe Onorato8a9b2202010-02-26 18:56:32 -08007002 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 TAG, "Got surface: " + mSurface
7004 + ", set left=" + mFrame.left + " top=" + mFrame.top
7005 + ", animLayer=" + mAnimLayer);
7006 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007007 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007008 if (SHOW_TRANSACTIONS) logSurface(this,
7009 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7010 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7011 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 }
7013 Surface.openTransaction();
7014 try {
7015 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007016 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007017 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007018 mSurface.setPosition(mSurfaceX, mSurfaceY);
7019 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007020 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007021 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 mSurface.hide();
7023 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007024 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007025 mSurface.setFlags(Surface.SURFACE_DITHER,
7026 Surface.SURFACE_DITHER);
7027 }
7028 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007029 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7031 }
7032 mLastHidden = true;
7033 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007034 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 Surface.closeTransaction();
7036 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007037 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 TAG, "Created surface " + this);
7039 }
7040 return mSurface;
7041 }
Romain Guy06882f82009-06-10 13:36:04 -07007042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007043 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044 if (mAppToken != null && this == mAppToken.startingWindow) {
7045 mAppToken.startingDisplayed = false;
7046 }
Romain Guy06882f82009-06-10 13:36:04 -07007047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007048 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007049 mDrawPending = false;
7050 mCommitDrawPending = false;
7051 mReadyToShow = false;
7052
7053 int i = mChildWindows.size();
7054 while (i > 0) {
7055 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007056 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007057 c.mAttachedHidden = true;
7058 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007059
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007060 if (mReportDestroySurface) {
7061 mReportDestroySurface = false;
7062 mSurfacePendingDestroy = true;
7063 try {
7064 mClient.dispatchGetNewSurface();
7065 // We'll really destroy on the next time around.
7066 return;
7067 } catch (RemoteException e) {
7068 }
7069 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007071 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007072 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007073 RuntimeException e = null;
7074 if (!HIDE_STACK_CRAWLS) {
7075 e = new RuntimeException();
7076 e.fillInStackTrace();
7077 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007078 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007079 + mSurface + ", session " + mSession, e);
7080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007081 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007082 RuntimeException e = null;
7083 if (!HIDE_STACK_CRAWLS) {
7084 e = new RuntimeException();
7085 e.fillInStackTrace();
7086 }
7087 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007088 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007089 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007091 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007092 + " surface " + mSurface + " session " + mSession
7093 + ": " + e.toString());
7094 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007095
Dianne Hackborn16064f92010-03-25 00:47:24 -07007096 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007098 }
7099 }
7100
7101 boolean finishDrawingLocked() {
7102 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007103 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007104 TAG, "finishDrawingLocked: " + mSurface);
7105 mCommitDrawPending = true;
7106 mDrawPending = false;
7107 return true;
7108 }
7109 return false;
7110 }
7111
7112 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007113 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007114 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007116 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007117 }
7118 mCommitDrawPending = false;
7119 mReadyToShow = true;
7120 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7121 final AppWindowToken atoken = mAppToken;
7122 if (atoken == null || atoken.allDrawn || starting) {
7123 performShowLocked();
7124 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007125 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 }
7127
7128 // This must be called while inside a transaction.
7129 boolean performShowLocked() {
7130 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007131 RuntimeException e = null;
7132 if (!HIDE_STACK_CRAWLS) {
7133 e = new RuntimeException();
7134 e.fillInStackTrace();
7135 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007136 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007137 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7138 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7139 }
7140 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007141 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7142 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007143 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007144 + " during animation: policyVis=" + mPolicyVisibility
7145 + " attHidden=" + mAttachedHidden
7146 + " tok.hiddenRequested="
7147 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007148 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 + (mAppToken != null ? mAppToken.hidden : false)
7150 + " animating=" + mAnimating
7151 + " tok animating="
7152 + (mAppToken != null ? mAppToken.animating : false));
7153 if (!showSurfaceRobustlyLocked(this)) {
7154 return false;
7155 }
7156 mLastAlpha = -1;
7157 mHasDrawn = true;
7158 mLastHidden = false;
7159 mReadyToShow = false;
7160 enableScreenIfNeededLocked();
7161
7162 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007164 int i = mChildWindows.size();
7165 while (i > 0) {
7166 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007167 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007168 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007169 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007170 if (c.mSurface != null) {
7171 c.performShowLocked();
7172 // It hadn't been shown, which means layout not
7173 // performed on it, so now we want to make sure to
7174 // do a layout. If called from within the transaction
7175 // loop, this will cause it to restart with a new
7176 // layout.
7177 mLayoutNeeded = true;
7178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007179 }
7180 }
Romain Guy06882f82009-06-10 13:36:04 -07007181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007182 if (mAttrs.type != TYPE_APPLICATION_STARTING
7183 && mAppToken != null) {
7184 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007185
Dianne Hackborn248b1882009-09-16 16:46:44 -07007186 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007187 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007188 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007189 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007190 // If this initial window is animating, stop it -- we
7191 // will do an animation to reveal it from behind the
7192 // starting window, so there is no need for it to also
7193 // be doing its own stuff.
7194 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007195 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007196 mAnimation = null;
7197 // Make sure we clean up the animation.
7198 mAnimating = true;
7199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007200 mFinishedStarting.add(mAppToken);
7201 mH.sendEmptyMessage(H.FINISHED_STARTING);
7202 }
7203 mAppToken.updateReportedVisibilityLocked();
7204 }
7205 }
7206 return true;
7207 }
Romain Guy06882f82009-06-10 13:36:04 -07007208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007209 // This must be called while inside a transaction. Returns true if
7210 // there is more animation to run.
7211 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007212 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007213 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7216 mHasTransformation = true;
7217 mHasLocalTransformation = true;
7218 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007219 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007220 TAG, "Starting animation in " + this +
7221 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7222 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7223 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7224 mAnimation.setStartTime(currentTime);
7225 mLocalAnimating = true;
7226 mAnimating = true;
7227 }
7228 mTransformation.clear();
7229 final boolean more = mAnimation.getTransformation(
7230 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007231 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 TAG, "Stepped animation in " + this +
7233 ": more=" + more + ", xform=" + mTransformation);
7234 if (more) {
7235 // we're not done!
7236 return true;
7237 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007238 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239 TAG, "Finished animation in " + this +
7240 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007241
7242 if (mAnimation != null) {
7243 mAnimation.cancel();
7244 mAnimation = null;
7245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007246 //WindowManagerService.this.dump();
7247 }
7248 mHasLocalTransformation = false;
7249 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007250 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007251 // When our app token is animating, we kind-of pretend like
7252 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7253 // part of this check means that we will only do this if
7254 // our window is not currently exiting, or it is not
7255 // locally animating itself. The idea being that one that
7256 // is exiting and doing a local animation should be removed
7257 // once that animation is done.
7258 mAnimating = true;
7259 mHasTransformation = true;
7260 mTransformation.clear();
7261 return false;
7262 } else if (mHasTransformation) {
7263 // Little trick to get through the path below to act like
7264 // we have finished an animation.
7265 mAnimating = true;
7266 } else if (isAnimating()) {
7267 mAnimating = true;
7268 }
7269 } else if (mAnimation != null) {
7270 // If the display is frozen, and there is a pending animation,
7271 // clear it and make sure we run the cleanup code.
7272 mAnimating = true;
7273 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007274 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007275 mAnimation = null;
7276 }
Romain Guy06882f82009-06-10 13:36:04 -07007277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278 if (!mAnimating && !mLocalAnimating) {
7279 return false;
7280 }
7281
Joe Onorato8a9b2202010-02-26 18:56:32 -08007282 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 TAG, "Animation done in " + this + ": exiting=" + mExiting
7284 + ", reportedVisible="
7285 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 mAnimating = false;
7288 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007289 if (mAnimation != null) {
7290 mAnimation.cancel();
7291 mAnimation = null;
7292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 mAnimLayer = mLayer;
7294 if (mIsImWindow) {
7295 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007296 } else if (mIsWallpaper) {
7297 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007298 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007299 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 + " anim layer: " + mAnimLayer);
7301 mHasTransformation = false;
7302 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007303 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7304 if (DEBUG_VISIBILITY) {
7305 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7306 + mPolicyVisibilityAfterAnim);
7307 }
7308 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7309 if (!mPolicyVisibility) {
7310 if (mCurrentFocus == this) {
7311 mFocusMayChange = true;
7312 }
7313 // Window is no longer visible -- make sure if we were waiting
7314 // for it to be displayed before enabling the display, that
7315 // we allow the display to be enabled now.
7316 enableScreenIfNeededLocked();
7317 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007319 mTransformation.clear();
7320 if (mHasDrawn
7321 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7322 && mAppToken != null
7323 && mAppToken.firstWindowDrawn
7324 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007325 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007326 + mToken + ": first real window done animating");
7327 mFinishedStarting.add(mAppToken);
7328 mH.sendEmptyMessage(H.FINISHED_STARTING);
7329 }
Romain Guy06882f82009-06-10 13:36:04 -07007330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 finishExit();
7332
7333 if (mAppToken != null) {
7334 mAppToken.updateReportedVisibilityLocked();
7335 }
7336
7337 return false;
7338 }
7339
7340 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007341 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 TAG, "finishExit in " + this
7343 + ": exiting=" + mExiting
7344 + " remove=" + mRemoveOnExit
7345 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 final int N = mChildWindows.size();
7348 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007349 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 }
Romain Guy06882f82009-06-10 13:36:04 -07007351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 if (!mExiting) {
7353 return;
7354 }
Romain Guy06882f82009-06-10 13:36:04 -07007355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007356 if (isWindowAnimating()) {
7357 return;
7358 }
7359
Joe Onorato8a9b2202010-02-26 18:56:32 -08007360 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007361 TAG, "Exit animation finished in " + this
7362 + ": remove=" + mRemoveOnExit);
7363 if (mSurface != null) {
7364 mDestroySurface.add(this);
7365 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007366 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007367 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 try {
7369 mSurface.hide();
7370 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007371 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 }
7373 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007374 }
7375 mExiting = false;
7376 if (mRemoveOnExit) {
7377 mPendingRemove.add(this);
7378 mRemoveOnExit = false;
7379 }
7380 }
Romain Guy06882f82009-06-10 13:36:04 -07007381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7383 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7384 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7385 if (dtdx < -.000001f || dtdx > .000001f) return false;
7386 if (dsdy < -.000001f || dsdy > .000001f) return false;
7387 return true;
7388 }
Romain Guy06882f82009-06-10 13:36:04 -07007389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007390 void computeShownFrameLocked() {
7391 final boolean selfTransformation = mHasLocalTransformation;
7392 Transformation attachedTransformation =
7393 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7394 ? mAttachedWindow.mTransformation : null;
7395 Transformation appTransformation =
7396 (mAppToken != null && mAppToken.hasTransformation)
7397 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007398
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007399 // Wallpapers are animated based on the "real" window they
7400 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007401 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007402 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007403 if (mWallpaperTarget.mHasLocalTransformation &&
7404 mWallpaperTarget.mAnimation != null &&
7405 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007406 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007407 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007408 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007409 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007410 }
7411 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007412 mWallpaperTarget.mAppToken.hasTransformation &&
7413 mWallpaperTarget.mAppToken.animation != null &&
7414 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007415 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007416 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007417 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007418 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007419 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007420 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 if (selfTransformation || attachedTransformation != null
7423 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007424 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007425 final Rect frame = mFrame;
7426 final float tmpFloats[] = mTmpFloats;
7427 final Matrix tmpMatrix = mTmpMatrix;
7428
7429 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007430 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007431 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007432 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007434 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007436 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007437 }
7438 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007439 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 }
7441
7442 // "convert" it into SurfaceFlinger's format
7443 // (a 2x2 matrix + an offset)
7444 // Here we must not transform the position of the surface
7445 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007446 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 tmpMatrix.getValues(tmpFloats);
7449 mDsDx = tmpFloats[Matrix.MSCALE_X];
7450 mDtDx = tmpFloats[Matrix.MSKEW_X];
7451 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7452 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007453 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7454 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007455 int w = frame.width();
7456 int h = frame.height();
7457 mShownFrame.set(x, y, x+w, y+h);
7458
7459 // Now set the alpha... but because our current hardware
7460 // can't do alpha transformation on a non-opaque surface,
7461 // turn it off if we are running an animation that is also
7462 // transforming since it is more important to have that
7463 // animation be smooth.
7464 mShownAlpha = mAlpha;
7465 if (!mLimitedAlphaCompositing
7466 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7467 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7468 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007469 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 if (selfTransformation) {
7471 mShownAlpha *= mTransformation.getAlpha();
7472 }
7473 if (attachedTransformation != null) {
7474 mShownAlpha *= attachedTransformation.getAlpha();
7475 }
7476 if (appTransformation != null) {
7477 mShownAlpha *= appTransformation.getAlpha();
7478 }
7479 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007480 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 }
Romain Guy06882f82009-06-10 13:36:04 -07007482
Joe Onorato8a9b2202010-02-26 18:56:32 -08007483 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007484 TAG, "Continuing animation in " + this +
7485 ": " + mShownFrame +
7486 ", alpha=" + mTransformation.getAlpha());
7487 return;
7488 }
Romain Guy06882f82009-06-10 13:36:04 -07007489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007491 if (mXOffset != 0 || mYOffset != 0) {
7492 mShownFrame.offset(mXOffset, mYOffset);
7493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 mShownAlpha = mAlpha;
7495 mDsDx = 1;
7496 mDtDx = 0;
7497 mDsDy = 0;
7498 mDtDy = 1;
7499 }
Romain Guy06882f82009-06-10 13:36:04 -07007500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 /**
7502 * Is this window visible? It is not visible if there is no
7503 * surface, or we are in the process of running an exit animation
7504 * that will remove the surface, or its app token has been hidden.
7505 */
7506 public boolean isVisibleLw() {
7507 final AppWindowToken atoken = mAppToken;
7508 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7509 && (atoken == null || !atoken.hiddenRequested)
7510 && !mExiting && !mDestroying;
7511 }
7512
7513 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007514 * Like {@link #isVisibleLw}, but also counts a window that is currently
7515 * "hidden" behind the keyguard as visible. This allows us to apply
7516 * things like window flags that impact the keyguard.
7517 * XXX I am starting to think we need to have ANOTHER visibility flag
7518 * for this "hidden behind keyguard" state rather than overloading
7519 * mPolicyVisibility. Ungh.
7520 */
7521 public boolean isVisibleOrBehindKeyguardLw() {
7522 final AppWindowToken atoken = mAppToken;
7523 return mSurface != null && !mAttachedHidden
7524 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007525 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007526 && !mExiting && !mDestroying;
7527 }
7528
7529 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 * Is this window visible, ignoring its app token? It is not visible
7531 * if there is no surface, or we are in the process of running an exit animation
7532 * that will remove the surface.
7533 */
7534 public boolean isWinVisibleLw() {
7535 final AppWindowToken atoken = mAppToken;
7536 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7537 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7538 && !mExiting && !mDestroying;
7539 }
7540
7541 /**
7542 * The same as isVisible(), but follows the current hidden state of
7543 * the associated app token, not the pending requested hidden state.
7544 */
7545 boolean isVisibleNow() {
7546 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007547 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007548 }
7549
7550 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007551 * Can this window possibly be a drag/drop target? The test here is
7552 * a combination of the above "visible now" with the check that the
7553 * Input Manager uses when discarding windows from input consideration.
7554 */
7555 boolean isPotentialDragTarget() {
7556 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7557 }
7558
7559 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007560 * Same as isVisible(), but we also count it as visible between the
7561 * call to IWindowSession.add() and the first relayout().
7562 */
7563 boolean isVisibleOrAdding() {
7564 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007565 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007566 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7567 && mPolicyVisibility && !mAttachedHidden
7568 && (atoken == null || !atoken.hiddenRequested)
7569 && !mExiting && !mDestroying;
7570 }
7571
7572 /**
7573 * Is this window currently on-screen? It is on-screen either if it
7574 * is visible or it is currently running an animation before no longer
7575 * being visible.
7576 */
7577 boolean isOnScreen() {
7578 final AppWindowToken atoken = mAppToken;
7579 if (atoken != null) {
7580 return mSurface != null && mPolicyVisibility && !mDestroying
7581 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007582 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007583 } else {
7584 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007585 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007586 }
7587 }
Romain Guy06882f82009-06-10 13:36:04 -07007588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007589 /**
7590 * Like isOnScreen(), but we don't return true if the window is part
7591 * of a transition that has not yet been started.
7592 */
7593 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007594 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007595 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007596 return false;
7597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007598 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007599 final boolean animating = atoken != null
7600 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007601 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007602 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7603 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007604 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 }
7606
7607 /** Is the window or its container currently animating? */
7608 boolean isAnimating() {
7609 final WindowState attached = mAttachedWindow;
7610 final AppWindowToken atoken = mAppToken;
7611 return mAnimation != null
7612 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007613 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 (atoken.animation != null
7615 || atoken.inPendingTransaction));
7616 }
7617
7618 /** Is this window currently animating? */
7619 boolean isWindowAnimating() {
7620 return mAnimation != null;
7621 }
7622
7623 /**
7624 * Like isOnScreen, but returns false if the surface hasn't yet
7625 * been drawn.
7626 */
7627 public boolean isDisplayedLw() {
7628 final AppWindowToken atoken = mAppToken;
7629 return mSurface != null && mPolicyVisibility && !mDestroying
7630 && !mDrawPending && !mCommitDrawPending
7631 && ((!mAttachedHidden &&
7632 (atoken == null || !atoken.hiddenRequested))
7633 || mAnimating);
7634 }
7635
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007636 /**
7637 * Returns true if the window has a surface that it has drawn a
7638 * complete UI in to.
7639 */
7640 public boolean isDrawnLw() {
7641 final AppWindowToken atoken = mAppToken;
7642 return mSurface != null && !mDestroying
7643 && !mDrawPending && !mCommitDrawPending;
7644 }
7645
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007646 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007647 * Return true if the window is opaque and fully drawn. This indicates
7648 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007649 */
7650 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007651 return (mAttrs.format == PixelFormat.OPAQUE
7652 || mAttrs.type == TYPE_WALLPAPER)
7653 && mSurface != null && mAnimation == null
7654 && (mAppToken == null || mAppToken.animation == null)
7655 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007656 }
7657
7658 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7659 return
7660 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007661 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7662 // only if it's visible
7663 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007664 // and only if the application fills the compatible screen
7665 mFrame.left <= mCompatibleScreenFrame.left &&
7666 mFrame.top <= mCompatibleScreenFrame.top &&
7667 mFrame.right >= mCompatibleScreenFrame.right &&
7668 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007669 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007670 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007671 }
7672
7673 boolean isFullscreen(int screenWidth, int screenHeight) {
7674 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007675 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007676 }
7677
7678 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007679 disposeInputChannel();
7680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007681 if (mAttachedWindow != null) {
7682 mAttachedWindow.mChildWindows.remove(this);
7683 }
7684 destroySurfaceLocked();
7685 mSession.windowRemovedLocked();
7686 try {
7687 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7688 } catch (RuntimeException e) {
7689 // Ignore if it has already been removed (usually because
7690 // we are doing this as part of processing a death note.)
7691 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007692 }
7693
7694 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007695 if (mInputChannel != null) {
7696 mInputManager.unregisterInputChannel(mInputChannel);
7697
7698 mInputChannel.dispose();
7699 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07007700 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007701 }
7702
7703 private class DeathRecipient implements IBinder.DeathRecipient {
7704 public void binderDied() {
7705 try {
7706 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007707 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007708 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007709 if (win != null) {
7710 removeWindowLocked(mSession, win);
7711 }
7712 }
7713 } catch (IllegalArgumentException ex) {
7714 // This will happen if the window has already been
7715 // removed.
7716 }
7717 }
7718 }
7719
7720 /** Returns true if this window desires key events. */
7721 public final boolean canReceiveKeys() {
7722 return isVisibleOrAdding()
7723 && (mViewVisibility == View.VISIBLE)
7724 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7725 }
7726
7727 public boolean hasDrawnLw() {
7728 return mHasDrawn;
7729 }
7730
7731 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007732 return showLw(doAnimation, true);
7733 }
7734
7735 boolean showLw(boolean doAnimation, boolean requestAnim) {
7736 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7737 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007738 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007739 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007740 if (doAnimation) {
7741 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7742 + mPolicyVisibility + " mAnimation=" + mAnimation);
7743 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7744 doAnimation = false;
7745 } else if (mPolicyVisibility && mAnimation == null) {
7746 // Check for the case where we are currently visible and
7747 // not animating; we do not want to do animation at such a
7748 // point to become visible when we already are.
7749 doAnimation = false;
7750 }
7751 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007752 mPolicyVisibility = true;
7753 mPolicyVisibilityAfterAnim = true;
7754 if (doAnimation) {
7755 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7756 }
7757 if (requestAnim) {
7758 requestAnimationLocked(0);
7759 }
7760 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 }
7762
7763 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007764 return hideLw(doAnimation, true);
7765 }
7766
7767 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007768 if (doAnimation) {
7769 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7770 doAnimation = false;
7771 }
7772 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007773 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7774 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007775 if (!current) {
7776 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007778 if (doAnimation) {
7779 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7780 if (mAnimation == null) {
7781 doAnimation = false;
7782 }
7783 }
7784 if (doAnimation) {
7785 mPolicyVisibilityAfterAnim = false;
7786 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007787 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007788 mPolicyVisibilityAfterAnim = false;
7789 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007790 // Window is no longer visible -- make sure if we were waiting
7791 // for it to be displayed before enabling the display, that
7792 // we allow the display to be enabled now.
7793 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007794 if (mCurrentFocus == this) {
7795 mFocusMayChange = true;
7796 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007797 }
7798 if (requestAnim) {
7799 requestAnimationLocked(0);
7800 }
7801 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007802 }
7803
7804 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007805 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7806 pw.print(" mClient="); pw.println(mClient.asBinder());
7807 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7808 if (mAttachedWindow != null || mLayoutAttached) {
7809 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7810 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7811 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007812 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7813 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7814 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007815 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7816 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007817 }
7818 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7819 pw.print(" mSubLayer="); pw.print(mSubLayer);
7820 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7821 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7822 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7823 pw.print("="); pw.print(mAnimLayer);
7824 pw.print(" mLastLayer="); pw.println(mLastLayer);
7825 if (mSurface != null) {
7826 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007827 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7828 pw.print(" layer="); pw.print(mSurfaceLayer);
7829 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7830 pw.print(" rect=("); pw.print(mSurfaceX);
7831 pw.print(","); pw.print(mSurfaceY);
7832 pw.print(") "); pw.print(mSurfaceW);
7833 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007834 }
7835 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7836 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7837 if (mAppToken != null) {
7838 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7839 }
7840 if (mTargetAppToken != null) {
7841 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7842 }
7843 pw.print(prefix); pw.print("mViewVisibility=0x");
7844 pw.print(Integer.toHexString(mViewVisibility));
7845 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007846 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7847 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007848 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7849 pw.print(prefix); pw.print("mPolicyVisibility=");
7850 pw.print(mPolicyVisibility);
7851 pw.print(" mPolicyVisibilityAfterAnim=");
7852 pw.print(mPolicyVisibilityAfterAnim);
7853 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7854 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007855 if (!mRelayoutCalled) {
7856 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7857 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007858 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007859 pw.print(" h="); pw.print(mRequestedHeight);
7860 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007861 if (mXOffset != 0 || mYOffset != 0) {
7862 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7863 pw.print(" y="); pw.println(mYOffset);
7864 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007865 pw.print(prefix); pw.print("mGivenContentInsets=");
7866 mGivenContentInsets.printShortString(pw);
7867 pw.print(" mGivenVisibleInsets=");
7868 mGivenVisibleInsets.printShortString(pw);
7869 pw.println();
7870 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7871 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7872 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7873 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007874 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007875 pw.print(prefix); pw.print("mShownFrame=");
7876 mShownFrame.printShortString(pw);
7877 pw.print(" last="); mLastShownFrame.printShortString(pw);
7878 pw.println();
7879 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7880 pw.print(" last="); mLastFrame.printShortString(pw);
7881 pw.println();
7882 pw.print(prefix); pw.print("mContainingFrame=");
7883 mContainingFrame.printShortString(pw);
7884 pw.print(" mDisplayFrame=");
7885 mDisplayFrame.printShortString(pw);
7886 pw.println();
7887 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7888 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7889 pw.println();
7890 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7891 pw.print(" last="); mLastContentInsets.printShortString(pw);
7892 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7893 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7894 pw.println();
7895 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7896 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7897 pw.print(" mAlpha="); pw.print(mAlpha);
7898 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7899 }
7900 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7901 || mAnimation != null) {
7902 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7903 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7904 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7905 pw.print(" mAnimation="); pw.println(mAnimation);
7906 }
7907 if (mHasTransformation || mHasLocalTransformation) {
7908 pw.print(prefix); pw.print("XForm: has=");
7909 pw.print(mHasTransformation);
7910 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7911 pw.print(" "); mTransformation.printShortString(pw);
7912 pw.println();
7913 }
7914 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7915 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7916 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7917 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7918 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7919 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7920 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7921 pw.print(" mDestroying="); pw.print(mDestroying);
7922 pw.print(" mRemoved="); pw.println(mRemoved);
7923 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007924 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007925 pw.print(prefix); pw.print("mOrientationChanging=");
7926 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007927 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7928 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007929 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007930 if (mHScale != 1 || mVScale != 1) {
7931 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7932 pw.print(" mVScale="); pw.println(mVScale);
7933 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007934 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007935 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7936 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7937 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007938 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7939 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7940 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7941 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007942 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007943
7944 String makeInputChannelName() {
7945 return Integer.toHexString(System.identityHashCode(this))
7946 + " " + mAttrs.getTitle();
7947 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007948
7949 @Override
7950 public String toString() {
7951 return "Window{"
7952 + Integer.toHexString(System.identityHashCode(this))
7953 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7954 }
7955 }
Romain Guy06882f82009-06-10 13:36:04 -07007956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007957 // -------------------------------------------------------------
7958 // Window Token State
7959 // -------------------------------------------------------------
7960
7961 class WindowToken {
7962 // The actual token.
7963 final IBinder token;
7964
7965 // The type of window this token is for, as per WindowManager.LayoutParams.
7966 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007968 // Set if this token was explicitly added by a client, so should
7969 // not be removed when all windows are removed.
7970 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007971
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007972 // For printing.
7973 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007975 // If this is an AppWindowToken, this is non-null.
7976 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007978 // All of the windows associated with this token.
7979 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7980
7981 // Is key dispatching paused for this token?
7982 boolean paused = false;
7983
7984 // Should this token's windows be hidden?
7985 boolean hidden;
7986
7987 // Temporary for finding which tokens no longer have visible windows.
7988 boolean hasVisible;
7989
Dianne Hackborna8f60182009-09-01 19:01:50 -07007990 // Set to true when this token is in a pending transaction where it
7991 // will be shown.
7992 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007993
Dianne Hackborna8f60182009-09-01 19:01:50 -07007994 // Set to true when this token is in a pending transaction where it
7995 // will be hidden.
7996 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007997
Dianne Hackborna8f60182009-09-01 19:01:50 -07007998 // Set to true when this token is in a pending transaction where its
7999 // windows will be put to the bottom of the list.
8000 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008001
Dianne Hackborna8f60182009-09-01 19:01:50 -07008002 // Set to true when this token is in a pending transaction where its
8003 // windows will be put to the top of the list.
8004 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008006 WindowToken(IBinder _token, int type, boolean _explicit) {
8007 token = _token;
8008 windowType = type;
8009 explicit = _explicit;
8010 }
8011
8012 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008013 pw.print(prefix); pw.print("token="); pw.println(token);
8014 pw.print(prefix); pw.print("windows="); pw.println(windows);
8015 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8016 pw.print(" hidden="); pw.print(hidden);
8017 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008018 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8019 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8020 pw.print(" waitingToHide="); pw.print(waitingToHide);
8021 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8022 pw.print(" sendingToTop="); pw.println(sendingToTop);
8023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008024 }
8025
8026 @Override
8027 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008028 if (stringName == null) {
8029 StringBuilder sb = new StringBuilder();
8030 sb.append("WindowToken{");
8031 sb.append(Integer.toHexString(System.identityHashCode(this)));
8032 sb.append(" token="); sb.append(token); sb.append('}');
8033 stringName = sb.toString();
8034 }
8035 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008036 }
8037 };
8038
8039 class AppWindowToken extends WindowToken {
8040 // Non-null only for application tokens.
8041 final IApplicationToken appToken;
8042
8043 // All of the windows and child windows that are included in this
8044 // application token. Note this list is NOT sorted!
8045 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8046
8047 int groupId = -1;
8048 boolean appFullscreen;
8049 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008050
8051 // The input dispatching timeout for this application token in nanoseconds.
8052 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008054 // These are used for determining when all windows associated with
8055 // an activity have been drawn, so they can be made visible together
8056 // at the same time.
8057 int lastTransactionSequence = mTransactionSequence-1;
8058 int numInterestingWindows;
8059 int numDrawnWindows;
8060 boolean inPendingTransaction;
8061 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008063 // Is this token going to be hidden in a little while? If so, it
8064 // won't be taken into account for setting the screen orientation.
8065 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008067 // Is this window's surface needed? This is almost like hidden, except
8068 // it will sometimes be true a little earlier: when the token has
8069 // been shown, but is still waiting for its app transition to execute
8070 // before making its windows shown.
8071 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008073 // Have we told the window clients to hide themselves?
8074 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 // Last visibility state we reported to the app token.
8077 boolean reportedVisible;
8078
8079 // Set to true when the token has been removed from the window mgr.
8080 boolean removed;
8081
8082 // Have we been asked to have this token keep the screen frozen?
8083 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008085 boolean animating;
8086 Animation animation;
8087 boolean hasTransformation;
8088 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008090 // Offset to the window of all layers in the token, for use by
8091 // AppWindowToken animations.
8092 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 // Information about an application starting window if displayed.
8095 StartingData startingData;
8096 WindowState startingWindow;
8097 View startingView;
8098 boolean startingDisplayed;
8099 boolean startingMoved;
8100 boolean firstWindowDrawn;
8101
8102 AppWindowToken(IApplicationToken _token) {
8103 super(_token.asBinder(),
8104 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8105 appWindowToken = this;
8106 appToken = _token;
8107 }
Romain Guy06882f82009-06-10 13:36:04 -07008108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008109 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008110 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 TAG, "Setting animation in " + this + ": " + anim);
8112 animation = anim;
8113 animating = false;
8114 anim.restrictDuration(MAX_ANIMATION_DURATION);
8115 anim.scaleCurrentDuration(mTransitionAnimationScale);
8116 int zorder = anim.getZAdjustment();
8117 int adj = 0;
8118 if (zorder == Animation.ZORDER_TOP) {
8119 adj = TYPE_LAYER_OFFSET;
8120 } else if (zorder == Animation.ZORDER_BOTTOM) {
8121 adj = -TYPE_LAYER_OFFSET;
8122 }
Romain Guy06882f82009-06-10 13:36:04 -07008123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008124 if (animLayerAdjustment != adj) {
8125 animLayerAdjustment = adj;
8126 updateLayers();
8127 }
8128 }
Romain Guy06882f82009-06-10 13:36:04 -07008129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008130 public void setDummyAnimation() {
8131 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008132 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 TAG, "Setting dummy animation in " + this);
8134 animation = sDummyAnimation;
8135 }
8136 }
8137
8138 public void clearAnimation() {
8139 if (animation != null) {
8140 animation = null;
8141 animating = true;
8142 }
8143 }
Romain Guy06882f82009-06-10 13:36:04 -07008144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 void updateLayers() {
8146 final int N = allAppWindows.size();
8147 final int adj = animLayerAdjustment;
8148 for (int i=0; i<N; i++) {
8149 WindowState w = allAppWindows.get(i);
8150 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008151 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008152 + w.mAnimLayer);
8153 if (w == mInputMethodTarget) {
8154 setInputMethodAnimLayerAdjustment(adj);
8155 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008156 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008157 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 }
8160 }
Romain Guy06882f82009-06-10 13:36:04 -07008161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 void sendAppVisibilityToClients() {
8163 final int N = allAppWindows.size();
8164 for (int i=0; i<N; i++) {
8165 WindowState win = allAppWindows.get(i);
8166 if (win == startingWindow && clientHidden) {
8167 // Don't hide the starting window.
8168 continue;
8169 }
8170 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008171 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008172 "Setting visibility of " + win + ": " + (!clientHidden));
8173 win.mClient.dispatchAppVisibility(!clientHidden);
8174 } catch (RemoteException e) {
8175 }
8176 }
8177 }
Romain Guy06882f82009-06-10 13:36:04 -07008178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008179 void showAllWindowsLocked() {
8180 final int NW = allAppWindows.size();
8181 for (int i=0; i<NW; i++) {
8182 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008183 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008184 "performing show on: " + w);
8185 w.performShowLocked();
8186 }
8187 }
Romain Guy06882f82009-06-10 13:36:04 -07008188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 // This must be called while inside a transaction.
8190 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008191 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008194 if (animation == sDummyAnimation) {
8195 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008196 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008197 // when it is really time to animate, this will be set to
8198 // a real animation and the next call will execute normally.
8199 return false;
8200 }
Romain Guy06882f82009-06-10 13:36:04 -07008201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008202 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8203 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008204 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 TAG, "Starting animation in " + this +
8206 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8207 + " scale=" + mTransitionAnimationScale
8208 + " allDrawn=" + allDrawn + " animating=" + animating);
8209 animation.initialize(dw, dh, dw, dh);
8210 animation.setStartTime(currentTime);
8211 animating = true;
8212 }
8213 transformation.clear();
8214 final boolean more = animation.getTransformation(
8215 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008216 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008217 TAG, "Stepped animation in " + this +
8218 ": more=" + more + ", xform=" + transformation);
8219 if (more) {
8220 // we're done!
8221 hasTransformation = true;
8222 return true;
8223 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008224 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008225 TAG, "Finished animation in " + this +
8226 " @ " + currentTime);
8227 animation = null;
8228 }
8229 } else if (animation != null) {
8230 // If the display is frozen, and there is a pending animation,
8231 // clear it and make sure we run the cleanup code.
8232 animating = true;
8233 animation = null;
8234 }
8235
8236 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 if (!animating) {
8239 return false;
8240 }
8241
8242 clearAnimation();
8243 animating = false;
8244 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8245 moveInputMethodWindowsIfNeededLocked(true);
8246 }
Romain Guy06882f82009-06-10 13:36:04 -07008247
Joe Onorato8a9b2202010-02-26 18:56:32 -08008248 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008249 TAG, "Animation done in " + this
8250 + ": reportedVisible=" + reportedVisible);
8251
8252 transformation.clear();
8253 if (animLayerAdjustment != 0) {
8254 animLayerAdjustment = 0;
8255 updateLayers();
8256 }
Romain Guy06882f82009-06-10 13:36:04 -07008257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008258 final int N = windows.size();
8259 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008260 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008261 }
8262 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008264 return false;
8265 }
8266
8267 void updateReportedVisibilityLocked() {
8268 if (appToken == null) {
8269 return;
8270 }
Romain Guy06882f82009-06-10 13:36:04 -07008271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008272 int numInteresting = 0;
8273 int numVisible = 0;
8274 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008275
Joe Onorato8a9b2202010-02-26 18:56:32 -08008276 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008277 final int N = allAppWindows.size();
8278 for (int i=0; i<N; i++) {
8279 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008280 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008281 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008282 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8283 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008284 continue;
8285 }
8286 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008287 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008288 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008289 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008290 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008291 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008292 + " pv=" + win.mPolicyVisibility
8293 + " dp=" + win.mDrawPending
8294 + " cdp=" + win.mCommitDrawPending
8295 + " ah=" + win.mAttachedHidden
8296 + " th="
8297 + (win.mAppToken != null
8298 ? win.mAppToken.hiddenRequested : false)
8299 + " a=" + win.mAnimating);
8300 }
8301 }
8302 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008303 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008304 if (!win.isAnimating()) {
8305 numVisible++;
8306 }
8307 nowGone = false;
8308 } else if (win.isAnimating()) {
8309 nowGone = false;
8310 }
8311 }
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008314 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008315 + numInteresting + " visible=" + numVisible);
8316 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008317 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008318 TAG, "Visibility changed in " + this
8319 + ": vis=" + nowVisible);
8320 reportedVisible = nowVisible;
8321 Message m = mH.obtainMessage(
8322 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8323 nowVisible ? 1 : 0,
8324 nowGone ? 1 : 0,
8325 this);
8326 mH.sendMessage(m);
8327 }
8328 }
Romain Guy06882f82009-06-10 13:36:04 -07008329
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008330 WindowState findMainWindow() {
8331 int j = windows.size();
8332 while (j > 0) {
8333 j--;
8334 WindowState win = windows.get(j);
8335 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8336 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8337 return win;
8338 }
8339 }
8340 return null;
8341 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008343 void dump(PrintWriter pw, String prefix) {
8344 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008345 if (appToken != null) {
8346 pw.print(prefix); pw.println("app=true");
8347 }
8348 if (allAppWindows.size() > 0) {
8349 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8350 }
8351 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008352 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008353 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8354 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8355 pw.print(" clientHidden="); pw.print(clientHidden);
8356 pw.print(" willBeHidden="); pw.print(willBeHidden);
8357 pw.print(" reportedVisible="); pw.println(reportedVisible);
8358 if (paused || freezingScreen) {
8359 pw.print(prefix); pw.print("paused="); pw.print(paused);
8360 pw.print(" freezingScreen="); pw.println(freezingScreen);
8361 }
8362 if (numInterestingWindows != 0 || numDrawnWindows != 0
8363 || inPendingTransaction || allDrawn) {
8364 pw.print(prefix); pw.print("numInterestingWindows=");
8365 pw.print(numInterestingWindows);
8366 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8367 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8368 pw.print(" allDrawn="); pw.println(allDrawn);
8369 }
8370 if (animating || animation != null) {
8371 pw.print(prefix); pw.print("animating="); pw.print(animating);
8372 pw.print(" animation="); pw.println(animation);
8373 }
8374 if (animLayerAdjustment != 0) {
8375 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8376 }
8377 if (hasTransformation) {
8378 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8379 pw.print(" transformation="); transformation.printShortString(pw);
8380 pw.println();
8381 }
8382 if (startingData != null || removed || firstWindowDrawn) {
8383 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8384 pw.print(" removed="); pw.print(removed);
8385 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8386 }
8387 if (startingWindow != null || startingView != null
8388 || startingDisplayed || startingMoved) {
8389 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8390 pw.print(" startingView="); pw.print(startingView);
8391 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8392 pw.print(" startingMoved"); pw.println(startingMoved);
8393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008394 }
8395
8396 @Override
8397 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008398 if (stringName == null) {
8399 StringBuilder sb = new StringBuilder();
8400 sb.append("AppWindowToken{");
8401 sb.append(Integer.toHexString(System.identityHashCode(this)));
8402 sb.append(" token="); sb.append(token); sb.append('}');
8403 stringName = sb.toString();
8404 }
8405 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008406 }
8407 }
Romain Guy06882f82009-06-10 13:36:04 -07008408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 // -------------------------------------------------------------
8410 // DummyAnimation
8411 // -------------------------------------------------------------
8412
8413 // This is an animation that does nothing: it just immediately finishes
8414 // itself every time it is called. It is used as a stub animation in cases
8415 // where we want to synchronize multiple things that may be animating.
8416 static final class DummyAnimation extends Animation {
8417 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8418 return false;
8419 }
8420 }
8421 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008423 // -------------------------------------------------------------
8424 // Async Handler
8425 // -------------------------------------------------------------
8426
8427 static final class StartingData {
8428 final String pkg;
8429 final int theme;
8430 final CharSequence nonLocalizedLabel;
8431 final int labelRes;
8432 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008434 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8435 int _labelRes, int _icon) {
8436 pkg = _pkg;
8437 theme = _theme;
8438 nonLocalizedLabel = _nonLocalizedLabel;
8439 labelRes = _labelRes;
8440 icon = _icon;
8441 }
8442 }
8443
8444 private final class H extends Handler {
8445 public static final int REPORT_FOCUS_CHANGE = 2;
8446 public static final int REPORT_LOSING_FOCUS = 3;
8447 public static final int ANIMATE = 4;
8448 public static final int ADD_STARTING = 5;
8449 public static final int REMOVE_STARTING = 6;
8450 public static final int FINISHED_STARTING = 7;
8451 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8453 public static final int HOLD_SCREEN_CHANGED = 12;
8454 public static final int APP_TRANSITION_TIMEOUT = 13;
8455 public static final int PERSIST_ANIMATION_SCALE = 14;
8456 public static final int FORCE_GC = 15;
8457 public static final int ENABLE_SCREEN = 16;
8458 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008459 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008460 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008461 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07008462 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008464 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 public H() {
8467 }
Romain Guy06882f82009-06-10 13:36:04 -07008468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 @Override
8470 public void handleMessage(Message msg) {
8471 switch (msg.what) {
8472 case REPORT_FOCUS_CHANGE: {
8473 WindowState lastFocus;
8474 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008476 synchronized(mWindowMap) {
8477 lastFocus = mLastFocus;
8478 newFocus = mCurrentFocus;
8479 if (lastFocus == newFocus) {
8480 // Focus is not changing, so nothing to do.
8481 return;
8482 }
8483 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008484 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008485 // + " to " + newFocus);
8486 if (newFocus != null && lastFocus != null
8487 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008488 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008489 mLosingFocus.add(lastFocus);
8490 lastFocus = null;
8491 }
8492 }
8493
8494 if (lastFocus != newFocus) {
8495 //System.out.println("Changing focus from " + lastFocus
8496 // + " to " + newFocus);
8497 if (newFocus != null) {
8498 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008499 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008500 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8501 } catch (RemoteException e) {
8502 // Ignore if process has died.
8503 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008504 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008505 }
8506
8507 if (lastFocus != null) {
8508 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008509 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008510 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8511 } catch (RemoteException e) {
8512 // Ignore if process has died.
8513 }
8514 }
8515 }
8516 } break;
8517
8518 case REPORT_LOSING_FOCUS: {
8519 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008521 synchronized(mWindowMap) {
8522 losers = mLosingFocus;
8523 mLosingFocus = new ArrayList<WindowState>();
8524 }
8525
8526 final int N = losers.size();
8527 for (int i=0; i<N; i++) {
8528 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008529 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8531 } catch (RemoteException e) {
8532 // Ignore if process has died.
8533 }
8534 }
8535 } break;
8536
8537 case ANIMATE: {
8538 synchronized(mWindowMap) {
8539 mAnimationPending = false;
8540 performLayoutAndPlaceSurfacesLocked();
8541 }
8542 } break;
8543
8544 case ADD_STARTING: {
8545 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8546 final StartingData sd = wtoken.startingData;
8547
8548 if (sd == null) {
8549 // Animation has been canceled... do nothing.
8550 return;
8551 }
Romain Guy06882f82009-06-10 13:36:04 -07008552
Joe Onorato8a9b2202010-02-26 18:56:32 -08008553 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008554 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 View view = null;
8557 try {
8558 view = mPolicy.addStartingWindow(
8559 wtoken.token, sd.pkg,
8560 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8561 sd.icon);
8562 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008563 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008564 }
8565
8566 if (view != null) {
8567 boolean abort = false;
8568
8569 synchronized(mWindowMap) {
8570 if (wtoken.removed || wtoken.startingData == null) {
8571 // If the window was successfully added, then
8572 // we need to remove it.
8573 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008574 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008575 "Aborted starting " + wtoken
8576 + ": removed=" + wtoken.removed
8577 + " startingData=" + wtoken.startingData);
8578 wtoken.startingWindow = null;
8579 wtoken.startingData = null;
8580 abort = true;
8581 }
8582 } else {
8583 wtoken.startingView = view;
8584 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008585 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 "Added starting " + wtoken
8587 + ": startingWindow="
8588 + wtoken.startingWindow + " startingView="
8589 + wtoken.startingView);
8590 }
8591
8592 if (abort) {
8593 try {
8594 mPolicy.removeStartingWindow(wtoken.token, view);
8595 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008596 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008597 }
8598 }
8599 }
8600 } break;
8601
8602 case REMOVE_STARTING: {
8603 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8604 IBinder token = null;
8605 View view = null;
8606 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008607 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008608 + wtoken + ": startingWindow="
8609 + wtoken.startingWindow + " startingView="
8610 + wtoken.startingView);
8611 if (wtoken.startingWindow != null) {
8612 view = wtoken.startingView;
8613 token = wtoken.token;
8614 wtoken.startingData = null;
8615 wtoken.startingView = null;
8616 wtoken.startingWindow = null;
8617 }
8618 }
8619 if (view != null) {
8620 try {
8621 mPolicy.removeStartingWindow(token, view);
8622 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008623 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008624 }
8625 }
8626 } break;
8627
8628 case FINISHED_STARTING: {
8629 IBinder token = null;
8630 View view = null;
8631 while (true) {
8632 synchronized (mWindowMap) {
8633 final int N = mFinishedStarting.size();
8634 if (N <= 0) {
8635 break;
8636 }
8637 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8638
Joe Onorato8a9b2202010-02-26 18:56:32 -08008639 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 "Finished starting " + wtoken
8641 + ": startingWindow=" + wtoken.startingWindow
8642 + " startingView=" + wtoken.startingView);
8643
8644 if (wtoken.startingWindow == null) {
8645 continue;
8646 }
8647
8648 view = wtoken.startingView;
8649 token = wtoken.token;
8650 wtoken.startingData = null;
8651 wtoken.startingView = null;
8652 wtoken.startingWindow = null;
8653 }
8654
8655 try {
8656 mPolicy.removeStartingWindow(token, view);
8657 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008658 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 }
8660 }
8661 } break;
8662
8663 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8664 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8665
8666 boolean nowVisible = msg.arg1 != 0;
8667 boolean nowGone = msg.arg2 != 0;
8668
8669 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008670 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671 TAG, "Reporting visible in " + wtoken
8672 + " visible=" + nowVisible
8673 + " gone=" + nowGone);
8674 if (nowVisible) {
8675 wtoken.appToken.windowsVisible();
8676 } else {
8677 wtoken.appToken.windowsGone();
8678 }
8679 } catch (RemoteException ex) {
8680 }
8681 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 case WINDOW_FREEZE_TIMEOUT: {
8684 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008685 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 int i = mWindows.size();
8687 while (i > 0) {
8688 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008689 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008690 if (w.mOrientationChanging) {
8691 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008692 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 }
8694 }
8695 performLayoutAndPlaceSurfacesLocked();
8696 }
8697 break;
8698 }
Romain Guy06882f82009-06-10 13:36:04 -07008699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008700 case HOLD_SCREEN_CHANGED: {
8701 Session oldHold;
8702 Session newHold;
8703 synchronized (mWindowMap) {
8704 oldHold = mLastReportedHold;
8705 newHold = (Session)msg.obj;
8706 mLastReportedHold = newHold;
8707 }
Romain Guy06882f82009-06-10 13:36:04 -07008708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008709 if (oldHold != newHold) {
8710 try {
8711 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008712 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008713 "window",
8714 BatteryStats.WAKE_TYPE_WINDOW);
8715 }
8716 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008717 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008718 "window",
8719 BatteryStats.WAKE_TYPE_WINDOW);
8720 }
8721 } catch (RemoteException e) {
8722 }
8723 }
8724 break;
8725 }
Romain Guy06882f82009-06-10 13:36:04 -07008726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008727 case APP_TRANSITION_TIMEOUT: {
8728 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008729 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008730 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008731 "*** APP TRANSITION TIMEOUT");
8732 mAppTransitionReady = true;
8733 mAppTransitionTimeout = true;
8734 performLayoutAndPlaceSurfacesLocked();
8735 }
8736 }
8737 break;
8738 }
Romain Guy06882f82009-06-10 13:36:04 -07008739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 case PERSIST_ANIMATION_SCALE: {
8741 Settings.System.putFloat(mContext.getContentResolver(),
8742 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8743 Settings.System.putFloat(mContext.getContentResolver(),
8744 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8745 break;
8746 }
Romain Guy06882f82009-06-10 13:36:04 -07008747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008748 case FORCE_GC: {
8749 synchronized(mWindowMap) {
8750 if (mAnimationPending) {
8751 // If we are animating, don't do the gc now but
8752 // delay a bit so we don't interrupt the animation.
8753 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8754 2000);
8755 return;
8756 }
8757 // If we are currently rotating the display, it will
8758 // schedule a new message when done.
8759 if (mDisplayFrozen) {
8760 return;
8761 }
8762 mFreezeGcPending = 0;
8763 }
8764 Runtime.getRuntime().gc();
8765 break;
8766 }
Romain Guy06882f82009-06-10 13:36:04 -07008767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768 case ENABLE_SCREEN: {
8769 performEnableScreen();
8770 break;
8771 }
Romain Guy06882f82009-06-10 13:36:04 -07008772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008773 case APP_FREEZE_TIMEOUT: {
8774 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008775 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008776 int i = mAppTokens.size();
8777 while (i > 0) {
8778 i--;
8779 AppWindowToken tok = mAppTokens.get(i);
8780 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008781 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008782 unsetAppFreezingScreenLocked(tok, true, true);
8783 }
8784 }
8785 }
8786 break;
8787 }
Romain Guy06882f82009-06-10 13:36:04 -07008788
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008789 case SEND_NEW_CONFIGURATION: {
8790 removeMessages(SEND_NEW_CONFIGURATION);
8791 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008792 break;
8793 }
Romain Guy06882f82009-06-10 13:36:04 -07008794
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008795 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008796 if (mWindowsChanged) {
8797 synchronized (mWindowMap) {
8798 mWindowsChanged = false;
8799 }
8800 notifyWindowsChanged();
8801 }
8802 break;
8803 }
8804
Christopher Tatea53146c2010-09-07 11:57:52 -07008805 case DRAG_START_TIMEOUT: {
8806 IBinder win = (IBinder)msg.obj;
8807 if (DEBUG_DRAG) {
8808 Slog.w(TAG, "Timeout starting drag by win " + win);
8809 }
8810 synchronized (mWindowMap) {
8811 // !!! TODO: ANR the app that has failed to start the drag in time
8812 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07008813 mDragState.unregister();
8814 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008815 mDragState.reset();
8816 mDragState = null;
8817 }
8818 }
Chris Tated4533f12010-10-19 15:15:08 -07008819 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008820 }
8821
Chris Tated4533f12010-10-19 15:15:08 -07008822 case DRAG_END_TIMEOUT: {
8823 IBinder win = (IBinder)msg.obj;
8824 if (DEBUG_DRAG) {
8825 Slog.w(TAG, "Timeout ending drag to win " + win);
8826 }
8827 synchronized (mWindowMap) {
8828 // !!! TODO: ANR the drag-receiving app
8829 mDragState.mDragResult = false;
8830 mDragState.endDragLw();
8831 }
8832 break;
8833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008834 }
8835 }
8836 }
8837
8838 // -------------------------------------------------------------
8839 // IWindowManager API
8840 // -------------------------------------------------------------
8841
8842 public IWindowSession openSession(IInputMethodClient client,
8843 IInputContext inputContext) {
8844 if (client == null) throw new IllegalArgumentException("null client");
8845 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008846 Session session = new Session(client, inputContext);
8847 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008848 }
8849
8850 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8851 synchronized (mWindowMap) {
8852 // The focus for the client is the window immediately below
8853 // where we would place the input method window.
8854 int idx = findDesiredInputMethodWindowIndexLocked(false);
8855 WindowState imFocus;
8856 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008857 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008858 if (imFocus != null) {
8859 if (imFocus.mSession.mClient != null &&
8860 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8861 return true;
8862 }
8863 }
8864 }
8865 }
8866 return false;
8867 }
Romain Guy06882f82009-06-10 13:36:04 -07008868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008869 // -------------------------------------------------------------
8870 // Internals
8871 // -------------------------------------------------------------
8872
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008873 final WindowState windowForClientLocked(Session session, IWindow client,
8874 boolean throwOnError) {
8875 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008876 }
Romain Guy06882f82009-06-10 13:36:04 -07008877
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008878 final WindowState windowForClientLocked(Session session, IBinder client,
8879 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008880 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008881 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008882 TAG, "Looking up client " + client + ": " + win);
8883 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008884 RuntimeException ex = new IllegalArgumentException(
8885 "Requested window " + client + " does not exist");
8886 if (throwOnError) {
8887 throw ex;
8888 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008889 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 return null;
8891 }
8892 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008893 RuntimeException ex = new IllegalArgumentException(
8894 "Requested window " + client + " is in session " +
8895 win.mSession + ", not " + session);
8896 if (throwOnError) {
8897 throw ex;
8898 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008899 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 return null;
8901 }
8902
8903 return win;
8904 }
8905
Dianne Hackborna8f60182009-09-01 19:01:50 -07008906 final void rebuildAppWindowListLocked() {
8907 int NW = mWindows.size();
8908 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008909 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008910 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008911
Dianne Hackborna8f60182009-09-01 19:01:50 -07008912 // First remove all existing app windows.
8913 i=0;
8914 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008915 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008916 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008917 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008918 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008919 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008920 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008921 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008922 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008923 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008924 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8925 && lastWallpaper == i-1) {
8926 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008927 }
8928 i++;
8929 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008930
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008931 // The wallpaper window(s) typically live at the bottom of the stack,
8932 // so skip them before adding app tokens.
8933 lastWallpaper++;
8934 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008935
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008936 // First add all of the exiting app tokens... these are no longer
8937 // in the main app list, but still have windows shown. We put them
8938 // in the back because now that the animation is over we no longer
8939 // will care about them.
8940 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008941 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008942 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8943 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008944
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008945 // And add in the still active app tokens in Z order.
8946 NT = mAppTokens.size();
8947 for (int j=0; j<NT; j++) {
8948 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008949 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008950
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008951 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008952 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008954 + " windows but added " + i);
8955 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008958 private final void assignLayersLocked() {
8959 int N = mWindows.size();
8960 int curBaseLayer = 0;
8961 int curLayer = 0;
8962 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008964 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008965 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008966 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8967 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008968 curLayer += WINDOW_LAYER_MULTIPLIER;
8969 w.mLayer = curLayer;
8970 } else {
8971 curBaseLayer = curLayer = w.mBaseLayer;
8972 w.mLayer = curLayer;
8973 }
8974 if (w.mTargetAppToken != null) {
8975 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8976 } else if (w.mAppToken != null) {
8977 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8978 } else {
8979 w.mAnimLayer = w.mLayer;
8980 }
8981 if (w.mIsImWindow) {
8982 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008983 } else if (w.mIsWallpaper) {
8984 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008985 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008986 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 + w.mAnimLayer);
8988 //System.out.println(
8989 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8990 }
8991 }
8992
8993 private boolean mInLayout = false;
8994 private final void performLayoutAndPlaceSurfacesLocked() {
8995 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008996 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 throw new RuntimeException("Recursive call!");
8998 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008999 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009000 return;
9001 }
9002
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009003 if (mWaitingForConfig) {
9004 // Our configuration has changed (most likely rotation), but we
9005 // don't yet have the complete configuration to report to
9006 // applications. Don't do any window layout until we have it.
9007 return;
9008 }
9009
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009010 if (mDisplay == null) {
9011 // Not yet initialized, nothing to do.
9012 return;
9013 }
9014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009015 boolean recoveringMemory = false;
9016 if (mForceRemoves != null) {
9017 recoveringMemory = true;
9018 // Wait a little it for things to settle down, and off we go.
9019 for (int i=0; i<mForceRemoves.size(); i++) {
9020 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009021 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009022 removeWindowInnerLocked(ws.mSession, ws);
9023 }
9024 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009025 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009026 Object tmp = new Object();
9027 synchronized (tmp) {
9028 try {
9029 tmp.wait(250);
9030 } catch (InterruptedException e) {
9031 }
9032 }
9033 }
Romain Guy06882f82009-06-10 13:36:04 -07009034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 mInLayout = true;
9036 try {
9037 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009039 int i = mPendingRemove.size()-1;
9040 if (i >= 0) {
9041 while (i >= 0) {
9042 WindowState w = mPendingRemove.get(i);
9043 removeWindowInnerLocked(w.mSession, w);
9044 i--;
9045 }
9046 mPendingRemove.clear();
9047
9048 mInLayout = false;
9049 assignLayersLocked();
9050 mLayoutNeeded = true;
9051 performLayoutAndPlaceSurfacesLocked();
9052
9053 } else {
9054 mInLayout = false;
9055 if (mLayoutNeeded) {
9056 requestAnimationLocked(0);
9057 }
9058 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009059 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009060 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9061 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009063 } catch (RuntimeException e) {
9064 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009065 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009066 }
9067 }
9068
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009069 private final int performLayoutLockedInner() {
9070 if (!mLayoutNeeded) {
9071 return 0;
9072 }
9073
9074 mLayoutNeeded = false;
9075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009076 final int dw = mDisplay.getWidth();
9077 final int dh = mDisplay.getHeight();
9078
9079 final int N = mWindows.size();
9080 int i;
9081
Joe Onorato8a9b2202010-02-26 18:56:32 -08009082 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009083 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9084
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009085 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009086
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009087 int seq = mLayoutSeq+1;
9088 if (seq < 0) seq = 0;
9089 mLayoutSeq = seq;
9090
9091 // First perform layout of any root windows (not attached
9092 // to another window).
9093 int topAttached = -1;
9094 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009095 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009096
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009097 // Don't do layout of a window if it is not visible, or
9098 // soon won't be visible, to avoid wasting time and funky
9099 // changes while a window is animating away.
9100 final AppWindowToken atoken = win.mAppToken;
9101 final boolean gone = win.mViewVisibility == View.GONE
9102 || !win.mRelayoutCalled
9103 || win.mRootToken.hidden
9104 || (atoken != null && atoken.hiddenRequested)
9105 || win.mAttachedHidden
9106 || win.mExiting || win.mDestroying;
9107
9108 if (!win.mLayoutAttached) {
9109 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9110 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9111 + " mLayoutAttached=" + win.mLayoutAttached);
9112 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9113 + win.mViewVisibility + " mRelayoutCalled="
9114 + win.mRelayoutCalled + " hidden="
9115 + win.mRootToken.hidden + " hiddenRequested="
9116 + (atoken != null && atoken.hiddenRequested)
9117 + " mAttachedHidden=" + win.mAttachedHidden);
9118 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009119
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009120 // If this view is GONE, then skip it -- keep the current
9121 // frame, and let the caller know so they can ignore it
9122 // if they want. (We do the normal layout for INVISIBLE
9123 // windows, since that means "perform layout as normal,
9124 // just don't display").
9125 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009126 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009127 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9128 win.mLayoutSeq = seq;
9129 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9130 + win.mFrame + " mContainingFrame="
9131 + win.mContainingFrame + " mDisplayFrame="
9132 + win.mDisplayFrame);
9133 } else {
9134 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009135 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009137 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009138
9139 // Now perform layout of attached windows, which usually
9140 // depend on the position of the window they are attached to.
9141 // XXX does not deal with windows that are attached to windows
9142 // that are themselves attached.
9143 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009144 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009145
9146 // If this view is GONE, then skip it -- keep the current
9147 // frame, and let the caller know so they can ignore it
9148 // if they want. (We do the normal layout for INVISIBLE
9149 // windows, since that means "perform layout as normal,
9150 // just don't display").
9151 if (win.mLayoutAttached) {
9152 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9153 + " mHaveFrame=" + win.mHaveFrame
9154 + " mViewVisibility=" + win.mViewVisibility
9155 + " mRelayoutCalled=" + win.mRelayoutCalled);
9156 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9157 || !win.mHaveFrame) {
9158 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9159 win.mLayoutSeq = seq;
9160 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9161 + win.mFrame + " mContainingFrame="
9162 + win.mContainingFrame + " mDisplayFrame="
9163 + win.mDisplayFrame);
9164 }
9165 }
9166 }
Jeff Brown349703e2010-06-22 01:27:15 -07009167
9168 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009169 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009170
9171 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009172 }
Romain Guy06882f82009-06-10 13:36:04 -07009173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 private final void performLayoutAndPlaceSurfacesLockedInner(
9175 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009176 if (mDisplay == null) {
9177 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9178 return;
9179 }
9180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009181 final long currentTime = SystemClock.uptimeMillis();
9182 final int dw = mDisplay.getWidth();
9183 final int dh = mDisplay.getHeight();
9184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009185 int i;
9186
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009187 if (mFocusMayChange) {
9188 mFocusMayChange = false;
9189 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9190 }
9191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009192 // Initialize state of exiting tokens.
9193 for (i=mExitingTokens.size()-1; i>=0; i--) {
9194 mExitingTokens.get(i).hasVisible = false;
9195 }
9196
9197 // Initialize state of exiting applications.
9198 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9199 mExitingAppTokens.get(i).hasVisible = false;
9200 }
9201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009202 boolean orientationChangeComplete = true;
9203 Session holdScreen = null;
9204 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009205 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009206 boolean focusDisplayed = false;
9207 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009208 boolean createWatermark = false;
9209
9210 if (mFxSession == null) {
9211 mFxSession = new SurfaceSession();
9212 createWatermark = true;
9213 }
9214
9215 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009216
9217 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009218
9219 if (createWatermark) {
9220 createWatermark();
9221 }
9222 if (mWatermark != null) {
9223 mWatermark.positionSurface(dw, dh);
9224 }
9225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009227 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009228 int repeats = 0;
9229 int changes = 0;
9230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009231 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009232 repeats++;
9233 if (repeats > 6) {
9234 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9235 mLayoutNeeded = false;
9236 break;
9237 }
9238
9239 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9240 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9241 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9242 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9243 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9244 assignLayersLocked();
9245 mLayoutNeeded = true;
9246 }
9247 }
9248 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9249 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9250 if (updateOrientationFromAppTokensLocked()) {
9251 mLayoutNeeded = true;
9252 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9253 }
9254 }
9255 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9256 mLayoutNeeded = true;
9257 }
9258 }
9259
9260 // FIRST LOOP: Perform a layout, if needed.
9261 if (repeats < 4) {
9262 changes = performLayoutLockedInner();
9263 if (changes != 0) {
9264 continue;
9265 }
9266 } else {
9267 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9268 changes = 0;
9269 }
9270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009271 final int transactionSequence = ++mTransactionSequence;
9272
9273 // Update animations of all applications, including those
9274 // associated with exiting/removed apps
9275 boolean tokensAnimating = false;
9276 final int NAT = mAppTokens.size();
9277 for (i=0; i<NAT; i++) {
9278 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9279 tokensAnimating = true;
9280 }
9281 }
9282 final int NEAT = mExitingAppTokens.size();
9283 for (i=0; i<NEAT; i++) {
9284 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9285 tokensAnimating = true;
9286 }
9287 }
9288
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009289 // SECOND LOOP: Execute animations and update visibility of windows.
9290
Joe Onorato8a9b2202010-02-26 18:56:32 -08009291 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009292 + transactionSequence + " tokensAnimating="
9293 + tokensAnimating);
9294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009296
9297 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009298 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009299 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009300
9301 mPolicy.beginAnimationLw(dw, dh);
9302
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009303 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009305 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009306 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009307
9308 final WindowManager.LayoutParams attrs = w.mAttrs;
9309
9310 if (w.mSurface != null) {
9311 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009312 if (w.commitFinishDrawingLocked(currentTime)) {
9313 if ((w.mAttrs.flags
9314 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009315 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009316 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009317 wallpaperMayChange = true;
9318 }
9319 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009320
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009321 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9323 animating = true;
9324 //w.dump(" ");
9325 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009326 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9327 wallpaperMayChange = true;
9328 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009329
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009330 if (mPolicy.doesForceHide(w, attrs)) {
9331 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009332 if (DEBUG_VISIBILITY) Slog.v(TAG,
9333 "Animation done that could impact force hide: "
9334 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009335 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009336 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009337 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9338 forceHiding = true;
9339 }
9340 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9341 boolean changed;
9342 if (forceHiding) {
9343 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009344 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9345 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009346 } else {
9347 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009348 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9349 "Now policy shown: " + w);
9350 if (changed) {
9351 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009352 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009353 // Assume we will need to animate. If
9354 // we don't (because the wallpaper will
9355 // stay with the lock screen), then we will
9356 // clean up later.
9357 Animation a = mPolicy.createForceHideEnterAnimation();
9358 if (a != null) {
9359 w.setAnimation(a);
9360 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009361 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009362 if (mCurrentFocus == null ||
9363 mCurrentFocus.mLayer < w.mLayer) {
9364 // We are showing on to of the current
9365 // focus, so re-evaluate focus to make
9366 // sure it is correct.
9367 mFocusMayChange = true;
9368 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009369 }
9370 }
9371 if (changed && (attrs.flags
9372 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9373 wallpaperMayChange = true;
9374 }
9375 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009377 mPolicy.animatingWindowLw(w, attrs);
9378 }
9379
9380 final AppWindowToken atoken = w.mAppToken;
9381 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9382 if (atoken.lastTransactionSequence != transactionSequence) {
9383 atoken.lastTransactionSequence = transactionSequence;
9384 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9385 atoken.startingDisplayed = false;
9386 }
9387 if ((w.isOnScreen() || w.mAttrs.type
9388 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9389 && !w.mExiting && !w.mDestroying) {
9390 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009391 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009392 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009394 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009395 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009396 + " pv=" + w.mPolicyVisibility
9397 + " dp=" + w.mDrawPending
9398 + " cdp=" + w.mCommitDrawPending
9399 + " ah=" + w.mAttachedHidden
9400 + " th=" + atoken.hiddenRequested
9401 + " a=" + w.mAnimating);
9402 }
9403 }
9404 if (w != atoken.startingWindow) {
9405 if (!atoken.freezingScreen || !w.mAppFreezing) {
9406 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009407 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009408 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009409 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 "tokenMayBeDrawn: " + atoken
9411 + " freezingScreen=" + atoken.freezingScreen
9412 + " mAppFreezing=" + w.mAppFreezing);
9413 tokenMayBeDrawn = true;
9414 }
9415 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009416 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 atoken.startingDisplayed = true;
9418 }
9419 }
9420 } else if (w.mReadyToShow) {
9421 w.performShowLocked();
9422 }
9423 }
9424
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009425 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426
9427 if (tokenMayBeDrawn) {
9428 // See if any windows have been drawn, so they (and others
9429 // associated with them) can now be shown.
9430 final int NT = mTokenList.size();
9431 for (i=0; i<NT; i++) {
9432 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9433 if (wtoken == null) {
9434 continue;
9435 }
9436 if (wtoken.freezingScreen) {
9437 int numInteresting = wtoken.numInterestingWindows;
9438 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009439 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009440 "allDrawn: " + wtoken
9441 + " interesting=" + numInteresting
9442 + " drawn=" + wtoken.numDrawnWindows);
9443 wtoken.showAllWindowsLocked();
9444 unsetAppFreezingScreenLocked(wtoken, false, true);
9445 orientationChangeComplete = true;
9446 }
9447 } else if (!wtoken.allDrawn) {
9448 int numInteresting = wtoken.numInterestingWindows;
9449 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009450 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009451 "allDrawn: " + wtoken
9452 + " interesting=" + numInteresting
9453 + " drawn=" + wtoken.numDrawnWindows);
9454 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009455 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009456
9457 // We can now show all of the drawn windows!
9458 if (!mOpeningApps.contains(wtoken)) {
9459 wtoken.showAllWindowsLocked();
9460 }
9461 }
9462 }
9463 }
9464 }
9465
9466 // If we are ready to perform an app transition, check through
9467 // all of the app tokens to be shown and see if they are ready
9468 // to go.
9469 if (mAppTransitionReady) {
9470 int NN = mOpeningApps.size();
9471 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009472 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009473 "Checking " + NN + " opening apps (frozen="
9474 + mDisplayFrozen + " timeout="
9475 + mAppTransitionTimeout + ")...");
9476 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9477 // If the display isn't frozen, wait to do anything until
9478 // all of the apps are ready. Otherwise just go because
9479 // we'll unfreeze the display when everyone is ready.
9480 for (i=0; i<NN && goodToGo; i++) {
9481 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009482 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009483 "Check opening app" + wtoken + ": allDrawn="
9484 + wtoken.allDrawn + " startingDisplayed="
9485 + wtoken.startingDisplayed);
9486 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9487 && !wtoken.startingMoved) {
9488 goodToGo = false;
9489 }
9490 }
9491 }
9492 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009493 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494 int transit = mNextAppTransition;
9495 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009496 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009498 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009500 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009501 mAppTransitionTimeout = false;
9502 mStartingIconInTransition = false;
9503 mSkipAppTransitionAnimation = false;
9504
9505 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9506
Dianne Hackborna8f60182009-09-01 19:01:50 -07009507 // If there are applications waiting to come to the
9508 // top of the stack, now is the time to move their windows.
9509 // (Note that we don't do apps going to the bottom
9510 // here -- we want to keep their windows in the old
9511 // Z-order until the animation completes.)
9512 if (mToTopApps.size() > 0) {
9513 NN = mAppTokens.size();
9514 for (i=0; i<NN; i++) {
9515 AppWindowToken wtoken = mAppTokens.get(i);
9516 if (wtoken.sendingToTop) {
9517 wtoken.sendingToTop = false;
9518 moveAppWindowsLocked(wtoken, NN, false);
9519 }
9520 }
9521 mToTopApps.clear();
9522 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009523
Dianne Hackborn25994b42009-09-04 14:21:19 -07009524 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009525
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009526 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009527 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009528
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009529 // The top-most window will supply the layout params,
9530 // and we will determine it below.
9531 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009532 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009533 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009534
Joe Onorato8a9b2202010-02-26 18:56:32 -08009535 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009536 "New wallpaper target=" + mWallpaperTarget
9537 + ", lower target=" + mLowerWallpaperTarget
9538 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009539 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009540 // Do a first pass through the tokens for two
9541 // things:
9542 // (1) Determine if both the closing and opening
9543 // app token sets are wallpaper targets, in which
9544 // case special animations are needed
9545 // (since the wallpaper needs to stay static
9546 // behind them).
9547 // (2) Find the layout params of the top-most
9548 // application window in the tokens, which is
9549 // what will control the animation theme.
9550 final int NC = mClosingApps.size();
9551 NN = NC + mOpeningApps.size();
9552 for (i=0; i<NN; i++) {
9553 AppWindowToken wtoken;
9554 int mode;
9555 if (i < NC) {
9556 wtoken = mClosingApps.get(i);
9557 mode = 1;
9558 } else {
9559 wtoken = mOpeningApps.get(i-NC);
9560 mode = 2;
9561 }
9562 if (mLowerWallpaperTarget != null) {
9563 if (mLowerWallpaperTarget.mAppToken == wtoken
9564 || mUpperWallpaperTarget.mAppToken == wtoken) {
9565 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009566 }
9567 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009568 if (wtoken.appFullscreen) {
9569 WindowState ws = wtoken.findMainWindow();
9570 if (ws != null) {
9571 // If this is a compatibility mode
9572 // window, we will always use its anim.
9573 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9574 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009575 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009576 bestAnimLayer = Integer.MAX_VALUE;
9577 } else if (ws.mLayer > bestAnimLayer) {
9578 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009579 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009580 bestAnimLayer = ws.mLayer;
9581 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009582 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009583 }
9584 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009585
Dianne Hackborn25994b42009-09-04 14:21:19 -07009586 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009587 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009588 "Wallpaper animation!");
9589 switch (transit) {
9590 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9591 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9592 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9593 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9594 break;
9595 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9596 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9597 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9598 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9599 break;
9600 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009601 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009602 "New transit: " + transit);
9603 } else if (oldWallpaper != null) {
9604 // We are transitioning from an activity with
9605 // a wallpaper to one without.
9606 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009607 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009608 "New transit away from wallpaper: " + transit);
9609 } else if (mWallpaperTarget != null) {
9610 // We are transitioning from an activity without
9611 // a wallpaper to now showing the wallpaper
9612 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009613 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009614 "New transit into wallpaper: " + transit);
9615 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009616
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009617 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9618 mLastEnterAnimToken = animToken;
9619 mLastEnterAnimParams = animLp;
9620 } else if (mLastEnterAnimParams != null) {
9621 animLp = mLastEnterAnimParams;
9622 mLastEnterAnimToken = null;
9623 mLastEnterAnimParams = null;
9624 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009625
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009626 // If all closing windows are obscured, then there is
9627 // no need to do an animation. This is the case, for
9628 // example, when this transition is being done behind
9629 // the lock screen.
9630 if (!mPolicy.allowAppAnimationsLw()) {
9631 animLp = null;
9632 }
9633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009634 NN = mOpeningApps.size();
9635 for (i=0; i<NN; i++) {
9636 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009637 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009638 "Now opening app" + wtoken);
9639 wtoken.reportedVisible = false;
9640 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009641 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009642 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009643 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009644 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009645 wtoken.showAllWindowsLocked();
9646 }
9647 NN = mClosingApps.size();
9648 for (i=0; i<NN; i++) {
9649 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009650 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651 "Now closing app" + wtoken);
9652 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009653 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009654 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009655 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009656 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009657 // Force the allDrawn flag, because we want to start
9658 // this guy's animations regardless of whether it's
9659 // gotten drawn.
9660 wtoken.allDrawn = true;
9661 }
9662
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009663 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009665 mOpeningApps.clear();
9666 mClosingApps.clear();
9667
9668 // This has changed the visibility of windows, so perform
9669 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009670 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009671 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009672 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9673 assignLayersLocked();
9674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009675 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009676 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009677 }
9678 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009679
Dianne Hackborn16064f92010-03-25 00:47:24 -07009680 int adjResult = 0;
9681
Dianne Hackborna8f60182009-09-01 19:01:50 -07009682 if (!animating && mAppTransitionRunning) {
9683 // We have finished the animation of an app transition. To do
9684 // this, we have delayed a lot of operations like showing and
9685 // hiding apps, moving apps in Z-order, etc. The app token list
9686 // reflects the correct Z-order, but the window list may now
9687 // be out of sync with it. So here we will just rebuild the
9688 // entire app window list. Fun!
9689 mAppTransitionRunning = false;
9690 // Clear information about apps that were moving.
9691 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009692
Dianne Hackborna8f60182009-09-01 19:01:50 -07009693 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009694 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009695 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009696 moveInputMethodWindowsIfNeededLocked(false);
9697 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009698 // Since the window list has been rebuilt, focus might
9699 // have to be recomputed since the actual order of windows
9700 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009701 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009702 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009703
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009704 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009705 // At this point, there was a window with a wallpaper that
9706 // was force hiding other windows behind it, but now it
9707 // is going away. This may be simple -- just animate
9708 // away the wallpaper and its window -- or it may be
9709 // hard -- the wallpaper now needs to be shown behind
9710 // something that was hidden.
9711 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009712 if (mLowerWallpaperTarget != null
9713 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009714 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009715 "wallpaperForceHiding changed with lower="
9716 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009717 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009718 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9719 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9720 if (mLowerWallpaperTarget.mAppToken.hidden) {
9721 // The lower target has become hidden before we
9722 // actually started the animation... let's completely
9723 // re-evaluate everything.
9724 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009725 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009726 }
9727 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009728 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009729 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009730 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009731 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009732 + " NEW: " + mWallpaperTarget
9733 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009734 if (mLowerWallpaperTarget == null) {
9735 // Whoops, we don't need a special wallpaper animation.
9736 // Clear them out.
9737 forceHiding = false;
9738 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009739 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009740 if (w.mSurface != null) {
9741 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009742 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009743 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009744 forceHiding = true;
9745 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9746 if (!w.mAnimating) {
9747 // We set the animation above so it
9748 // is not yet running.
9749 w.clearAnimation();
9750 }
9751 }
9752 }
9753 }
9754 }
9755 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009756
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009757 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009758 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009759 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009760 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009761 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009762
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009763 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009764 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009765 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009766 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009767 assignLayersLocked();
9768 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009769 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009770 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009771 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009772 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009773
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009774 if (mFocusMayChange) {
9775 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009776 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009777 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009778 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009779 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009780 }
9781
9782 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009783 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009784 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009785
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009786 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9787 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009788
Jeff Browne33348b2010-07-15 23:54:05 -07009789 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009790 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791
9792 // THIRD LOOP: Update the surfaces of all windows.
9793
9794 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9795
9796 boolean obscured = false;
9797 boolean blurring = false;
9798 boolean dimming = false;
9799 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009800 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009801 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009802
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009803 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009806 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009807
9808 boolean displayed = false;
9809 final WindowManager.LayoutParams attrs = w.mAttrs;
9810 final int attrFlags = attrs.flags;
9811
9812 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009813 // XXX NOTE: The logic here could be improved. We have
9814 // the decision about whether to resize a window separated
9815 // from whether to hide the surface. This can cause us to
9816 // resize a surface even if we are going to hide it. You
9817 // can see this by (1) holding device in landscape mode on
9818 // home screen; (2) tapping browser icon (device will rotate
9819 // to landscape; (3) tap home. The wallpaper will be resized
9820 // in step 2 but then immediately hidden, causing us to
9821 // have to resize and then redraw it again in step 3. It
9822 // would be nice to figure out how to avoid this, but it is
9823 // difficult because we do need to resize surfaces in some
9824 // cases while they are hidden such as when first showing a
9825 // window.
9826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009828 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 TAG, "Placing surface #" + i + " " + w.mSurface
9830 + ": new=" + w.mShownFrame + ", old="
9831 + w.mLastShownFrame);
9832
9833 boolean resize;
9834 int width, height;
9835 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9836 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9837 w.mLastRequestedHeight != w.mRequestedHeight;
9838 // for a scaled surface, we just want to use
9839 // the requested size.
9840 width = w.mRequestedWidth;
9841 height = w.mRequestedHeight;
9842 w.mLastRequestedWidth = width;
9843 w.mLastRequestedHeight = height;
9844 w.mLastShownFrame.set(w.mShownFrame);
9845 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009846 if (SHOW_TRANSACTIONS) logSurface(w,
9847 "POS " + w.mShownFrame.left
9848 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009849 w.mSurfaceX = w.mShownFrame.left;
9850 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9852 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009853 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009854 if (!recoveringMemory) {
9855 reclaimSomeSurfaceMemoryLocked(w, "position");
9856 }
9857 }
9858 } else {
9859 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9860 width = w.mShownFrame.width();
9861 height = w.mShownFrame.height();
9862 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009863 }
9864
9865 if (resize) {
9866 if (width < 1) width = 1;
9867 if (height < 1) height = 1;
9868 if (w.mSurface != null) {
9869 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009870 if (SHOW_TRANSACTIONS) logSurface(w,
9871 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009872 + w.mShownFrame.top + " SIZE "
9873 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009874 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009875 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009876 w.mSurfaceW = width;
9877 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009878 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009879 w.mSurfaceX = w.mShownFrame.left;
9880 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009881 w.mSurface.setPosition(w.mShownFrame.left,
9882 w.mShownFrame.top);
9883 } catch (RuntimeException e) {
9884 // If something goes wrong with the surface (such
9885 // as running out of memory), don't take down the
9886 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009887 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009888 + "size=(" + width + "x" + height
9889 + "), pos=(" + w.mShownFrame.left
9890 + "," + w.mShownFrame.top + ")", e);
9891 if (!recoveringMemory) {
9892 reclaimSomeSurfaceMemoryLocked(w, "size");
9893 }
9894 }
9895 }
9896 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009897 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009898 w.mContentInsetsChanged =
9899 !w.mLastContentInsets.equals(w.mContentInsets);
9900 w.mVisibleInsetsChanged =
9901 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009902 boolean configChanged =
9903 w.mConfiguration != mCurConfiguration
9904 && (w.mConfiguration == null
9905 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009906 if (DEBUG_CONFIGURATION && configChanged) {
9907 Slog.v(TAG, "Win " + w + " config changed: "
9908 + mCurConfiguration);
9909 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009910 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009911 + ": configChanged=" + configChanged
9912 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009913 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009914 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009915 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009916 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009917 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009918 w.mLastFrame.set(w.mFrame);
9919 w.mLastContentInsets.set(w.mContentInsets);
9920 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009921 // If the screen is currently frozen, then keep
9922 // it frozen until this window draws at its new
9923 // orientation.
9924 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009925 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009926 "Resizing while display frozen: " + w);
9927 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009928 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009929 mWindowsFreezingScreen = true;
9930 // XXX should probably keep timeout from
9931 // when we first froze the display.
9932 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9933 mH.sendMessageDelayed(mH.obtainMessage(
9934 H.WINDOW_FREEZE_TIMEOUT), 2000);
9935 }
9936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937 // If the orientation is changing, then we need to
9938 // hold off on unfreezing the display until this
9939 // window has been redrawn; to do that, we need
9940 // to go through the process of getting informed
9941 // by the application when it has finished drawing.
9942 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009943 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944 "Orientation start waiting for draw in "
9945 + w + ", surface " + w.mSurface);
9946 w.mDrawPending = true;
9947 w.mCommitDrawPending = false;
9948 w.mReadyToShow = false;
9949 if (w.mAppToken != null) {
9950 w.mAppToken.allDrawn = false;
9951 }
9952 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009953 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009954 "Resizing window " + w + " to " + w.mFrame);
9955 mResizingWindows.add(w);
9956 } else if (w.mOrientationChanging) {
9957 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009958 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009959 "Orientation not waiting for draw in "
9960 + w + ", surface " + w.mSurface);
9961 w.mOrientationChanging = false;
9962 }
9963 }
9964 }
9965
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009966 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009967 if (!w.mLastHidden) {
9968 //dump();
9969 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009970 if (SHOW_TRANSACTIONS) logSurface(w,
9971 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009972 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009973 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009974 try {
9975 w.mSurface.hide();
9976 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009977 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009978 }
9979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009980 }
9981 // If we are waiting for this window to handle an
9982 // orientation change, well, it is hidden, so
9983 // doesn't really matter. Note that this does
9984 // introduce a potential glitch if the window
9985 // becomes unhidden before it has drawn for the
9986 // new orientation.
9987 if (w.mOrientationChanging) {
9988 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009989 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009990 "Orientation change skips hidden " + w);
9991 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 } else if (w.mLastLayer != w.mAnimLayer
9993 || w.mLastAlpha != w.mShownAlpha
9994 || w.mLastDsDx != w.mDsDx
9995 || w.mLastDtDx != w.mDtDx
9996 || w.mLastDsDy != w.mDsDy
9997 || w.mLastDtDy != w.mDtDy
9998 || w.mLastHScale != w.mHScale
9999 || w.mLastVScale != w.mVScale
10000 || w.mLastHidden) {
10001 displayed = true;
10002 w.mLastAlpha = w.mShownAlpha;
10003 w.mLastLayer = w.mAnimLayer;
10004 w.mLastDsDx = w.mDsDx;
10005 w.mLastDtDx = w.mDtDx;
10006 w.mLastDsDy = w.mDsDy;
10007 w.mLastDtDy = w.mDtDy;
10008 w.mLastHScale = w.mHScale;
10009 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010010 if (SHOW_TRANSACTIONS) logSurface(w,
10011 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010012 + " matrix=[" + (w.mDsDx*w.mHScale)
10013 + "," + (w.mDtDx*w.mVScale)
10014 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010015 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010016 if (w.mSurface != null) {
10017 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010018 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010019 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010020 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 w.mSurface.setLayer(w.mAnimLayer);
10022 w.mSurface.setMatrix(
10023 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10024 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10025 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010026 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010027 if (!recoveringMemory) {
10028 reclaimSomeSurfaceMemoryLocked(w, "update");
10029 }
10030 }
10031 }
10032
10033 if (w.mLastHidden && !w.mDrawPending
10034 && !w.mCommitDrawPending
10035 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010036 if (SHOW_TRANSACTIONS) logSurface(w,
10037 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010038 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010039 + " during relayout");
10040 if (showSurfaceRobustlyLocked(w)) {
10041 w.mHasDrawn = true;
10042 w.mLastHidden = false;
10043 } else {
10044 w.mOrientationChanging = false;
10045 }
10046 }
10047 if (w.mSurface != null) {
10048 w.mToken.hasVisible = true;
10049 }
10050 } else {
10051 displayed = true;
10052 }
10053
10054 if (displayed) {
10055 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010056 if (attrs.width == LayoutParams.MATCH_PARENT
10057 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058 covered = true;
10059 }
10060 }
10061 if (w.mOrientationChanging) {
10062 if (w.mDrawPending || w.mCommitDrawPending) {
10063 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010064 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010065 "Orientation continue waiting for draw in " + w);
10066 } else {
10067 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010068 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 "Orientation change complete in " + w);
10070 }
10071 }
10072 w.mToken.hasVisible = true;
10073 }
10074 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010075 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010076 "Orientation change skips hidden " + w);
10077 w.mOrientationChanging = false;
10078 }
10079
10080 final boolean canBeSeen = w.isDisplayedLw();
10081
10082 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10083 focusDisplayed = true;
10084 }
10085
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010086 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010088 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010089 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010090 if (w.mSurface != null) {
10091 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10092 holdScreen = w.mSession;
10093 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010094 if (!syswin && w.mAttrs.screenBrightness >= 0
10095 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010096 screenBrightness = w.mAttrs.screenBrightness;
10097 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010098 if (!syswin && w.mAttrs.buttonBrightness >= 0
10099 && buttonBrightness < 0) {
10100 buttonBrightness = w.mAttrs.buttonBrightness;
10101 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010102 if (canBeSeen
10103 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10104 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10105 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010106 syswin = true;
10107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010108 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010109
Dianne Hackborn25994b42009-09-04 14:21:19 -070010110 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10111 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 // This window completely covers everything behind it,
10113 // so we want to leave all of them as unblurred (for
10114 // performance reasons).
10115 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010116 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010117 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010118 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010119 obscured = true;
10120 if (mBackgroundFillerSurface == null) {
10121 try {
10122 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010123 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010124 0, dw, dh,
10125 PixelFormat.OPAQUE,
10126 Surface.FX_SURFACE_NORMAL);
10127 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010128 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010129 }
10130 }
10131 try {
10132 mBackgroundFillerSurface.setPosition(0, 0);
10133 mBackgroundFillerSurface.setSize(dw, dh);
10134 // Using the same layer as Dim because they will never be shown at the
10135 // same time.
10136 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10137 mBackgroundFillerSurface.show();
10138 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010139 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010140 }
10141 backgroundFillerShown = true;
10142 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010143 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010145 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010146 + ": blurring=" + blurring
10147 + " obscured=" + obscured
10148 + " displayed=" + displayed);
10149 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10150 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010151 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010152 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010153 if (mDimAnimator == null) {
10154 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010155 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010156 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010157 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010159 }
10160 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10161 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010162 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010163 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010164 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010165 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 + mBlurSurface + ": CREATE");
10167 try {
Romain Guy06882f82009-06-10 13:36:04 -070010168 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010169 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010170 -1, 16, 16,
10171 PixelFormat.OPAQUE,
10172 Surface.FX_SURFACE_BLUR);
10173 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010174 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010175 }
10176 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010177 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010178 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10179 + mBlurSurface + ": pos=(0,0) (" +
10180 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010181 mBlurSurface.setPosition(0, 0);
10182 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010183 mBlurSurface.setLayer(w.mAnimLayer-2);
10184 if (!mBlurShown) {
10185 try {
10186 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10187 + mBlurSurface + ": SHOW");
10188 mBlurSurface.show();
10189 } catch (RuntimeException e) {
10190 Slog.w(TAG, "Failure showing blur surface", e);
10191 }
10192 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010193 }
10194 }
10195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010196 }
10197 }
10198 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010199
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010200 if (obscuredChanged && mWallpaperTarget == w) {
10201 // This is the wallpaper target and its obscured state
10202 // changed... make sure the current wallaper's visibility
10203 // has been updated accordingly.
10204 updateWallpaperVisibilityLocked();
10205 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010206 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010207
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010208 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10209 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010210 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010211 try {
10212 mBackgroundFillerSurface.hide();
10213 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010214 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010215 }
10216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010217
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010218 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010219 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10220 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010221 }
Romain Guy06882f82009-06-10 13:36:04 -070010222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010223 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010224 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010225 + ": HIDE");
10226 try {
10227 mBlurSurface.hide();
10228 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010229 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010230 }
10231 mBlurShown = false;
10232 }
10233
Joe Onorato8a9b2202010-02-26 18:56:32 -080010234 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010236 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010237 }
10238
Jeff Browne33348b2010-07-15 23:54:05 -070010239 mInputMonitor.updateInputWindowsLw();
10240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010241 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010242
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010243 if (mWatermark != null) {
10244 mWatermark.drawIfNeeded();
10245 }
10246
Joe Onorato8a9b2202010-02-26 18:56:32 -080010247 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010248 "With display frozen, orientationChangeComplete="
10249 + orientationChangeComplete);
10250 if (orientationChangeComplete) {
10251 if (mWindowsFreezingScreen) {
10252 mWindowsFreezingScreen = false;
10253 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10254 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010255 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010256 }
Romain Guy06882f82009-06-10 13:36:04 -070010257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010258 i = mResizingWindows.size();
10259 if (i > 0) {
10260 do {
10261 i--;
10262 WindowState win = mResizingWindows.get(i);
10263 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010264 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10265 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010266 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010267 boolean configChanged =
10268 win.mConfiguration != mCurConfiguration
10269 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010270 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10271 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10272 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010273 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010274 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010275 + " / " + mCurConfiguration + " / 0x"
10276 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010277 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010278 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010279 win.mClient.resized(win.mFrame.width(),
10280 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010281 win.mLastVisibleInsets, win.mDrawPending,
10282 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283 win.mContentInsetsChanged = false;
10284 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010285 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 } catch (RemoteException e) {
10287 win.mOrientationChanging = false;
10288 }
10289 } while (i > 0);
10290 mResizingWindows.clear();
10291 }
Romain Guy06882f82009-06-10 13:36:04 -070010292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010294 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010295 i = mDestroySurface.size();
10296 if (i > 0) {
10297 do {
10298 i--;
10299 WindowState win = mDestroySurface.get(i);
10300 win.mDestroying = false;
10301 if (mInputMethodWindow == win) {
10302 mInputMethodWindow = null;
10303 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010304 if (win == mWallpaperTarget) {
10305 wallpaperDestroyed = true;
10306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 win.destroySurfaceLocked();
10308 } while (i > 0);
10309 mDestroySurface.clear();
10310 }
10311
10312 // Time to remove any exiting tokens?
10313 for (i=mExitingTokens.size()-1; i>=0; i--) {
10314 WindowToken token = mExitingTokens.get(i);
10315 if (!token.hasVisible) {
10316 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010317 if (token.windowType == TYPE_WALLPAPER) {
10318 mWallpaperTokens.remove(token);
10319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010320 }
10321 }
10322
10323 // Time to remove any exiting applications?
10324 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10325 AppWindowToken token = mExitingAppTokens.get(i);
10326 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010327 // Make sure there is no animation running on this token,
10328 // so any windows associated with it will be removed as
10329 // soon as their animations are complete
10330 token.animation = null;
10331 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010332 mAppTokens.remove(token);
10333 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010334 if (mLastEnterAnimToken == token) {
10335 mLastEnterAnimToken = null;
10336 mLastEnterAnimParams = null;
10337 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010338 }
10339 }
10340
Dianne Hackborna8f60182009-09-01 19:01:50 -070010341 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010342
Dianne Hackborna8f60182009-09-01 19:01:50 -070010343 if (!animating && mAppTransitionRunning) {
10344 // We have finished the animation of an app transition. To do
10345 // this, we have delayed a lot of operations like showing and
10346 // hiding apps, moving apps in Z-order, etc. The app token list
10347 // reflects the correct Z-order, but the window list may now
10348 // be out of sync with it. So here we will just rebuild the
10349 // entire app window list. Fun!
10350 mAppTransitionRunning = false;
10351 needRelayout = true;
10352 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010353 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010354 // Clear information about apps that were moving.
10355 mToBottomApps.clear();
10356 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010358 if (focusDisplayed) {
10359 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10360 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010361 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010362 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010363 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010364 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010365 requestAnimationLocked(0);
10366 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010367 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10368 }
Jeff Browneb857f12010-07-16 10:06:33 -070010369
Jeff Browne33348b2010-07-15 23:54:05 -070010370 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010371
Jeff Brown8e03b752010-06-13 19:16:55 -070010372 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10374 mPowerManager.setScreenBrightnessOverride(-1);
10375 } else {
10376 mPowerManager.setScreenBrightnessOverride((int)
10377 (screenBrightness * Power.BRIGHTNESS_ON));
10378 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010379 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10380 mPowerManager.setButtonBrightnessOverride(-1);
10381 } else {
10382 mPowerManager.setButtonBrightnessOverride((int)
10383 (buttonBrightness * Power.BRIGHTNESS_ON));
10384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 if (holdScreen != mHoldingScreenOn) {
10386 mHoldingScreenOn = holdScreen;
10387 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10388 mH.sendMessage(m);
10389 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010390
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010391 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010392 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010393 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10394 LocalPowerManager.BUTTON_EVENT, true);
10395 mTurnOnScreen = false;
10396 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010397
10398 // Check to see if we are now in a state where the screen should
10399 // be enabled, because the window obscured flags have changed.
10400 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010402
10403 /**
10404 * Must be called with the main window manager lock held.
10405 */
10406 void setHoldScreenLocked(boolean holding) {
10407 boolean state = mHoldingScreenWakeLock.isHeld();
10408 if (holding != state) {
10409 if (holding) {
10410 mHoldingScreenWakeLock.acquire();
10411 } else {
10412 mPolicy.screenOnStoppedLw();
10413 mHoldingScreenWakeLock.release();
10414 }
10415 }
10416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417
10418 void requestAnimationLocked(long delay) {
10419 if (!mAnimationPending) {
10420 mAnimationPending = true;
10421 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10422 }
10423 }
Romain Guy06882f82009-06-10 13:36:04 -070010424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010425 /**
10426 * Have the surface flinger show a surface, robustly dealing with
10427 * error conditions. In particular, if there is not enough memory
10428 * to show the surface, then we will try to get rid of other surfaces
10429 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010430 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010431 * @return Returns true if the surface was successfully shown.
10432 */
10433 boolean showSurfaceRobustlyLocked(WindowState win) {
10434 try {
10435 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010436 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010438 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010439 if (DEBUG_VISIBILITY) Slog.v(TAG,
10440 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010441 win.mTurnOnScreen = false;
10442 mTurnOnScreen = true;
10443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010444 }
10445 return true;
10446 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010447 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010448 }
Romain Guy06882f82009-06-10 13:36:04 -070010449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010450 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 return false;
10453 }
Romain Guy06882f82009-06-10 13:36:04 -070010454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10456 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010457
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010458 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 if (mForceRemoves == null) {
10462 mForceRemoves = new ArrayList<WindowState>();
10463 }
Romain Guy06882f82009-06-10 13:36:04 -070010464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010465 long callingIdentity = Binder.clearCallingIdentity();
10466 try {
10467 // There was some problem... first, do a sanity check of the
10468 // window list to make sure we haven't left any dangling surfaces
10469 // around.
10470 int N = mWindows.size();
10471 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010472 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010474 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 if (ws.mSurface != null) {
10476 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010477 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 + ws + " surface=" + ws.mSurface
10479 + " token=" + win.mToken
10480 + " pid=" + ws.mSession.mPid
10481 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010482 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010483 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010484 ws.mSurface = null;
10485 mForceRemoves.add(ws);
10486 i--;
10487 N--;
10488 leakedSurface = true;
10489 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010490 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 + ws + " surface=" + ws.mSurface
10492 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010493 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010494 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010495 ws.mSurface = null;
10496 leakedSurface = true;
10497 }
10498 }
10499 }
Romain Guy06882f82009-06-10 13:36:04 -070010500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 boolean killedApps = false;
10502 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010503 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 SparseIntArray pidCandidates = new SparseIntArray();
10505 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010506 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 if (ws.mSurface != null) {
10508 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10509 }
10510 }
10511 if (pidCandidates.size() > 0) {
10512 int[] pids = new int[pidCandidates.size()];
10513 for (int i=0; i<pids.length; i++) {
10514 pids[i] = pidCandidates.keyAt(i);
10515 }
10516 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010517 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 killedApps = true;
10519 }
10520 } catch (RemoteException e) {
10521 }
10522 }
10523 }
Romain Guy06882f82009-06-10 13:36:04 -070010524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 if (leakedSurface || killedApps) {
10526 // We managed to reclaim some memory, so get rid of the trouble
10527 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010528 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010529 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010530 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010531 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 win.mSurface = null;
10533 }
Romain Guy06882f82009-06-10 13:36:04 -070010534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010535 try {
10536 win.mClient.dispatchGetNewSurface();
10537 } catch (RemoteException e) {
10538 }
10539 }
10540 } finally {
10541 Binder.restoreCallingIdentity(callingIdentity);
10542 }
10543 }
Romain Guy06882f82009-06-10 13:36:04 -070010544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010545 private boolean updateFocusedWindowLocked(int mode) {
10546 WindowState newFocus = computeFocusedWindowLocked();
10547 if (mCurrentFocus != newFocus) {
10548 // This check makes sure that we don't already have the focus
10549 // change message pending.
10550 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10551 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010552 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010553 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10554 final WindowState oldFocus = mCurrentFocus;
10555 mCurrentFocus = newFocus;
10556 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010558 final WindowState imWindow = mInputMethodWindow;
10559 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010560 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010562 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10563 mLayoutNeeded = true;
10564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010565 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10566 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010567 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10568 // Client will do the layout, but we need to assign layers
10569 // for handleNewWindowLocked() below.
10570 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010571 }
10572 }
Jeff Brown349703e2010-06-22 01:27:15 -070010573
10574 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10575 // If we defer assigning layers, then the caller is responsible for
10576 // doing this part.
10577 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010579 return true;
10580 }
10581 return false;
10582 }
Jeff Brown349703e2010-06-22 01:27:15 -070010583
10584 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010585 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010587
10588 private WindowState computeFocusedWindowLocked() {
10589 WindowState result = null;
10590 WindowState win;
10591
10592 int i = mWindows.size() - 1;
10593 int nextAppIndex = mAppTokens.size()-1;
10594 WindowToken nextApp = nextAppIndex >= 0
10595 ? mAppTokens.get(nextAppIndex) : null;
10596
10597 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010598 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599
Joe Onorato8a9b2202010-02-26 18:56:32 -080010600 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 TAG, "Looking for focus: " + i
10602 + " = " + win
10603 + ", flags=" + win.mAttrs.flags
10604 + ", canReceive=" + win.canReceiveKeys());
10605
10606 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010608 // If this window's application has been removed, just skip it.
10609 if (thisApp != null && thisApp.removed) {
10610 i--;
10611 continue;
10612 }
Romain Guy06882f82009-06-10 13:36:04 -070010613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010614 // If there is a focused app, don't allow focus to go to any
10615 // windows below it. If this is an application window, step
10616 // through the app tokens until we find its app.
10617 if (thisApp != null && nextApp != null && thisApp != nextApp
10618 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10619 int origAppIndex = nextAppIndex;
10620 while (nextAppIndex > 0) {
10621 if (nextApp == mFocusedApp) {
10622 // Whoops, we are below the focused app... no focus
10623 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010624 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010625 TAG, "Reached focused app: " + mFocusedApp);
10626 return null;
10627 }
10628 nextAppIndex--;
10629 nextApp = mAppTokens.get(nextAppIndex);
10630 if (nextApp == thisApp) {
10631 break;
10632 }
10633 }
10634 if (thisApp != nextApp) {
10635 // Uh oh, the app token doesn't exist! This shouldn't
10636 // happen, but if it does we can get totally hosed...
10637 // so restart at the original app.
10638 nextAppIndex = origAppIndex;
10639 nextApp = mAppTokens.get(nextAppIndex);
10640 }
10641 }
10642
10643 // Dispatch to this window if it is wants key events.
10644 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010645 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010646 TAG, "Found focus @ " + i + " = " + win);
10647 result = win;
10648 break;
10649 }
10650
10651 i--;
10652 }
10653
10654 return result;
10655 }
10656
10657 private void startFreezingDisplayLocked() {
10658 if (mDisplayFrozen) {
10659 return;
10660 }
Romain Guy06882f82009-06-10 13:36:04 -070010661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010664 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010665 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 if (mFreezeGcPending != 0) {
10667 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010668 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010669 mH.removeMessages(H.FORCE_GC);
10670 Runtime.getRuntime().gc();
10671 mFreezeGcPending = now;
10672 }
10673 } else {
10674 mFreezeGcPending = now;
10675 }
Romain Guy06882f82009-06-10 13:36:04 -070010676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010677 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010678
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010679 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010680
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010681 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10682 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010683 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010684 mAppTransitionReady = true;
10685 }
Romain Guy06882f82009-06-10 13:36:04 -070010686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010687 if (PROFILE_ORIENTATION) {
10688 File file = new File("/data/system/frozen");
10689 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10690 }
10691 Surface.freezeDisplay(0);
10692 }
Romain Guy06882f82009-06-10 13:36:04 -070010693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010694 private void stopFreezingDisplayLocked() {
10695 if (!mDisplayFrozen) {
10696 return;
10697 }
Romain Guy06882f82009-06-10 13:36:04 -070010698
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010699 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10700 return;
10701 }
10702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010703 mDisplayFrozen = false;
10704 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10705 if (PROFILE_ORIENTATION) {
10706 Debug.stopMethodTracing();
10707 }
10708 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010709
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010710 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010711
Christopher Tateb696aee2010-04-02 19:08:30 -070010712 // While the display is frozen we don't re-compute the orientation
10713 // to avoid inconsistent states. However, something interesting
10714 // could have actually changed during that time so re-evaluate it
10715 // now to catch that.
10716 if (updateOrientationFromAppTokensLocked()) {
10717 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10718 }
10719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010720 // A little kludge: a lot could have happened while the
10721 // display was frozen, so now that we are coming back we
10722 // do a gc so that any remote references the system
10723 // processes holds on others can be released if they are
10724 // no longer needed.
10725 mH.removeMessages(H.FORCE_GC);
10726 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10727 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010729 mScreenFrozenLock.release();
10730 }
Romain Guy06882f82009-06-10 13:36:04 -070010731
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010732 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10733 DisplayMetrics dm) {
10734 if (index < tokens.length) {
10735 String str = tokens[index];
10736 if (str != null && str.length() > 0) {
10737 try {
10738 int val = Integer.parseInt(str);
10739 return val;
10740 } catch (Exception e) {
10741 }
10742 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010743 }
10744 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10745 return defDps;
10746 }
10747 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10748 return val;
10749 }
10750
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010751 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010752 final String[] mTokens;
10753 final String mText;
10754 final Paint mTextPaint;
10755 final int mTextWidth;
10756 final int mTextHeight;
10757 final int mTextAscent;
10758 final int mTextDescent;
10759 final int mDeltaX;
10760 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010761
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010762 Surface mSurface;
10763 int mLastDW;
10764 int mLastDH;
10765 boolean mDrawNeeded;
10766
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010767 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010768 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010769 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010770
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010771 if (false) {
10772 Log.i(TAG, "*********************** WATERMARK");
10773 for (int i=0; i<tokens.length; i++) {
10774 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10775 }
10776 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010777
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010778 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010779
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010780 StringBuilder builder = new StringBuilder(32);
10781 int len = mTokens[0].length();
10782 len = len & ~1;
10783 for (int i=0; i<len; i+=2) {
10784 int c1 = mTokens[0].charAt(i);
10785 int c2 = mTokens[0].charAt(i+1);
10786 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10787 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10788 else c1 -= '0';
10789 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10790 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10791 else c2 -= '0';
10792 builder.append((char)(255-((c1*16)+c2)));
10793 }
10794 mText = builder.toString();
10795 if (false) {
10796 Log.i(TAG, "Final text: " + mText);
10797 }
10798
10799 int fontSize = getPropertyInt(tokens, 1,
10800 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10801
10802 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10803 mTextPaint.setTextSize(fontSize);
10804 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10805
10806 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10807 mTextWidth = (int)mTextPaint.measureText(mText);
10808 mTextAscent = fm.ascent;
10809 mTextDescent = fm.descent;
10810 mTextHeight = fm.descent - fm.ascent;
10811
10812 mDeltaX = getPropertyInt(tokens, 2,
10813 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10814 mDeltaY = getPropertyInt(tokens, 3,
10815 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10816 int shadowColor = getPropertyInt(tokens, 4,
10817 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10818 int color = getPropertyInt(tokens, 5,
10819 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10820 int shadowRadius = getPropertyInt(tokens, 6,
10821 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10822 int shadowDx = getPropertyInt(tokens, 8,
10823 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10824 int shadowDy = getPropertyInt(tokens, 9,
10825 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10826
10827 mTextPaint.setColor(color);
10828 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010829
10830 try {
10831 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010832 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010833 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010834 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010835 mSurface.show();
10836 } catch (OutOfResourcesException e) {
10837 }
10838 }
10839
10840 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010841 if (mLastDW != dw || mLastDH != dh) {
10842 mLastDW = dw;
10843 mLastDH = dh;
10844 mSurface.setSize(dw, dh);
10845 mDrawNeeded = true;
10846 }
10847 }
10848
10849 void drawIfNeeded() {
10850 if (mDrawNeeded) {
10851 final int dw = mLastDW;
10852 final int dh = mLastDH;
10853
10854 mDrawNeeded = false;
10855 Rect dirty = new Rect(0, 0, dw, dh);
10856 Canvas c = null;
10857 try {
10858 c = mSurface.lockCanvas(dirty);
10859 } catch (IllegalArgumentException e) {
10860 } catch (OutOfResourcesException e) {
10861 }
10862 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010863 c.drawColor(0, PorterDuff.Mode.CLEAR);
10864
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010865 int deltaX = mDeltaX;
10866 int deltaY = mDeltaY;
10867
10868 // deltaX shouldn't be close to a round fraction of our
10869 // x step, or else things will line up too much.
10870 int div = (dw+mTextWidth)/deltaX;
10871 int rem = (dw+mTextWidth) - (div*deltaX);
10872 int qdelta = deltaX/4;
10873 if (rem < qdelta || rem > (deltaX-qdelta)) {
10874 deltaX += deltaX/3;
10875 }
10876
10877 int y = -mTextHeight;
10878 int x = -mTextWidth;
10879 while (y < (dh+mTextHeight)) {
10880 c.drawText(mText, x, y, mTextPaint);
10881 x += deltaX;
10882 if (x >= dw) {
10883 x -= (dw+mTextWidth);
10884 y += deltaY;
10885 }
10886 }
10887 mSurface.unlockCanvasAndPost(c);
10888 }
10889 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010890 }
10891 }
10892
10893 void createWatermark() {
10894 if (mWatermark != null) {
10895 return;
10896 }
10897
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010898 File file = new File("/system/etc/setup.conf");
10899 FileInputStream in = null;
10900 try {
10901 in = new FileInputStream(file);
10902 DataInputStream ind = new DataInputStream(in);
10903 String line = ind.readLine();
10904 if (line != null) {
10905 String[] toks = line.split("%");
10906 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070010907 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010908 }
10909 }
10910 } catch (FileNotFoundException e) {
10911 } catch (IOException e) {
10912 } finally {
10913 if (in != null) {
10914 try {
10915 in.close();
10916 } catch (IOException e) {
10917 }
10918 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010919 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010920 }
10921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010922 @Override
10923 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10924 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10925 != PackageManager.PERMISSION_GRANTED) {
10926 pw.println("Permission Denial: can't dump WindowManager from from pid="
10927 + Binder.getCallingPid()
10928 + ", uid=" + Binder.getCallingUid());
10929 return;
10930 }
Romain Guy06882f82009-06-10 13:36:04 -070010931
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010932 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010933 pw.println(" ");
10934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010935 synchronized(mWindowMap) {
10936 pw.println("Current Window Manager state:");
10937 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010938 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010939 pw.print(" Window #"); pw.print(i); pw.print(' ');
10940 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010941 w.dump(pw, " ");
10942 }
10943 if (mInputMethodDialogs.size() > 0) {
10944 pw.println(" ");
10945 pw.println(" Input method dialogs:");
10946 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10947 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010948 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010949 }
10950 }
10951 if (mPendingRemove.size() > 0) {
10952 pw.println(" ");
10953 pw.println(" Remove pending for:");
10954 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10955 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010956 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10957 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010958 w.dump(pw, " ");
10959 }
10960 }
10961 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10962 pw.println(" ");
10963 pw.println(" Windows force removing:");
10964 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10965 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010966 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10967 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010968 w.dump(pw, " ");
10969 }
10970 }
10971 if (mDestroySurface.size() > 0) {
10972 pw.println(" ");
10973 pw.println(" Windows waiting to destroy their surface:");
10974 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10975 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010976 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10977 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010978 w.dump(pw, " ");
10979 }
10980 }
10981 if (mLosingFocus.size() > 0) {
10982 pw.println(" ");
10983 pw.println(" Windows losing focus:");
10984 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10985 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010986 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10987 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010988 w.dump(pw, " ");
10989 }
10990 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010991 if (mResizingWindows.size() > 0) {
10992 pw.println(" ");
10993 pw.println(" Windows waiting to resize:");
10994 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10995 WindowState w = mResizingWindows.get(i);
10996 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10997 pw.print(w); pw.println(":");
10998 w.dump(pw, " ");
10999 }
11000 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011001 if (mSessions.size() > 0) {
11002 pw.println(" ");
11003 pw.println(" All active sessions:");
11004 Iterator<Session> it = mSessions.iterator();
11005 while (it.hasNext()) {
11006 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011007 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011008 s.dump(pw, " ");
11009 }
11010 }
11011 if (mTokenMap.size() > 0) {
11012 pw.println(" ");
11013 pw.println(" All tokens:");
11014 Iterator<WindowToken> it = mTokenMap.values().iterator();
11015 while (it.hasNext()) {
11016 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011017 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011018 token.dump(pw, " ");
11019 }
11020 }
11021 if (mTokenList.size() > 0) {
11022 pw.println(" ");
11023 pw.println(" Window token list:");
11024 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011025 pw.print(" #"); pw.print(i); pw.print(": ");
11026 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011027 }
11028 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011029 if (mWallpaperTokens.size() > 0) {
11030 pw.println(" ");
11031 pw.println(" Wallpaper tokens:");
11032 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11033 WindowToken token = mWallpaperTokens.get(i);
11034 pw.print(" Wallpaper #"); pw.print(i);
11035 pw.print(' '); pw.print(token); pw.println(':');
11036 token.dump(pw, " ");
11037 }
11038 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011039 if (mAppTokens.size() > 0) {
11040 pw.println(" ");
11041 pw.println(" Application tokens in Z order:");
11042 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011043 pw.print(" App #"); pw.print(i); pw.print(": ");
11044 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011045 }
11046 }
11047 if (mFinishedStarting.size() > 0) {
11048 pw.println(" ");
11049 pw.println(" Finishing start of application tokens:");
11050 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11051 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011052 pw.print(" Finished Starting #"); pw.print(i);
11053 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011054 token.dump(pw, " ");
11055 }
11056 }
11057 if (mExitingTokens.size() > 0) {
11058 pw.println(" ");
11059 pw.println(" Exiting tokens:");
11060 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11061 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011062 pw.print(" Exiting #"); pw.print(i);
11063 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011064 token.dump(pw, " ");
11065 }
11066 }
11067 if (mExitingAppTokens.size() > 0) {
11068 pw.println(" ");
11069 pw.println(" Exiting application tokens:");
11070 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11071 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011072 pw.print(" Exiting App #"); pw.print(i);
11073 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011074 token.dump(pw, " ");
11075 }
11076 }
11077 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011078 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11079 pw.print(" mLastFocus="); pw.println(mLastFocus);
11080 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11081 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11082 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011083 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011084 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11085 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11086 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11087 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011088 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11089 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11090 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011091 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11092 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11093 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11094 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011095 if (mDimAnimator != null) {
11096 mDimAnimator.printTo(pw);
11097 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011098 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011099 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011100 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011101 pw.print(mInputMethodAnimLayerAdjustment);
11102 pw.print(" mWallpaperAnimLayerAdjustment=");
11103 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011104 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11105 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011106 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11107 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011108 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11109 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011110 pw.print(" mRotation="); pw.print(mRotation);
11111 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11112 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11113 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11114 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11115 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11116 pw.print(" mNextAppTransition=0x");
11117 pw.print(Integer.toHexString(mNextAppTransition));
11118 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011119 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011120 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011121 if (mNextAppTransitionPackage != null) {
11122 pw.print(" mNextAppTransitionPackage=");
11123 pw.print(mNextAppTransitionPackage);
11124 pw.print(", mNextAppTransitionEnter=0x");
11125 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11126 pw.print(", mNextAppTransitionExit=0x");
11127 pw.print(Integer.toHexString(mNextAppTransitionExit));
11128 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011129 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11130 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011131 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11132 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11133 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11134 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011135 if (mOpeningApps.size() > 0) {
11136 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11137 }
11138 if (mClosingApps.size() > 0) {
11139 pw.print(" mClosingApps="); pw.println(mClosingApps);
11140 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011141 if (mToTopApps.size() > 0) {
11142 pw.print(" mToTopApps="); pw.println(mToTopApps);
11143 }
11144 if (mToBottomApps.size() > 0) {
11145 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11146 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011147 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11148 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011149 }
11150 }
11151
Jeff Brown349703e2010-06-22 01:27:15 -070011152 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011153 public void monitor() {
11154 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011155 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011157
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011158 /**
11159 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011160 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011161 */
11162 private static class DimAnimator {
11163 Surface mDimSurface;
11164 boolean mDimShown = false;
11165 float mDimCurrentAlpha;
11166 float mDimTargetAlpha;
11167 float mDimDeltaPerMs;
11168 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011169
11170 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011171
11172 DimAnimator (SurfaceSession session) {
11173 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011174 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011175 + mDimSurface + ": CREATE");
11176 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011177 mDimSurface = new Surface(session, 0,
11178 "DimSurface",
11179 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011180 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011181 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011182 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011183 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011184 }
11185 }
11186 }
11187
11188 /**
11189 * Show the dim surface.
11190 */
11191 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011192 if (!mDimShown) {
11193 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11194 dw + "x" + dh + ")");
11195 mDimShown = true;
11196 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011197 mLastDimWidth = dw;
11198 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011199 mDimSurface.setPosition(0, 0);
11200 mDimSurface.setSize(dw, dh);
11201 mDimSurface.show();
11202 } catch (RuntimeException e) {
11203 Slog.w(TAG, "Failure showing dim surface", e);
11204 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011205 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11206 mLastDimWidth = dw;
11207 mLastDimHeight = dh;
11208 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011209 }
11210 }
11211
11212 /**
11213 * Set's the dim surface's layer and update dim parameters that will be used in
11214 * {@link updateSurface} after all windows are examined.
11215 */
11216 void updateParameters(WindowState w, long currentTime) {
11217 mDimSurface.setLayer(w.mAnimLayer-1);
11218
11219 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011220 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011221 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011222 if (mDimTargetAlpha != target) {
11223 // If the desired dim level has changed, then
11224 // start an animation to it.
11225 mLastDimAnimTime = currentTime;
11226 long duration = (w.mAnimating && w.mAnimation != null)
11227 ? w.mAnimation.computeDurationHint()
11228 : DEFAULT_DIM_DURATION;
11229 if (target > mDimTargetAlpha) {
11230 // This is happening behind the activity UI,
11231 // so we can make it run a little longer to
11232 // give a stronger impression without disrupting
11233 // the user.
11234 duration *= DIM_DURATION_MULTIPLIER;
11235 }
11236 if (duration < 1) {
11237 // Don't divide by zero
11238 duration = 1;
11239 }
11240 mDimTargetAlpha = target;
11241 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11242 }
11243 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011244
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011245 /**
11246 * Updating the surface's alpha. Returns true if the animation continues, or returns
11247 * false when the animation is finished and the dim surface is hidden.
11248 */
11249 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11250 if (!dimming) {
11251 if (mDimTargetAlpha != 0) {
11252 mLastDimAnimTime = currentTime;
11253 mDimTargetAlpha = 0;
11254 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11255 }
11256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011257
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011258 boolean animating = false;
11259 if (mLastDimAnimTime != 0) {
11260 mDimCurrentAlpha += mDimDeltaPerMs
11261 * (currentTime-mLastDimAnimTime);
11262 boolean more = true;
11263 if (displayFrozen) {
11264 // If the display is frozen, there is no reason to animate.
11265 more = false;
11266 } else if (mDimDeltaPerMs > 0) {
11267 if (mDimCurrentAlpha > mDimTargetAlpha) {
11268 more = false;
11269 }
11270 } else if (mDimDeltaPerMs < 0) {
11271 if (mDimCurrentAlpha < mDimTargetAlpha) {
11272 more = false;
11273 }
11274 } else {
11275 more = false;
11276 }
11277
11278 // Do we need to continue animating?
11279 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011280 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011281 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11282 mLastDimAnimTime = currentTime;
11283 mDimSurface.setAlpha(mDimCurrentAlpha);
11284 animating = true;
11285 } else {
11286 mDimCurrentAlpha = mDimTargetAlpha;
11287 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011288 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011289 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11290 mDimSurface.setAlpha(mDimCurrentAlpha);
11291 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011292 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011293 + ": HIDE");
11294 try {
11295 mDimSurface.hide();
11296 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011297 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011298 }
11299 mDimShown = false;
11300 }
11301 }
11302 }
11303 return animating;
11304 }
11305
11306 public void printTo(PrintWriter pw) {
11307 pw.print(" mDimShown="); pw.print(mDimShown);
11308 pw.print(" current="); pw.print(mDimCurrentAlpha);
11309 pw.print(" target="); pw.print(mDimTargetAlpha);
11310 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11311 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11312 }
11313 }
11314
11315 /**
11316 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11317 * This is used for opening/closing transition for apps in compatible mode.
11318 */
11319 private static class FadeInOutAnimation extends Animation {
11320 int mWidth;
11321 boolean mFadeIn;
11322
11323 public FadeInOutAnimation(boolean fadeIn) {
11324 setInterpolator(new AccelerateInterpolator());
11325 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11326 mFadeIn = fadeIn;
11327 }
11328
11329 @Override
11330 protected void applyTransformation(float interpolatedTime, Transformation t) {
11331 float x = interpolatedTime;
11332 if (!mFadeIn) {
11333 x = 1.0f - x; // reverse the interpolation for fade out
11334 }
11335 if (x < 0.5) {
11336 // move the window out of the screen.
11337 t.getMatrix().setTranslate(mWidth, 0);
11338 } else {
11339 t.getMatrix().setTranslate(0, 0);// show
11340 t.setAlpha((x - 0.5f) * 2);
11341 }
11342 }
11343
11344 @Override
11345 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11346 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11347 mWidth = width;
11348 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011349
11350 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011351 public int getZAdjustment() {
11352 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011353 }
11354 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011355}